Skip to content

Commit 8b734d3

Browse files
committed
Improve variable names and comments
Also set default `GITHUB_EVENT_NAME` in `setupActionsVars`
1 parent a61e3cb commit 8b734d3

File tree

9 files changed

+45
-29
lines changed

9 files changed

+45
-29
lines changed

lib/analyze-action.js

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/init-action-post.js

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/init-action.js

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/setup-codeql-action.js

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/upload-lib.js

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/upload-sarif-action.js

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/setup-codeql.test.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,6 @@ test("getCodeQLSource correctly returns nightly CLI version when forced by FF",
334334
const logger = getRecordingLogger(loggedMessages);
335335
const features = createFeatures([Feature.ForceNightly]);
336336

337-
process.env["GITHUB_EVENT_NAME"] = "dynamic";
338-
339337
const expectedDate = "30260213";
340338
const expectedTag = `codeql-bundle-${expectedDate}`;
341339

@@ -356,6 +354,8 @@ test("getCodeQLSource correctly returns nightly CLI version when forced by FF",
356354

357355
await withTmpDir(async (tmpDir) => {
358356
setupActionsVars(tmpDir, tmpDir);
357+
process.env["GITHUB_EVENT_NAME"] = "dynamic";
358+
359359
const source = await setupCodeql.getCodeQLSource(
360360
undefined,
361361
SAMPLE_DEFAULT_CLI_VERSION,
@@ -393,8 +393,6 @@ test("getCodeQLSource correctly returns latest version from toolcache when tools
393393
const logger = getRecordingLogger(loggedMessages);
394394
const features = createFeatures([Feature.AllowToolcacheInput]);
395395

396-
process.env["GITHUB_EVENT_NAME"] = "dynamic";
397-
398396
const latestToolcacheVersion = "3.2.1";
399397
const latestVersionPath = "/path/to/latest";
400398
const testVersions = ["2.3.1", latestToolcacheVersion, "1.2.3"];
@@ -408,6 +406,8 @@ test("getCodeQLSource correctly returns latest version from toolcache when tools
408406

409407
await withTmpDir(async (tmpDir) => {
410408
setupActionsVars(tmpDir, tmpDir);
409+
process.env["GITHUB_EVENT_NAME"] = "dynamic";
410+
411411
const source = await setupCodeql.getCodeQLSource(
412412
"toolcache",
413413
SAMPLE_DEFAULT_CLI_VERSION,
@@ -463,16 +463,17 @@ const toolcacheInputFallbackMacro = test.macro({
463463
const logger = getRecordingLogger(loggedMessages);
464464
const features = createFeatures(featureList);
465465

466-
for (const [k, v] of Object.entries(environment)) {
467-
process.env[k] = v;
468-
}
469-
470466
const findAllVersionsStub = sinon
471467
.stub(toolcache, "findAllVersions")
472468
.returns(testVersions);
473469

474470
await withTmpDir(async (tmpDir) => {
475471
setupActionsVars(tmpDir, tmpDir);
472+
473+
for (const [k, v] of Object.entries(environment)) {
474+
process.env[k] = v;
475+
}
476+
476477
const source = await setupCodeql.getCodeQLSource(
477478
"toolcache",
478479
SAMPLE_DEFAULT_CLI_VERSION,

src/setup-codeql.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -321,17 +321,19 @@ export async function getCodeQLSource(
321321
*/
322322
let url: string | undefined;
323323

324-
// We only allow forcing the nightly CLI via the FF for `dynamic` events (or in test mode).
325-
// For advanced workflows, a value from `CODEQL_NIGHTLY_TOOLS_INPUTS` can be specified.
324+
// We allow forcing the nightly CLI via the FF for `dynamic` events (or in test mode) where the
325+
// `tools` input cannot be adjusted to explicitly request it.
326+
const canForceNightlyWithFF = isDynamicWorkflow() || util.isInTestMode();
326327
const forceNightlyValueFF = await features.getValue(Feature.ForceNightly);
327-
const forceNightly =
328-
forceNightlyValueFF && (isDynamicWorkflow() || util.isInTestMode());
328+
const forceNightly = forceNightlyValueFF && canForceNightlyWithFF;
329329

330-
if (
331-
forceNightly ||
332-
(toolsInput !== undefined &&
333-
CODEQL_NIGHTLY_TOOLS_INPUTS.includes(toolsInput))
334-
) {
330+
// For advanced workflows, a value from `CODEQL_NIGHTLY_TOOLS_INPUTS` can be specified explicitly
331+
// for the `tools` input in the workflow file.
332+
const nightlyRequestedByToolsInput =
333+
toolsInput !== undefined &&
334+
CODEQL_NIGHTLY_TOOLS_INPUTS.includes(toolsInput);
335+
336+
if (forceNightly || nightlyRequestedByToolsInput) {
335337
if (forceNightly) {
336338
logger.info(
337339
`Using the latest CodeQL CLI nightly, as forced by the ${Feature.ForceNightly} feature flag.`,

src/testing-utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ export function setupActionsVars(tempDir: string, toolsDir: string) {
145145
process.env["RUNNER_TEMP"] = tempDir;
146146
process.env["RUNNER_TOOL_CACHE"] = toolsDir;
147147
process.env["GITHUB_WORKSPACE"] = tempDir;
148+
process.env["GITHUB_EVENT_NAME"] = "push";
148149
}
149150

150151
export interface LoggedMessage {

0 commit comments

Comments
 (0)