Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c05a5b7
Add `ActionsEnvVars` enum
mbg Jun 16, 2026
652296e
Allow abstracting over `process.env`
mbg Jun 16, 2026
9c4ee01
Add `RemoteFileAddress` type
mbg Jun 23, 2026
07b6b1e
Move `getRemoteConfig` to `config/file.ts`
mbg Jun 23, 2026
9ef8be7
Refactor `parseRemoteFileAddress` out of `getRemoteConfig`
mbg Jun 23, 2026
82e5ca6
Return `RemoteFileAddress` from `parseRemoteFileAddress`
mbg Jun 23, 2026
c7a94c9
Add `getRemoteConfig` JSDoc
mbg Jun 23, 2026
85c8a8c
Add tests for `parseRemoteFileAddress`
mbg Jun 23, 2026
598d008
Make `ref` optional in `parseRemoteFileAddress`
mbg Jun 23, 2026
e537ff2
Make `path` optional in `parseRemoteFileAddress`
mbg Jun 23, 2026
12821cf
Make `owner` optional in `parseRemoteFileAddress`
mbg Jun 23, 2026
81ad479
Fix test names
mbg Jun 23, 2026
8102fa6
Anchor regex and trim input
mbg Jun 23, 2026
00e5a58
Update format in error message
mbg Jun 23, 2026
8d69da9
Improve whitespace handling
mbg Jun 23, 2026
3fe7ef9
Fix `getEnv` not using `getOptionalEnvVarFrom`
mbg Jun 23, 2026
812b882
Merge remote-tracking branch 'origin/main' into mbg/repo-props/config…
mbg Jun 23, 2026
f77cf55
Support old and new formats
mbg Jun 26, 2026
d8d1d6d
Add FF for shorthands
mbg Jun 24, 2026
e446d55
Add initial `ActionState` type
mbg Jun 30, 2026
f86aa52
Use `ActionState` for `getRemoteConfig`
mbg Jun 30, 2026
7b2af89
Add `TestEnv` class to simplify testing of `ActionState`-dependent fu…
mbg Jun 30, 2026
b6be81d
Gate new remote file format behind FF
mbg Jun 30, 2026
708e106
Index `ActionState` over the types of state used
mbg Jun 30, 2026
5094019
Refactor `Config` type out of `config-utils`
mbg Jul 6, 2026
73f4741
Refactor pack registry code out of `config-utils`
mbg Jul 6, 2026
69c9e8c
Mark some `status-report` imports as `type`-only to avoid circular de…
mbg Jul 6, 2026
8e22350
Thread `ActionState` to `initConfig`
mbg Jul 6, 2026
7dc37cb
Merge remote-tracking branch 'origin/main' into mbg/repo-props/config…
mbg Jul 6, 2026
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
Prev Previous commit
Next Next commit
Allow abstracting over process.env
  • Loading branch information
mbg committed Jun 23, 2026
commit 652296eb9e76be692cbe3c9faa47dec498736254
14 changes: 10 additions & 4 deletions lib/entry-points.js

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

8 changes: 8 additions & 0 deletions src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,11 @@ export enum EnvVar {
/** Used by Code Scanning Risk Assessment to communicate the assessment ID to the CodeQL Action. */
RISK_ASSESSMENT_ID = "CODEQL_ACTION_RISK_ASSESSMENT_ID",
}

/** A wrapper around an environment, to allow abstracting away from `process.env` in tests. */
export interface Env {
/** Tries to get the value for `name` and throws if there isn't one. */
getRequired(name: string): string;
/** Gets the value for `name`, or `undefined` if it isn't set or empty. */
getOptional(name: string): string | undefined;
}
7 changes: 7 additions & 0 deletions src/testing-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { CachingKind } from "./caching-utils";
import * as codeql from "./codeql";
import { Config } from "./config-utils";
import * as defaults from "./defaults.json";
import { Env } from "./environment";
import {
CodeQLDefaultVersionInfo,
Feature,
Expand All @@ -29,6 +30,7 @@ import { OverlayDatabaseMode } from "./overlay/overlay-database-mode";
import {
DEFAULT_DEBUG_ARTIFACT_NAME,
DEFAULT_DEBUG_DATABASE_NAME,
getEnv,
GitHubVariant,
GitHubVersion,
HTTPError,
Expand Down Expand Up @@ -172,6 +174,11 @@ export function makeMacro<Args extends unknown[]>(
return wrapper;
}

export function getTestEnv(): Env {
const testEnv: NodeJS.ProcessEnv = {};
return getEnv(testEnv);
}

/**
* Gets an `ActionsEnv` instance for use in tests.
*/
Expand Down
42 changes: 35 additions & 7 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import * as apiCompatibility from "./api-compatibility.json";
import type { CodeQL, VersionInfo } from "./codeql";
import type { Pack } from "./config/db-config";
import type { Config } from "./config-utils";
import { EnvVar } from "./environment";
import { Env, EnvVar } from "./environment";
import * as json from "./json";
import { Language } from "./languages";
import { Logger } from "./logging";
Expand Down Expand Up @@ -566,28 +566,56 @@ export function initializeEnvironment(version: string) {
core.exportVariable(EnvVar.VERSION, version);
}

/** Gets an `Env` instance for `env`, which is `process.env` by default. */
export function getEnv(env: NodeJS.ProcessEnv = process.env): Env {
return {
getRequired: (name) => getRequiredEnvVar(env, name),
getOptional: (name) => getOptionalEnvVar(name),
};
}
Comment thread
mbg marked this conversation as resolved.
Resolved

/**
* Get an environment parameter, but throw an error if it is not set.
* Gets an environment variable, but throws an error if it is not set.
*/
export function getRequiredEnvParam(paramName: string): string {
const value = process.env[paramName];
export function getRequiredEnvVar(
env: NodeJS.ProcessEnv,
paramName: string,
): string {
const value = env[paramName];
if (value === undefined || value.length === 0) {
throw new Error(`${paramName} environment variable must be set`);
}
return value;
}

/**
* Get an environment variable, but return `undefined` if it is not set or empty.
* Get an environment parameter, but throw an error if it is not set.
*/
export function getOptionalEnvVar(paramName: string): string | undefined {
const value = process.env[paramName];
export function getRequiredEnvParam(paramName: string): string {
return getRequiredEnvVar(process.env, paramName);
}

/**
* Gets an environment variable, but returns `undefined` if it is not set or empty.
*/
export function getOptionalEnvVarFrom(
env: NodeJS.ProcessEnv,
paramName: string,
): string | undefined {
const value = env[paramName];
if (value?.trim().length === 0) {
return undefined;
}
return value;
}

/**
* Get an environment variable, but return `undefined` if it is not set or empty.
*/
export function getOptionalEnvVar(paramName: string): string | undefined {
return getOptionalEnvVarFrom(process.env, paramName);
}

export class HTTPError extends Error {
public status: number;

Expand Down