| 1 | #!/usr/bin/env bash |
| 2 | # Start CI on a Notes PR that the Actions bot opened. Events raised with |
| 3 | # GITHUB_TOKEN never start workflows, so such a PR shows action_required with |
| 4 | # zero jobs until a human-authenticated close/reopen re-emits pull_request. |
| 5 | set -euo pipefail |
| 6 | |
| 7 | if [ "$#" -ne 1 ] || [[ ! "$1" =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$ ]]; then |
| 8 | echo "usage: scripts/release-notes-pr-kick.sh MAJOR.MINOR.PATCH" >&2 |
| 9 | exit 2 |
| 10 | fi |
| 11 | |
| 12 | version="$1" |
| 13 | repository="${RELEASE_REPOSITORY:-esengine/DeepSeek-Reasonix}" |
| 14 | branch="release-notes/v$version" |
| 15 | wait_seconds="${RELEASE_NOTES_KICK_WAIT_SECONDS:-120}" |
| 16 | |
| 17 | for command in gh jq; do |
| 18 | command -v "$command" >/dev/null || { |
| 19 | echo "required command is unavailable: $command" >&2 |
| 20 | exit 2 |
| 21 | } |
| 22 | done |
| 23 | |
| 24 | prs="$(gh pr list --repo "$repository" --head "$branch" --state open --json number,headRefOid --limit 2)" |
| 25 | count="$(jq 'length' <<<"$prs")" |
| 26 | if [ "$count" -ne 1 ]; then |
| 27 | echo "expected exactly one open PR for $branch, found $count" >&2 |
| 28 | exit 1 |
| 29 | fi |
| 30 | number="$(jq -r '.[0].number' <<<"$prs")" |
| 31 | head="$(jq -r '.[0].headRefOid' <<<"$prs")" |
| 32 | |
| 33 | check_runs() { |
| 34 | gh api "repos/$repository/commits/$head/check-runs" --jq '.total_count' |
| 35 | } |
| 36 | |
| 37 | if [ "$(check_runs)" -gt 0 ]; then |
| 38 | echo "PR #$number already has check runs on $head; nothing to kick" |
| 39 | exit 0 |
| 40 | fi |
| 41 | |
| 42 | # Only the recorded-but-never-started shape is safe to kick. Anything else |
| 43 | # with zero check runs needs a look, not a reopen. |
| 44 | stalled="$(gh api "repos/$repository/actions/runs?event=pull_request&head_sha=$head&per_page=20" \ |
| 45 | --jq "[.workflow_runs[] | select(.head_sha == \"$head\" and .conclusion == \"action_required\")] | length")" |
| 46 | if [ "$stalled" -eq 0 ]; then |
| 47 | echo "PR #$number has no check runs and no action_required run on $head; inspect before kicking" >&2 |
| 48 | exit 1 |
| 49 | fi |
| 50 | |
| 51 | echo "PR #$number: $stalled recorded-but-unstarted run(s) on $head; closing and reopening" |
| 52 | gh pr close "$number" --repo "$repository" |
| 53 | gh pr reopen "$number" --repo "$repository" |
| 54 | |
| 55 | deadline=$((SECONDS + wait_seconds)) |
| 56 | while [ "$(check_runs)" -eq 0 ]; do |
| 57 | if [ "$SECONDS" -ge "$deadline" ]; then |
| 58 | echo "no check runs appeared on $head within ${wait_seconds}s" >&2 |
| 59 | exit 1 |
| 60 | fi |
| 61 | sleep 5 |
| 62 | done |
| 63 | echo "CI started on PR #$number ($head)" |
| 64 |