From 101c666610e16af6056e3bc1523c5e88dacf08ae Mon Sep 17 00:00:00 2001 From: Colin McDonnell Date: Fri, 16 Jan 2026 16:54:42 +0000 Subject: [PATCH] Fix capitalization issues --- entry | 35 +++++++++++++++++++++++++++ main.ts | 4 ++++ utils/normalizeEnv.ts | 56 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 utils/normalizeEnv.ts diff --git a/entry b/entry index fa15636..bffc8dc 100755 --- a/entry +++ b/entry @@ -119867,6 +119867,40 @@ ${encodedEvent}` : ""} ${runtimeContext}`; } +// utils/normalizeEnv.ts +function normalizeEnv() { + const upperKeys = /* @__PURE__ */ new Map(); + for (const key of Object.keys(process.env)) { + const upper2 = key.toUpperCase(); + const existing = upperKeys.get(upper2) || []; + existing.push(key); + upperKeys.set(upper2, existing); + } + for (const [upperKey, keys] of upperKeys) { + if (keys.length === 1) { + const key = keys[0]; + if (key !== upperKey) { + process.env[upperKey] = process.env[key]; + delete process.env[key]; + } + continue; + } + const values = keys.map((k) => process.env[k]); + const uniqueValues = new Set(values); + if (uniqueValues.size > 1) { + log.warning( + `env var conflict: ${keys.join(", ")} have different values. using uppercase ${upperKey}.` + ); + } + const preferredKey = keys.find((k) => k === upperKey) || keys[0]; + const preferredValue = process.env[preferredKey]; + for (const key of keys) { + delete process.env[key]; + } + process.env[upperKey] = preferredValue; + } +} + // utils/payload.ts import { isAbsolute, resolve } from "node:path"; var ToolPermissionInput = type.enumerated("disabled", "enabled"); @@ -138455,6 +138489,7 @@ async function resolveRunId(repoData) { async function main(core5) { var _stack2 = []; try { + normalizeEnv(); process.env.ORIGINAL_GITHUB_TOKEN = process.env.GITHUB_TOKEN; const payload = resolvePayload(core5); if (payload.cwd && process.cwd() !== payload.cwd) { diff --git a/main.ts b/main.ts index 3152387..65e5062 100644 --- a/main.ts +++ b/main.ts @@ -5,6 +5,7 @@ import { validateApiKey } from "./utils/apiKeys.ts"; import { log } from "./utils/cli.ts"; import { reportErrorToComment } from "./utils/errorReport.ts"; import { resolveInstructions } from "./utils/instructions.ts"; +import { normalizeEnv } from "./utils/normalizeEnv.ts"; import { resolvePayload } from "./utils/payload.ts"; import { resolveRepoData } from "./utils/repoData.ts"; import { resolveAgent } from "./utils/resolveAgent.ts"; @@ -25,6 +26,9 @@ export interface MainResult { export async function main(core: { getInput: (name: string, options?: { required?: boolean }) => string; }): Promise { + // normalize env var names to uppercase (handles case-insensitive workflow files) + normalizeEnv(); + // store original GITHUB_TOKEN process.env.ORIGINAL_GITHUB_TOKEN = process.env.GITHUB_TOKEN; diff --git a/utils/normalizeEnv.ts b/utils/normalizeEnv.ts new file mode 100644 index 0000000..351d2ba --- /dev/null +++ b/utils/normalizeEnv.ts @@ -0,0 +1,56 @@ +import { log } from "./cli.ts"; + +/** + * Normalize environment variables to uppercase. + * This handles case-insensitive env var names (e.g., `anthropic_api_key` -> `ANTHROPIC_API_KEY`). + * + * If there are conflicts (same key with different capitalizations but different values), + * logs a warning and keeps the uppercase version. + */ +export function normalizeEnv(): void { + const upperKeys = new Map(); + + // group keys by their uppercase form + for (const key of Object.keys(process.env)) { + const upper = key.toUpperCase(); + const existing = upperKeys.get(upper) || []; + existing.push(key); + upperKeys.set(upper, existing); + } + + // process each group + for (const [upperKey, keys] of upperKeys) { + if (keys.length === 1) { + const key = keys[0]; + if (key !== upperKey) { + // single key, just needs uppercasing + process.env[upperKey] = process.env[key]; + delete process.env[key]; + } + continue; + } + + // multiple keys with different capitalizations + const values = keys.map((k) => process.env[k]); + const uniqueValues = new Set(values); + + if (uniqueValues.size > 1) { + // conflict: different values for different capitalizations + log.warning( + `env var conflict: ${keys.join(", ")} have different values. using uppercase ${upperKey}.` + ); + } + + // prefer the uppercase version if it exists, otherwise use the first one + const preferredKey = keys.find((k) => k === upperKey) || keys[0]; + const preferredValue = process.env[preferredKey]; + + // delete all variants + for (const key of keys) { + delete process.env[key]; + } + + // set the uppercase version + process.env[upperKey] = preferredValue; + } +}