From 80dcb7ccdf33e958fc80b56bab2efeeef1133ddc Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Thu, 9 Jul 2026 14:31:08 +0100 Subject: [PATCH] Add `RUNNER_ENVIRONMENT` to `ActionsEnvVars` --- lib/entry-points.js | 4 ++-- src/actions-util.ts | 2 +- src/autobuild.ts | 4 ++-- src/environment.ts | 1 + src/init.test.ts | 3 ++- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/entry-points.js b/lib/entry-points.js index a84f452be..19e45627c 100644 --- a/lib/entry-points.js +++ b/lib/entry-points.js @@ -145330,7 +145330,7 @@ var getFileType = async (filePath) => { } }; function isSelfHostedRunner(env = getEnv()) { - return env.getOptional("RUNNER_ENVIRONMENT") === "self-hosted"; + return env.getOptional("RUNNER_ENVIRONMENT" /* RUNNER_ENVIRONMENT */) === "self-hosted"; } function isDynamicWorkflow(env = getEnv()) { return getWorkflowEventName(env) === "dynamic"; @@ -151679,7 +151679,7 @@ async function setupCppAutobuild(codeql, logger) { logger ); if (await features.getValue("cpp_dependency_installation_enabled" /* CppDependencyInstallation */, codeql)) { - if (process.env["RUNNER_ENVIRONMENT"] === "self-hosted" && process.env[envVar] !== "true") { + if (process.env["RUNNER_ENVIRONMENT" /* RUNNER_ENVIRONMENT */] === "self-hosted" && process.env[envVar] !== "true") { logger.info( `Disabling ${featureName} as we are on a self-hosted runner.${getWorkflowEventName() !== "dynamic" ? ` To override this, set the ${envVar} environment variable to 'true' in your workflow. See ${"https://docs.github.com/en/actions/learn-github-actions/variables#defining-environment-variables-for-a-single-workflow" /* DEFINE_ENV_VARIABLES */} for more information.` : ""}` ); diff --git a/src/actions-util.ts b/src/actions-util.ts index 9782bfb5e..12af438fb 100644 --- a/src/actions-util.ts +++ b/src/actions-util.ts @@ -275,7 +275,7 @@ export const getFileType = async (filePath: string): Promise => { }; export function isSelfHostedRunner(env: Env = getEnv()) { - return env.getOptional("RUNNER_ENVIRONMENT") === "self-hosted"; + return env.getOptional(ActionsEnvVars.RUNNER_ENVIRONMENT) === "self-hosted"; } /** Determines whether the workflow trigger is `dynamic`. */ diff --git a/src/autobuild.ts b/src/autobuild.ts index fc4983f4e..7ec6ba987 100644 --- a/src/autobuild.ts +++ b/src/autobuild.ts @@ -5,7 +5,7 @@ import { getGitHubVersion } from "./api-client"; import { CodeQL, getCodeQL } from "./codeql"; import * as configUtils from "./config-utils"; import { DocUrl } from "./doc-url"; -import { EnvVar } from "./environment"; +import { ActionsEnvVars, EnvVar } from "./environment"; import { Feature, featureConfig, initFeatures } from "./feature-flags"; import { BuiltInLanguage, Language } from "./languages"; import { Logger } from "./logging"; @@ -126,7 +126,7 @@ export async function setupCppAutobuild(codeql: CodeQL, logger: Logger) { if (await features.getValue(Feature.CppDependencyInstallation, codeql)) { // disable autoinstall on self-hosted runners unless explicitly requested if ( - process.env["RUNNER_ENVIRONMENT"] === "self-hosted" && + process.env[ActionsEnvVars.RUNNER_ENVIRONMENT] === "self-hosted" && process.env[envVar] !== "true" ) { logger.info( diff --git a/src/environment.ts b/src/environment.ts index 663a6396d..7b007d652 100644 --- a/src/environment.ts +++ b/src/environment.ts @@ -181,6 +181,7 @@ export enum ActionsEnvVars { GITHUB_SERVER_URL = "GITHUB_SERVER_URL", GITHUB_SHA = "GITHUB_SHA", GITHUB_WORKFLOW = "GITHUB_WORKFLOW", + RUNNER_ENVIRONMENT = "RUNNER_ENVIRONMENT", RUNNER_NAME = "RUNNER_NAME", RUNNER_OS = "RUNNER_OS", RUNNER_TEMP = "RUNNER_TEMP", diff --git a/src/init.test.ts b/src/init.test.ts index 88ad0c9b1..1f0d2c701 100644 --- a/src/init.test.ts +++ b/src/init.test.ts @@ -8,6 +8,7 @@ import * as sinon from "sinon"; import * as actionsUtil from "./actions-util"; import { createStubCodeQL } from "./codeql"; +import { ActionsEnvVars } from "./environment"; import { Feature } from "./feature-flags"; import { checkPacksForOverlayCompatibility, @@ -84,7 +85,7 @@ for (const { runnerEnv, ErrorConstructor, message } of [ `cleanupDatabaseClusterDirectory throws a ${ErrorConstructor.name} when cleanup fails on ${runnerEnv} runner`, async (t) => { await withTmpDir(async (tmpDir: string) => { - process.env["RUNNER_ENVIRONMENT"] = runnerEnv; + process.env[ActionsEnvVars.RUNNER_ENVIRONMENT] = runnerEnv; const dbLocation = path.resolve(tmpDir, "dbs"); fs.mkdirSync(dbLocation, { recursive: true });