Skip to content

fix(ci-providers): use JOB_CHECK_RUN_ID for GitHub Actions ci.job.id#2307

Merged
anmarchenko merged 2 commits into
masterfrom
anmarchenko/github-job-check-run-id
May 5, 2026
Merged

fix(ci-providers): use JOB_CHECK_RUN_ID for GitHub Actions ci.job.id#2307
anmarchenko merged 2 commits into
masterfrom
anmarchenko/github-job-check-run-id

Conversation

@anmarchenko

@anmarchenko anmarchenko commented May 5, 2026

Copy link
Copy Markdown
Member

What and why?

The ci-env spec fixtures bundled in packages/base/src/helpers/__tests__/ci-env/ had drifted from the canonical datadog-ci-spec source. Notably:

  • github.json lost the JOB_CHECK_RUN_ID env var. The canonical spec maps JOB_CHECK_RUN_ID (which GitHub Actions injects with the numeric job ID of the running step) to the ci.job.id span tag, and uses it to build a ci.job.url of the form <server>/<repo>/actions/runs/<run_id>/job/<job_id> — instead of the older <server>/<repo>/commit/<sha>/checks fallback.
  • 12 other providers had a *_PR_NUMBER env var stored as a JSON int instead of a string (the test harness coerces both to strings, so this was cosmetic but worth refreshing).
  • buildkite.json's ci.node.labels order was refreshed from the canonical spec; the implementation emits labels in env-insertion order, which doesn't match the spec's order. Rather than coupling the test to either ordering, the getCIMetadata spec test now compares ci.node.labels order-independently (matching the existing pattern in the sibling "reads env info for spec" suite).

The datadog-ci-spec CI job for this repo doesn't catch the drift because its Makefile copies generated fixtures into generated/datadog-ci/src/helpers/__tests__/ci-env/, a path that no longer exists after the monorepo restructure to packages/base/.... So the override silently no-ops and the bundled (stale) fixtures are what get tested.

How?

  • Code (packages/base/src/helpers/ci.ts): added JOB_CHECK_RUN_ID to the GitHub env destructure and introduced githubJobID = JOB_CHECK_RUN_ID ?? fallbackGithubJobID. Both ci.job.id and ci.job.url now consume githubJobID, so the actions/runs/<run_id>/job/<job_id> URL is built whenever the runtime exposes the job ID — without relying on the log-scraping fallback.
  • Fixtures: regenerated all 16 ci-env fixtures from the latest datadog-ci-spec YAMLs.
  • Test (packages/base/src/helpers/__tests__/ci.test.ts): the getCIMetadata spec test now destructures CI_ENV_VARS and CI_NODE_LABELS out of the comparison and checks them via JSON.parse + arrayContaining, so the test tolerates ordering differences in auto-generated fixtures. This mirrors the pattern already used by the sibling "reads env info for spec" suite.
  • Verified: CI='' yarn test -t 'ci spec' → 321 passed, 0 failed.

Note on Windows e2e (Node 24) failure

The "End-to-end test the package (Windows) (24)" check fails on this PR with Error: EBADF: bad file descriptor, fstat inside Node's ESM loader (node:fs:391getSourceSynccreateCJSModuleWrap). This is a Node.js 24.15.0 upstream regression (see nodejs/corepack#813, yarnpkg/berry#7065), unrelated to anything this PR changes — the crash fires while loading jest.config-e2e.mjs, before any of our code runs. Master's last successful run used Node v24.14.1; this PR's run picked up the freshly-released v24.15.0. The CI fix is being tracked in #2306, which pins/works around the Node 24 issue.

Review checklist

  • Feature or bugfix MUST have appropriate tests (unit, integration) — covered by the existing ci spec suite, which now exercises the JOB_CHECK_RUN_ID path via the refreshed github.json fixture.

🤖 Generated with Claude Code

GitHub Actions exposes the numeric job ID of the running step via the
JOB_CHECK_RUN_ID env var. This commit reads it and uses it for both the
ci.job.id span tag and the ci.job.url, falling back to the existing
log-scraped fallbackGithubJobID when JOB_CHECK_RUN_ID is not set.

Also refreshes the ci-env spec fixtures from the canonical
DataDog/datadog-ci-spec source — most providers gained a JSON-string
form of their PR-number env var, github.json gained the new
JOB_CHECK_RUN_ID field plus updated ci.job.id / ci.job.url expectations,
and buildkite.json's ci.node.labels expectation now matches insertion
order (which is what the implementation already produces).

Verified: CI='' yarn test -t 'ci spec' → 321 passed, 0 failed.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@anmarchenko
anmarchenko requested review from a team as code owners May 5, 2026 09:31
@anmarchenko
anmarchenko requested a review from rodrigo-roca May 5, 2026 09:31
@anmarchenko anmarchenko added the software-delivery Related to [coverage, deployment, dora, junit, measure, tag, trace] label May 5, 2026
@datadog-official

datadog-official Bot commented May 5, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 5c79f40 | Docs | Datadog PR Page | Give us feedback!

The `getCIMetadata` spec test did a strict deep-equal on the whole tags
object, which made it sensitive to label ordering inside the
`ci.node.labels` JSON array — even though the fixtures are
auto-generated and ordering is not part of the contract. Apply the same
destructure + `arrayContaining` pattern already used by the sibling
"reads env info for spec" suite so both tests handle the auto-generated
fixtures consistently.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@anmarchenko
anmarchenko merged commit 5b5e9e2 into master May 5, 2026
73 of 79 checks passed
@anmarchenko
anmarchenko deleted the anmarchenko/github-job-check-run-id branch May 5, 2026 10:28
@ava-silver ava-silver mentioned this pull request May 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

software-delivery Related to [coverage, deployment, dora, junit, measure, tag, trace]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants