Allow abstracting over process.env#3993
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
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
Envinterface andgetEnv(...)helper to abstract reads fromprocess.env(or a provided env map). - Split env-var access helpers into
*From(env, ...)variants plusprocess.envwrappers. - Add
ActionsEnvVarsenum 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.getRequiredandEnv.getOptionalcurrently treat whitespace-only values differently:getOptionalEnvVarFromtreats" "as unset (viatrim()), butgetRequiredEnvVaraccepts it because it only checksvalue.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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two straight-forward commits cherry-picked from #3990 (and, in turn, #3973) which add an
Envinterface that allows us to abstract overprocess.envso that tests don't have to run synchronously because they queryprocess.envand 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:
Which use cases does this change impact?
Environments:
How did/will you validate this change?
If something goes wrong after this change is released, what are the mitigation and rollback strategies?
How will you know if something goes wrong after this change is released?
Are there any special considerations for merging or releasing this change?
Merge / deployment checklist