| 1 | #!/usr/bin/env bash |
| 2 | # Wait for successful push CI on one immutable main-v2 candidate. |
| 3 | set -euo pipefail |
| 4 | |
| 5 | if [ "$#" -ne 1 ] || [[ ! "$1" =~ ^[0-9a-f]{40}$ ]]; then |
| 6 | echo "usage: verify-release-push-ci.sh FULL_COMMIT_SHA" >&2 |
| 7 | exit 2 |
| 8 | fi |
| 9 | |
| 10 | candidate="$1" |
| 11 | repository="${RELEASE_REPOSITORY:-esengine/DeepSeek-Reasonix}" |
| 12 | wait_seconds="${RELEASE_CI_WAIT_SECONDS:-1800}" |
| 13 | poll_seconds="${RELEASE_CI_POLL_SECONDS:-10}" |
| 14 | |
| 15 | if [[ ! "$wait_seconds" =~ ^[0-9]+$ ]] || [[ ! "$poll_seconds" =~ ^[1-9][0-9]*$ ]]; then |
| 16 | echo "RELEASE_CI_WAIT_SECONDS must be non-negative and RELEASE_CI_POLL_SECONDS must be positive" >&2 |
| 17 | exit 2 |
| 18 | fi |
| 19 | for command in gh jq; do |
| 20 | command -v "$command" >/dev/null || { |
| 21 | echo "required command is unavailable: $command" >&2 |
| 22 | exit 2 |
| 23 | } |
| 24 | done |
| 25 | |
| 26 | deadline=$((SECONDS + wait_seconds)) |
| 27 | while :; do |
| 28 | runs="$(gh run list --repo "$repository" --workflow ci.yml --commit "$candidate" \ |
| 29 | --event push --limit 20 --json headSha,status,conclusion 2>/dev/null || true)" |
| 30 | run_status="$(jq -r --arg sha "$candidate" \ |
| 31 | '[.[] | select(.headSha == $sha)][0].status // ""' <<<"$runs" 2>/dev/null || true)" |
| 32 | conclusion="$(jq -r --arg sha "$candidate" \ |
| 33 | '[.[] | select(.headSha == $sha and .status == "completed")][0].conclusion // ""' <<<"$runs" 2>/dev/null || true)" |
| 34 | case "$conclusion" in |
| 35 | success) |
| 36 | echo "successful main-v2 push CI verified: $candidate" |
| 37 | exit 0 |
| 38 | ;; |
| 39 | failure | cancelled | timed_out | action_required | startup_failure) |
| 40 | echo "CI for $candidate concluded $conclusion" >&2 |
| 41 | exit 1 |
| 42 | ;; |
| 43 | esac |
| 44 | if [ "$SECONDS" -ge "$deadline" ]; then |
| 45 | echo "timed out waiting for successful main-v2 CI on $candidate (last status: ${run_status:-missing})" >&2 |
| 46 | exit 1 |
| 47 | fi |
| 48 | sleep "$poll_seconds" |
| 49 | done |
| 50 |