Skip to content

Commit ca32fde

Browse files
committed
ci(all-green): stop datadog-ci's own CI detection from overwriting per-test pipeline tags
getCISpanTags() derives ci.pipeline.name/id/number and ci.job.name straight from GITHUB_WORKFLOW/GITHUB_JOB/GITHUB_RUN_ID/GITHUB_RUN_NUMBER, applying the same value to every file in the batched junit upload -- overwriting the per-test values the --xpath-tag mappings lift from each testsuite's own stamped properties. Blanking just those four env vars for the datadog-ci child process leaves every other GITHUB_*-derived tag (repository URL, PR association, commit SHA) untouched, since none of those collide with what the xpath mappings set. Generated by Claude Code.
1 parent 6052d9b commit ca32fde

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

scripts/run-upload.mjs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,16 @@ import { setTimeout as sleep } from 'node:timers/promises'
1717
*
1818
* @param {string} command
1919
* @param {string[]} args
20+
* @param {NodeJS.ProcessEnv} [env]
2021
* @returns {Promise<UploadResult>}
2122
*/
22-
function spawnUpload (command, args) {
23+
function spawnUpload (command, args, env) {
2324
return new Promise(resolve => {
2425
const start = Date.now()
25-
const child = spawn(command, args, { stdio: ['ignore', 'pipe', 'pipe'] })
26+
const child = spawn(command, args, {
27+
stdio: ['ignore', 'pipe', 'pipe'],
28+
...(env && { env: { ...process.env, ...env } }),
29+
})
2630
let output = ''
2731
child.stdout.on('data', chunk => { output += chunk })
2832
child.stderr.on('data', chunk => { output += chunk })
@@ -40,10 +44,12 @@ function spawnUpload (command, args) {
4044
*
4145
* @param {string} command
4246
* @param {string[]} args
47+
* @param {NodeJS.ProcessEnv} [env] Extra environment variables to overlay onto the child's
48+
* environment, on top of (not instead of) this process's own.
4349
* @returns {Promise<UploadResult>}
4450
*/
45-
export async function runUpload (command, args) {
46-
const result = await spawnUpload(command, args)
51+
export async function runUpload (command, args, env) {
52+
const result = await spawnUpload(command, args, env)
4753
if (result.code !== 0) process.exitCode = 1
4854
return result
4955
}

scripts/upload-junit.mjs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { runUpload } from './run-upload.mjs'
44
const INPUT_DIR = 'junit-results'
55

66
// Every sibling workflow's upload is merged into one call, so datadog-ci's own GITHUB_*-derived
7-
// Pipeline/Job facets would attribute every test to the All Green workflow instead of the one that
7+
// Pipeline/Job tags would attribute every test to the All Green workflow instead of the one that
88
// produced it. `.mochamultireporterrc.js` stamps each testsuite with its own job's CI metadata (plus
99
// `node_version`) as XML properties at mocha-run time, while that job's own GITHUB_* env vars are
1010
// still correct; these xpath-tag mappings lift those properties into real per-test tags at upload
@@ -18,6 +18,18 @@ const XPATH_TAGS = [
1818
"ci.job.name=/testcase/..//property[@name='ci.job.name']/@value",
1919
]
2020

21+
// datadog-ci derives its own ci.pipeline.name/id/number/url and ci.job.name tags directly from
22+
// these GITHUB_* variables (the All Green job's own), applying the same values to every file in
23+
// the batched upload — which would overwrite the per-test XPATH_TAGS values above. Blanking just
24+
// these four leaves every other GITHUB_*-derived tag (repository URL, PR association, commit SHA)
25+
// untouched, since those don't collide with anything XPATH_TAGS sets.
26+
const NO_PIPELINE_ATTRIBUTION_ENV = {
27+
GITHUB_WORKFLOW: '',
28+
GITHUB_JOB: '',
29+
GITHUB_RUN_ID: '',
30+
GITHUB_RUN_NUMBER: '',
31+
}
32+
2133
/**
2234
* Upload every sibling workflow's downloaded junit reports to Datadog in a single call.
2335
* `--auto-discovery` already walks `junit-results/<run-id>/<artifact-name>/*.xml` recursively and
@@ -34,6 +46,6 @@ export async function uploadAllJunit () {
3446
const result = await runUpload('datadog-ci', [
3547
'junit', 'upload', '--service', 'dd-trace-js-tests', '--auto-discovery', INPUT_DIR,
3648
...XPATH_TAGS.flatMap(tag => ['--xpath-tag', tag]),
37-
])
49+
], NO_PIPELINE_ATTRIBUTION_ENV)
3850
return [result]
3951
}

0 commit comments

Comments
 (0)