Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Fix job_id resolution on best effort basis (#75185)

Nemanja Glumacd7a4cf22916a
diff --git a/.github/actions/resolve-job-id/action.yml b/.github/actions/resolve-job-id/action.yml
index 25cc81b64cf..fa3b200c90d 100644
--- a/.github/actions/resolve-job-id/action.yml
+++ b/.github/actions/resolve-job-id/action.yml
@@ -11,24 +11,37 @@ runs:
- name: Resolve JOB_ID
shell: bash
env:
+ # Use the built-in per-job token, not a PAT: this lookup is best-effort
+ # (a miss just leaves JOB_ID unset, never breaks the run) and other jobs
+ # depend on the automation PAT's rate-limit budget — we don't want ~70
+ # e2e shards drawing it down. Worst case under heavy CI load is the
+ # occasional unresolved job_id, which is acceptable. DEV-2117.
GH_TOKEN: ${{ github.token }}
RUNNER_NAME: ${{ runner.name }}
run: |
# GitHub doesn't expose the current job's numeric id, so we look it up
- # from the Actions API. A runner runs exactly one job at a time, so
- # filtering by runner_name within (run_id, run_attempt) is unique.
- # max_by(.started_at) handles the rare case of a runner sequentially
- # running multiple jobs in the same attempt — we want the latest.
+ # from the Actions API. A runner runs exactly one job at a time, so the
+ # in-progress job with this runner_name within (run_id, run_attempt) is
+ # unique. We require status == in_progress and no completed_at so a
+ # reused runner can't match a job it already finished this attempt, with
+ # max_by(.started_at) as a final tiebreaker.
+ #
+ # $GITHUB_RUN_ID is the whole CI run, whose total job count exceeds the
+ # 100-per-page cap (~185 jobs), so this shard's job is frequently NOT on
+ # the first page. --paginate --slurp pulls every page and slurps them
+ # into one array so the filter sees all jobs, not just the first 100 —
+ # without it the lookup returned null whenever this job sorted past
+ # position 100 (DEV-2117).
set +e
api_url="/repos/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID/attempts/$GITHUB_RUN_ATTEMPT/jobs?per_page=100"
- jq_filter="[.jobs[] | select(.runner_name == \"$RUNNER_NAME\")] | max_by(.started_at) | \"\(.id) \(.html_url)\""
+ jq_filter="[.[].jobs[] | select(.runner_name == \"$RUNNER_NAME\" and .status == \"in_progress\" and .completed_at == null)] | max_by(.started_at) | \"\(.id) \(.html_url)\""
# The Actions jobs API is eventually consistent: after a runner picks
# up a job, it can take a few seconds for runner_name to appear in the
# response. Retry briefly to absorb that.
out=""
for attempt in 1 2 3 4 5; do
- out=$(gh api "$api_url" --jq "$jq_filter" 2>/dev/null)
+ out=$(gh api --paginate --slurp "$api_url" --jq "$jq_filter" 2>/dev/null)
if [ -n "$out" ] && [ "$out" != "null null" ]; then
break
fi