diff --git a/.github/workflows/woa-main-ci.yml b/.github/workflows/woa-main-ci.yml index 95b5ebd9d3e..dad61c6d08a 100644 --- a/.github/workflows/woa-main-ci.yml +++ b/.github/workflows/woa-main-ci.yml @@ -37,7 +37,7 @@ jobs: contents: read checks: read outputs: - dispatch: ${{ steps.select.outputs.dispatch }} + dispatch: ${{ steps.select.outputs.dispatch || 'false' }} correlation-id: ${{ steps.resolve.outputs.correlation_id }} public-run-id: ${{ steps.resolve.outputs.public_run_id }} public-sha: ${{ steps.resolve.outputs.public_sha }} @@ -59,6 +59,15 @@ jobs: PUBLIC_RUN_ID: ${{ inputs.public_run_id }} run: | set -euo pipefail + trap 'status=$?; echo "::error::Public build resolution failed at line $LINENO (exit $status)."; exit "$status"' ERR + skip_resolution() { + echo "::notice::Skipping WoA dispatch: $1" + echo "Skipping WoA dispatch: $1" >> "$GITHUB_STEP_SUMMARY" + echo "eligible=false" >> "$GITHUB_OUTPUT" + exit 0 + } + + echo "Resolving public CI run: ${PUBLIC_RUN_ID:-latest successful main push}." public_sha='' if [[ -z "$PUBLIC_RUN_ID" ]]; then lookup_output=$(./ci/tools/lookup-run-id --branch main --event push --head-sha NVIDIA/cuda-python CI) @@ -72,17 +81,27 @@ jobs: run=$(gh api \ -H 'X-GitHub-Api-Version: 2026-03-10' \ "repos/NVIDIA/cuda-python/actions/runs/$PUBLIC_RUN_ID") - jq -e --arg sha "$public_sha" ' - .repository.full_name == "NVIDIA/cuda-python" and - .workflow_id == 155304118 and - .path == ".github/workflows/ci.yml" and - .event == "push" and - .head_branch == "main" and - ((.status == "in_progress" and .conclusion == null) or - (.status == "completed" and .conclusion == "success")) and - ($sha == "" or .head_sha == $sha) and - (.head_sha | test("^[0-9a-f]{40}$")) - ' <<< "$run" >/dev/null + echo "Public run metadata:" + jq '{id, repository: .repository.full_name, workflow_id, path, event, + head_branch, head_sha, status, conclusion, run_attempt, created_at, updated_at}' <<< "$run" + checks=$(jq --arg sha "$public_sha" ' + { + repository: (.repository.full_name == "NVIDIA/cuda-python"), + workflow_id: (.workflow_id == 155304118), + workflow_path: (.path == ".github/workflows/ci.yml"), + event: (.event == "push"), + branch: (.head_branch == "main"), + status_and_conclusion: ((.status == "in_progress" and .conclusion == null) or + (.status == "completed" and .conclusion == "success")), + expected_sha: ($sha == "" or .head_sha == $sha), + sha_format: ((.head_sha // "") | test("^[0-9a-f]{40}$")) + } + ' <<< "$run") + echo "Public run eligibility checks (all must be true): $checks" + failed_checks=$(jq -r 'to_entries | map(select(.value == false) | .key) | join(", ")' <<< "$checks") + if [[ -n "$failed_checks" ]]; then + skip_resolution "Run $PUBLIC_RUN_ID is outside the eligible scope: $failed_checks." + fi if [[ -z "$public_sha" ]]; then public_sha=$(jq -r .head_sha <<< "$run") fi @@ -90,17 +109,23 @@ jobs: comparison=$(gh api \ -H 'X-GitHub-Api-Version: 2026-03-10' \ "repos/NVIDIA/cuda-python/compare/$public_sha...main") - jq -e '.status == "ahead" or .status == "identical"' <<< "$comparison" >/dev/null + echo "Public commit comparison ($public_sha...main):" + jq '{status, ahead_by, behind_by, total_commits}' <<< "$comparison" + if ! jq -e '.status == "ahead" or .status == "identical"' <<< "$comparison" >/dev/null; then + skip_resolution "Commit $public_sha is not on main (comparison: $(jq -r .status <<< "$comparison"))." + fi correlation_id="v1:NVIDIA/cuda-python:$PUBLIC_RUN_ID:$public_sha" echo "correlation_id=$correlation_id" >> "$GITHUB_OUTPUT" echo "public_run_id=$PUBLIC_RUN_ID" >> "$GITHUB_OUTPUT" echo "public_sha=$public_sha" >> "$GITHUB_OUTPUT" + echo "eligible=true" >> "$GITHUB_OUTPUT" { echo "Resolved public run \`$PUBLIC_RUN_ID\` at commit \`$public_sha\`." } >> "$GITHUB_STEP_SUMMARY" - name: Select public batch + if: ${{ steps.resolve.outputs.eligible == 'true' }} id: select env: GH_TOKEN: ${{ github.token }}