-
Notifications
You must be signed in to change notification settings - Fork 458
Do not use core.exportVariable in unit tests
#3930
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| import * as core from "@actions/core"; | ||
|
|
||
| /** | ||
| * Environment variables used by the CodeQL Action. | ||
| * | ||
|
|
@@ -154,3 +156,29 @@ 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", | ||
| } | ||
|
|
||
| /** | ||
| * Returns whether we are in test mode. This is used by CodeQL Action PR checks. | ||
| * | ||
| * In test mode, we skip several uploads (SARIF results, status reports, DBs, ...). | ||
| */ | ||
| export function isInTestMode(): boolean { | ||
| return process.env[EnvVar.TEST_MODE] === "true"; | ||
| } | ||
|
|
||
| /** | ||
| * Wrapper around `core.exportVariable` which does not call `core.exportVariable` | ||
| * when running unit tests. This is important, because otherwise `core.exportVariable` | ||
| * sets environment variables for other steps in a workflow when we run unit tests in CI. | ||
| */ | ||
| export function exportVariable(name: string, val: any): void { | ||
| if (process.env["NODE_ENV"] === "test") { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this just use the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The |
||
| // Setting the environment variable for the current process is OK since we reset | ||
| // those at the end of each test. This allows tests to pass that rely on that | ||
| // part of the `core.exportVariable` behaviour. | ||
| process.env[name] = val; | ||
| } else { | ||
| // Call `core.exportVariable` whenever we are not in a test environment. | ||
| core.exportVariable(name, val); | ||
| } | ||
|
mbg marked this conversation as resolved.
|
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.