From 0e6852c442d3f40e1c6f7a7e51730887cc1f5532 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 14 Aug 2026 04:03:52 +0000 Subject: [PATCH 1/2] Simplify action_setup_otlp.cjs: dedupe conditional writeEnvLine calls Extract a writeIfValid helper to remove repeated if(isValid...) writeEnvLine(...) patterns for trace-id/span-id/parent-span-id output and env propagation. Behavior unchanged; all log messages and file writes are identical. Source: recent activity around #52565 (shared prompt extraction) and #52542 (shared reporting import) motivated looking for similar duplication-reduction opportunities in actions/setup/js. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- actions/setup/js/action_setup_otlp.cjs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/actions/setup/js/action_setup_otlp.cjs b/actions/setup/js/action_setup_otlp.cjs index 76759462018..48892953a76 100644 --- a/actions/setup/js/action_setup_otlp.cjs +++ b/actions/setup/js/action_setup_otlp.cjs @@ -171,17 +171,30 @@ async function run() { const githubOutput = process.env.GITHUB_OUTPUT; const githubEnv = process.env.GITHUB_ENV; + /** + * Write a key=value line to filePath only if isValid(value) holds. + * @param {string | undefined} filePath + * @param {string} key + * @param {string} value + * @param {string} logLabel - Label used in the confirmation log message + * @param {string} fileLabel + * @param {(value: string) => boolean} isValid + */ + const writeIfValid = (filePath, key, value, logLabel, fileLabel, isValid) => { + if (isValid(value)) writeEnvLine(filePath, key, value, logLabel, fileLabel); + }; + // Always expose trace ID as a step output for cross-job correlation, even // when OTLP is not configured. This ensures needs.*.outputs.setup-trace-id // is populated for downstream jobs regardless of observability configuration. - if (isValidTraceId(traceId)) writeEnvLine(githubOutput, "trace-id", traceId, `trace-id=${traceId}`, "GITHUB_OUTPUT"); - if (isValidSpanId(spanId)) writeEnvLine(githubOutput, "span-id", spanId, `span-id=${spanId}`, "GITHUB_OUTPUT"); - if (isValidSpanId(parentSpanId)) writeEnvLine(githubOutput, "parent-span-id", parentSpanId, `parent-span-id=${parentSpanId}`, "GITHUB_OUTPUT"); + writeIfValid(githubOutput, "trace-id", traceId, `trace-id=${traceId}`, "GITHUB_OUTPUT", isValidTraceId); + writeIfValid(githubOutput, "span-id", spanId, `span-id=${spanId}`, "GITHUB_OUTPUT", isValidSpanId); + writeIfValid(githubOutput, "parent-span-id", parentSpanId, `parent-span-id=${parentSpanId}`, "GITHUB_OUTPUT", isValidSpanId); // Always propagate trace/span context to subsequent steps in this job so // that the conclusion span can find the same trace ID. - if (isValidTraceId(traceId)) writeEnvLine(githubEnv, "GITHUB_AW_OTEL_TRACE_ID", traceId, "GITHUB_AW_OTEL_TRACE_ID", "GITHUB_ENV"); - if (isValidSpanId(spanId)) writeEnvLine(githubEnv, "GITHUB_AW_OTEL_PARENT_SPAN_ID", spanId, "GITHUB_AW_OTEL_PARENT_SPAN_ID", "GITHUB_ENV"); + writeIfValid(githubEnv, "GITHUB_AW_OTEL_TRACE_ID", traceId, "GITHUB_AW_OTEL_TRACE_ID", "GITHUB_ENV", isValidTraceId); + writeIfValid(githubEnv, "GITHUB_AW_OTEL_PARENT_SPAN_ID", spanId, "GITHUB_AW_OTEL_PARENT_SPAN_ID", "GITHUB_ENV", isValidSpanId); // Propagate setup-end timestamp so the conclusion span can measure actual // job execution duration (setup-end → conclusion-start). if (githubEnv) { From e540029265ef1d89251f4d1b09a33e31672bdd25 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 14 Aug 2026 06:35:56 +0000 Subject: [PATCH 2/2] Refine writeIfValid helper docs and expression form Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com> --- actions/setup/js/action_setup_otlp.cjs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/actions/setup/js/action_setup_otlp.cjs b/actions/setup/js/action_setup_otlp.cjs index 48892953a76..188e9d5aa8c 100644 --- a/actions/setup/js/action_setup_otlp.cjs +++ b/actions/setup/js/action_setup_otlp.cjs @@ -172,17 +172,10 @@ async function run() { const githubEnv = process.env.GITHUB_ENV; /** - * Write a key=value line to filePath only if isValid(value) holds. * @param {string | undefined} filePath - * @param {string} key - * @param {string} value - * @param {string} logLabel - Label used in the confirmation log message - * @param {string} fileLabel * @param {(value: string) => boolean} isValid */ - const writeIfValid = (filePath, key, value, logLabel, fileLabel, isValid) => { - if (isValid(value)) writeEnvLine(filePath, key, value, logLabel, fileLabel); - }; + const writeIfValid = (filePath, key, value, logLabel, fileLabel, isValid) => isValid(value) && writeEnvLine(filePath, key, value, logLabel, fileLabel); // Always expose trace ID as a step output for cross-job correlation, even // when OTLP is not configured. This ensures needs.*.outputs.setup-trace-id