Skip to content

Commit d5f0374

Browse files
committed
Force nightly bundle when FF is enabled
1 parent 466a4f0 commit d5f0374

File tree

8 files changed

+149
-29
lines changed

8 files changed

+149
-29
lines changed

lib/analyze-action.js

Lines changed: 12 additions & 4 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: 12 additions & 4 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: 12 additions & 4 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: 12 additions & 4 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: 12 additions & 4 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: 12 additions & 4 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: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,65 @@ test("getCodeQLSource correctly returns nightly CLI version when tools == nightl
329329
});
330330
});
331331

332+
test("getCodeQLSource correctly returns nightly CLI version when forced by FF", async (t) => {
333+
const loggedMessages: LoggedMessage[] = [];
334+
const logger = getRecordingLogger(loggedMessages);
335+
const features = createFeatures([Feature.ForceNightly]);
336+
337+
process.env["GITHUB_EVENT_NAME"] = "dynamic";
338+
339+
const expectedDate = "30260213";
340+
const expectedTag = `codeql-bundle-${expectedDate}`;
341+
342+
// Ensure that we consistently select "zstd" for the test.
343+
sinon.stub(process, "platform").value("linux");
344+
sinon.stub(tar, "isZstdAvailable").resolves({
345+
available: true,
346+
foundZstdBinary: true,
347+
});
348+
349+
const client = github.getOctokit("123");
350+
const listReleases = sinon.stub(client.rest.repos, "listReleases");
351+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
352+
listReleases.resolves({
353+
data: [{ tag_name: expectedTag }],
354+
} as any);
355+
sinon.stub(api, "getApiClient").value(() => client);
356+
357+
await withTmpDir(async (tmpDir) => {
358+
setupActionsVars(tmpDir, tmpDir);
359+
const source = await setupCodeql.getCodeQLSource(
360+
undefined,
361+
SAMPLE_DEFAULT_CLI_VERSION,
362+
SAMPLE_DOTCOM_API_DETAILS,
363+
GitHubVariant.DOTCOM,
364+
false,
365+
features,
366+
logger,
367+
);
368+
369+
// Check that the `CodeQLToolsSource` object matches our expectations.
370+
const expectedVersion = `0.0.0-${expectedDate}`;
371+
const expectedURL = `https://github.com/dsp-testing/codeql-cli-nightlies/releases/download/${expectedTag}/${setupCodeql.getCodeQLBundleName("zstd")}`;
372+
t.deepEqual(source, {
373+
bundleVersion: expectedDate,
374+
cliVersion: undefined,
375+
codeqlURL: expectedURL,
376+
compressionMethod: "zstd",
377+
sourceType: "download",
378+
toolsVersion: expectedVersion,
379+
} satisfies setupCodeql.CodeQLToolsSource);
380+
381+
// Afterwards, ensure that we see the expected messages in the log.
382+
checkExpectedLogMessages(t, loggedMessages, [
383+
`Using the latest CodeQL CLI nightly, as forced by the ${Feature.ForceNightly} feature flag.`,
384+
`Bundle version ${expectedDate} is not in SemVer format. Will treat it as pre-release ${expectedVersion}.`,
385+
`Attempting to obtain CodeQL tools. CLI version: unknown, bundle tag name: ${expectedTag}`,
386+
`Using CodeQL CLI sourced from ${expectedURL}`,
387+
]);
388+
});
389+
});
390+
332391
test("getCodeQLSource correctly returns latest version from toolcache when tools == toolcache", async (t) => {
333392
const loggedMessages: LoggedMessage[] = [];
334393
const logger = getRecordingLogger(loggedMessages);

src/setup-codeql.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -321,13 +321,26 @@ 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.
326+
const forceNightlyValueFF = await features.getValue(Feature.ForceNightly);
327+
const forceNightly =
328+
forceNightlyValueFF && (isDynamicWorkflow() || util.isInTestMode());
329+
324330
if (
325-
toolsInput !== undefined &&
326-
CODEQL_NIGHTLY_TOOLS_INPUTS.includes(toolsInput)
331+
forceNightly ||
332+
(toolsInput !== undefined &&
333+
CODEQL_NIGHTLY_TOOLS_INPUTS.includes(toolsInput))
327334
) {
328-
logger.info(
329-
`Using the latest CodeQL CLI nightly, as requested by 'tools: ${toolsInput}'.`,
330-
);
335+
if (forceNightly) {
336+
logger.info(
337+
`Using the latest CodeQL CLI nightly, as forced by the ${Feature.ForceNightly} feature flag.`,
338+
);
339+
} else {
340+
logger.info(
341+
`Using the latest CodeQL CLI nightly, as requested by 'tools: ${toolsInput}'.`,
342+
);
343+
}
331344
toolsInput = await getNightlyToolsUrl(logger);
332345
}
333346

0 commit comments

Comments
 (0)