Skip to content

Allow abstracting over process.env#3993

Merged
mbg merged 2 commits into
mainfrom
mbg/env-abstraction
Jul 6, 2026
Merged

Allow abstracting over process.env#3993
mbg merged 2 commits into
mainfrom
mbg/env-abstraction

Conversation

@mbg

@mbg mbg commented Jul 6, 2026

Copy link
Copy Markdown
Member

Two straight-forward commits cherry-picked from #3990 (and, in turn, #3973) which add an Env interface that allows us to abstract over process.env so that tests don't have to run synchronously because they query process.env and can instead query a test-specific environment.

Not used in this PR, but cherry-picked so that we can hopefully merge it relatively quickly and make use of it elsewhere.

Risk assessment

For internal use only. Please select the risk level of this change:

  • Low risk: Changes are fully under feature flags, or have been fully tested and validated in pre-production environments and are highly observable, or are documentation or test only.

Which use cases does this change impact?

Environments:

  • Testing/None - This change does not impact any CodeQL workflows in production.

How did/will you validate this change?

  • None - I am not validating these changes.

If something goes wrong after this change is released, what are the mitigation and rollback strategies?

  • Development/testing only - This change cannot cause any failures in production.

How will you know if something goes wrong after this change is released?

  • Other - Please provide details.

Are there any special considerations for merging or releasing this change?

  • No special considerations - This change can be merged at any time.

Merge / deployment checklist

  • Confirm this change is backwards compatible with existing workflows.
  • Consider adding a changelog entry for this change.
  • Confirm the readme and docs have been updated if necessary.

@mbg mbg self-assigned this Jul 6, 2026
Copilot AI review requested due to automatic review settings July 6, 2026 11:30
@mbg mbg requested a review from a team as a code owner July 6, 2026 11:30
@github-actions github-actions Bot added the size/S Should be easy to review label Jul 6, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Warning

  • Copilot's review of this pull request may be incomplete because some of the changed files are excluded by your Copilot content exclusion settings. See Excluding content from Copilot for details.

Pull request overview

This PR introduces a small abstraction layer over environment access to avoid hard-coding process.env in places that need to be testable, and begins standardizing GitHub Actions environment variable names via an enum.

Changes:

  • Add an Env interface and getEnv(...) helper to abstract reads from process.env (or a provided env map).
  • Split env-var access helpers into *From(env, ...) variants plus process.env wrappers.
  • Add ActionsEnvVars enum and update some call sites/tests to use it instead of raw strings.
Show a summary per file
File Description
src/util.ts Adds Env adapter and env accessor helpers that can take a NodeJS.ProcessEnv.
src/environment.ts Defines the new Env interface used to abstract environment lookups.
src/testing-utils.ts Adds a test helper for creating an Env and tightens typing for default Actions env vars.
src/actions-util.ts Introduces ActionsEnvVars enum and replaces some raw env var strings with enum constants.
src/api-client.ts Updates env-var lookups to use ActionsEnvVars constants.
lib/entry-points.js Changed but excluded from diff (and typically generated output).

Review details

Files excluded by content exclusion policy (1)
  • lib/entry-points.js
Comments suppressed due to low confidence (1)

src/util.ts:588

  • Env.getRequired and Env.getOptional currently treat whitespace-only values differently: getOptionalEnvVarFrom treats " " as unset (via trim()), but getRequiredEnvVar accepts it because it only checks value.length === 0. This inconsistency is surprising for callers and can hide misconfiguration.
  const value = env[paramName];
  if (value === undefined || value.length === 0) {
    throw new Error(`${paramName} environment variable must be set`);
  }
  return value;
  • Files reviewed: 5/6 changed files
  • Comments generated: 3
  • Review effort level: Low

Comment thread src/testing-utils.ts
Comment thread src/actions-util.ts
Comment thread src/actions-util.ts

@sam-robson sam-robson left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM 👍🏻

@mbg mbg added this pull request to the merge queue Jul 6, 2026
Merged via the queue into main with commit ae4c8d0 Jul 6, 2026
226 checks passed
@mbg mbg deleted the mbg/env-abstraction branch July 6, 2026 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S Should be easy to review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants