Repository navigation
Conversation
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.
🟡 Changes recommended
NODE_ENV-based detection can suppress cross-step exports in real workflows that set NODE_ENV=test.
1 open finding
What changed in this PR
Introduces an environment abstraction that prevents unit tests from exporting variables to subsequent workflow steps.
Changes:
- Adds
Env.exportand test-environment detection. - Migrates environment exports away from
core.exportVariable. - Updates tests, linting, and CodeQL query configuration.
| File | Description |
|---|---|
src/environment.ts |
Adds environment export and test-mode abstractions. |
src/testing-utils.ts |
Configures isolated test environments. |
src/actions-util.ts |
Removes exporting from ActionsEnv. |
src/util.ts |
Uses the environment export wrapper. |
src/upload-lib.ts |
Migrates SARIF-related exports. |
src/status-report.ts |
Migrates status and UUID exports. |
src/setup-codeql.ts |
Migrates setup-state export. |
src/setup-codeql-action.ts |
Uses action-state environment exporting. |
src/init.ts |
Migrates deprecation-warning export. |
src/init-action.ts |
Uses action-state environment access and exporting. |
src/init-action-post.ts |
Migrates final-status exports. |
src/debug-artifacts.ts |
Migrates artifact-scan export. |
src/config-utils.ts |
Migrates TRAP-cache exports. |
src/codeql.ts |
Migrates warning-suppression export. |
src/autobuild.ts |
Migrates autobuild exports. |
src/autobuild-action.ts |
Uses action-state environment exporting. |
src/api-client.ts |
Migrates analysis-key export. |
src/analyze-action.ts |
Uses action-state environment exporting. |
src/overlay/caching.test.ts |
Updates the test-mode stub location. |
src/init.test.ts |
Updates environment export stubs. |
queries/default-setup-environment-variables.ql |
Allows NODE_ENV access. |
eslint.config.mjs |
Prohibits direct core.exportVariable use. |
lib/entry-points.js |
Generated bundle update; excluded from review. |
Files excluded by content exclusion policy (1)
- lib/entry-points.js
🧠 Review effort: Balanced
Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.
| if (!this.isTestingEnv()) { | ||
| core.exportVariable(name, val); |
There was a problem hiding this comment.
This seems like a potential concern if we have advanced setup users running CodeQL in the same job as unit tests. Hopefully that NODE_ENV variable wouldn't be exported, but I suppose it's possible. Do you think we should instead set a specific CODEQL_ACTION_ environment variable in the npm test script?
| if (!this.isTestingEnv()) { | ||
| core.exportVariable(name, val); |
There was a problem hiding this comment.
This seems like a potential concern if we have advanced setup users running CodeQL in the same job as unit tests. Hopefully that NODE_ENV variable wouldn't be exported, but I suppose it's possible. Do you think we should instead set a specific CODEQL_ACTION_ environment variable in the npm test script?
| // A basic check that we don't use `exportVariable` from `@actions/core`. This rule depends on | ||
| // the module being imported as `core`, but that is a good enough check for us. |
There was a problem hiding this comment.
A CodeQL query might be more robust, but admittedly would give feedback later on in the development loop. Perhaps it's worth having both so we catch anything missed by this rule?
There was a problem hiding this comment.
Two thoughts here:
- That could probably be for a separate PR if we want to do it?
- That said, ideally, our
exportVariablewrapper would go away sooner than later and we'd just useEnv::exporteverywhere. In that case, the linter rule could just look forexportVariableand we wouldn't have to worry about where it came from. I suppose that we could equally rename ourexportVariabletoexportEnvVaror similar now to avoid the issue now. Do you think a query would still have a benefit over the linter rule in that case?

This PR revives #3930 as per the discussion at #4198 (comment). This PR aims to accomplish the same goals as #3930, but is updated based on changes that have happened in the codebase since. The original PR description follows.
Although we already clear environment variables that are set during unit tests, that does not affect the behaviour of
core.exportVariablewhich additionally sets environment variables for subsequent steps in a workflow. If the unit tests are run in CI, thencore.exportVariablesets environment variables for subsequent steps in the workflow job which can interfere with them.This PR improves the situation by introducing a wrapper around
core.exportVariablewhich does not callcore.exportVariablewhenNODE_ENVistest(which is set automatically byava).The main change compared to the previous PR is that we now have
ReadOnlyEnvandEnvand it makes sense to integrate the logic of ourexportVariablewrapper with those.At first glance, a potential concern with using the
exportmethod of theEnvclass is that, ifNODE_ENVistest, it only stores the environment variable in theEnvinstance. Other functions which may depend on the environment variable, but still useprocess.envto access it, do not see the value. However, all of the unit tests pass, and so we can rule out that this is an issue affecting the tests.Outside of unit tests, where
NODE_ENVis not expected to be set totest, the implementation callscore.exportVariableas well, which does set the environment variable for theprocess.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?
.test.tsfiles).pr-checks).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