Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 7 additions & 22 deletions actions/setup/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions actions/setup/js/action_conclusion_otlp.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
*/

const sendOtlpSpan = require("./send_otlp_span.cjs");
const { getActionInput } = require("./action_input_utils.cjs");

/**
* Send the OTLP job-conclusion span. Non-fatal: all errors are silently
Expand All @@ -48,9 +49,7 @@ async function run() {
const rawJobStartMs = parseInt(process.env.GITHUB_AW_OTEL_JOB_START_MS || "0", 10);
const startMs = rawJobStartMs > 0 ? rawJobStartMs : undefined;

// Normalize job-name input: handle both INPUT_JOB_NAME (underscore, standard)
// and INPUT_JOB-NAME (hyphen, used by some runner versions).
const jobName = (process.env.INPUT_JOB_NAME || process.env["INPUT_JOB-NAME"] || "").trim();
const jobName = getActionInput("JOB_NAME");
const spanName = jobName ? `gh-aw.${jobName}.conclusion` : "gh-aw.job.conclusion";
console.log(`[otlp] sending conclusion span "${spanName}" to ${endpoint}`);

Expand Down
20 changes: 20 additions & 0 deletions actions/setup/js/action_input_utils.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// @ts-check
"use strict";

/**
* Read a GitHub Actions input value, handling both the standard underscore form
* (INPUT_<NAME>) and the hyphen form (INPUT_<NAM-E>) preserved by some runner versions.
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doc comment uses the placeholder INPUT_<NAM-E>, which looks like a typo and is confusing (it suggests a character was dropped). Consider rewording to something like INPUT_<NAME-WITH-HYPHENS> or giving a concrete example (e.g. INPUT_JOB-NAME) so the underscore vs hyphen forms are unambiguous.

Suggested change
* (INPUT_<NAME>) and the hyphen form (INPUT_<NAM-E>) preserved by some runner versions.
* (INPUT_<NAME>) and the hyphen form (INPUT_<NAME-WITH-HYPHENS>) preserved by some runner versions.

Copilot uses AI. Check for mistakes.
*
* GitHub Actions converts input names to INPUT_<UPPER_UNDERSCORE> by default, but
* some runner versions preserve the original hyphen from the input name. Checking
* both forms ensures the value is resolved regardless of the runner version.
*
* @param {string} name - Input name in UPPER_UNDERSCORE form (e.g. "JOB_NAME")
* @returns {string} Trimmed input value, or "" if not set.
*/
function getActionInput(name) {
const hyphenName = name.replace(/_/g, "-");
return (process.env[`INPUT_${name}`] || process.env[`INPUT_${hyphenName}`] || "").trim();
}

module.exports = { getActionInput };
57 changes: 57 additions & 0 deletions actions/setup/js/action_input_utils.test.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// @ts-check
import { describe, it, expect, beforeEach, afterEach } from "vitest";
import { createRequire } from "module";

const req = createRequire(import.meta.url);
const { getActionInput } = req("./action_input_utils.cjs");

describe("getActionInput", () => {
let originalEnv;

beforeEach(() => {
originalEnv = {
INPUT_JOB_NAME: process.env.INPUT_JOB_NAME,
"INPUT_JOB-NAME": process.env["INPUT_JOB-NAME"],
};
delete process.env.INPUT_JOB_NAME;
delete process.env["INPUT_JOB-NAME"];
});

afterEach(() => {
if (originalEnv.INPUT_JOB_NAME !== undefined) {
process.env.INPUT_JOB_NAME = originalEnv.INPUT_JOB_NAME;
} else {
delete process.env.INPUT_JOB_NAME;
}
if (originalEnv["INPUT_JOB-NAME"] !== undefined) {
process.env["INPUT_JOB-NAME"] = originalEnv["INPUT_JOB-NAME"];
} else {
delete process.env["INPUT_JOB-NAME"];
}
});

it("returns the underscore form value when set", () => {
process.env.INPUT_JOB_NAME = "agent";
expect(getActionInput("JOB_NAME")).toBe("agent");
});

it("returns the hyphen form value when only the hyphen form is set", () => {
process.env["INPUT_JOB-NAME"] = "agent";
expect(getActionInput("JOB_NAME")).toBe("agent");
});

it("prefers the underscore form over the hyphen form", () => {
process.env.INPUT_JOB_NAME = "underscore-value";
process.env["INPUT_JOB-NAME"] = "hyphen-value";
expect(getActionInput("JOB_NAME")).toBe("underscore-value");
});

it("trims whitespace from the returned value", () => {
process.env.INPUT_JOB_NAME = " agent ";
expect(getActionInput("JOB_NAME")).toBe("agent");
});

it("returns empty string when neither form is set", () => {
expect(getActionInput("JOB_NAME")).toBe("");
});
});
16 changes: 5 additions & 11 deletions actions/setup/js/action_setup_otlp.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
const path = require("path");
const { appendFileSync } = require("fs");
const { nowMs } = require("./performance_now.cjs");
const { getActionInput } = require("./action_input_utils.cjs");

/**
* Send the OTLP job-setup span and propagate trace context via GITHUB_OUTPUT /
Expand All @@ -48,24 +49,17 @@ async function run() {
// Explicitly read INPUT_TRACE_ID and pass it as options.traceId so the
// activation job's trace ID is used even when process.env propagation
// through GitHub Actions expression evaluation is unreliable.
// Also handle INPUT_TRACE-ID (with hyphen) in case the runner preserves
// the original input name hyphen instead of converting it to an underscore.
const inputTraceId = (process.env.INPUT_TRACE_ID || process.env["INPUT_TRACE-ID"] || "").trim().toLowerCase();
const inputTraceId = getActionInput("TRACE_ID").toLowerCase();
if (inputTraceId) {
console.log(`[otlp] INPUT_TRACE_ID=${inputTraceId} (will reuse activation trace)`);
} else {
console.log("[otlp] INPUT_TRACE_ID not set, a new trace ID will be generated");
}

// Normalize job-name input: handle both INPUT_JOB_NAME (underscore, standard)
// and INPUT_JOB-NAME (hyphen, used by some runner versions). Mirror the same
// two-key lookup that INPUT_TRACE_ID uses above so script-mode invocations
// (setup.sh → node action_setup_otlp.cjs) always resolve the job name even
// when the runner preserves the original hyphen in the env var name.
const inputJobName = (process.env.INPUT_JOB_NAME || process.env["INPUT_JOB-NAME"] || "").trim();
// Normalize to the canonical underscore form so sendJobSetupSpan (which
// reads process.env.INPUT_JOB_NAME) always finds the value.
const inputJobName = getActionInput("JOB_NAME");
if (inputJobName) {
// Normalise to the canonical underscore form so sendJobSetupSpan (which
// reads process.env.INPUT_JOB_NAME) always finds the value.
process.env.INPUT_JOB_NAME = inputJobName;
}

Expand Down
Loading