Skip to content

Commit 89606bb

Browse files
henrymercerCopilot
andcommitted
Return toolcache rejection reasons with Result
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent bd2ddba commit 89606bb

3 files changed

Lines changed: 66 additions & 40 deletions

File tree

‎lib/entry-points.js‎

Lines changed: 22 additions & 15 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: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
SAMPLE_DEFAULT_CLI_VERSION,
2626
SAMPLE_DOTCOM_API_DETAILS,
2727
checkExpectedLogMessages,
28+
checkUnexpectedLogMessages,
2829
createFeatures,
2930
createTestConfig,
3031
getRecordingLogger,
@@ -331,6 +332,10 @@ test.serial(
331332
downloadDurationMs: 200,
332333
totalDurationMs: 300,
333334
});
335+
checkUnexpectedLogMessages(t, loggedMessages, [
336+
"Not caching the CodeQL tools",
337+
"Could not cache CodeQL tools",
338+
]);
334339

335340
// Ensure message logging CodeQL CLI version was present in user logs.
336341
const expected_message: string = `Using CodeQL CLI version ${LINKED_CLI_VERSION.cliVersion}`;
@@ -563,6 +568,9 @@ for (const bundlePath of [
563568
t.deepEqual(toolcache.findAllVersions("CodeQL"), []);
564569
checkExpectedLogMessages(t, messages, [
565570
`Using CodeQL CLI sourced from ${url}`,
571+
bundlePath === "codeql-bundle-ruby-linux64.tar.zst"
572+
? "Not caching the CodeQL tools because they came from a bundle that contains only a single language."
573+
: `Could not cache CodeQL tools because we could not determine the bundle version from the URL ${url}.`,
566574
]);
567575
});
568576
},
@@ -1473,6 +1481,7 @@ for (const asset of [
14731481
`setupCodeQLBundle keeps explicitly requested ${asset} out of the toolcache`,
14741482
async (t) => {
14751483
const extractStub = stubDownloadAndExtract();
1484+
const messages: LoggedMessage[] = [];
14761485
const url = `https://github.com/github/codeql-action/releases/download/codeql-bundle-v9.9.9/${asset}`;
14771486
process.env[ActionsEnvVars.RUNNER_ENVIRONMENT] = "self-hosted";
14781487

@@ -1487,7 +1496,7 @@ for (const asset of [
14871496
undefined, // rawLanguages
14881497
false, // useOverlayAwareDefaultCliVersion
14891498
createFeatures([]),
1490-
getRunnerLogger(true),
1499+
getRecordingLogger(messages),
14911500
);
14921501

14931502
t.true(extractStub.calledOnce);
@@ -1500,6 +1509,12 @@ for (const asset of [
15001509
t.is(path.dirname(result.codeqlFolder), tmpDir);
15011510
t.deepEqual(toolcache.findAllVersions("CodeQL"), []);
15021511
t.false(fs.existsSync(`${result.codeqlFolder}.complete`));
1512+
checkExpectedLogMessages(t, messages, [
1513+
"Not caching the CodeQL tools because they came from a bundle that contains only a single language.",
1514+
]);
1515+
checkUnexpectedLogMessages(t, messages, [
1516+
"Could not cache CodeQL tools because we could not determine the bundle version",
1517+
]);
15031518
});
15041519
},
15051520
);

‎src/setup-codeql.ts‎

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -879,9 +879,10 @@ export const downloadCodeQL = async function (
879879
);
880880
}
881881

882-
const toolcacheDestination = getToolcacheDestination(source, logger);
883-
const extractedBundlePath =
884-
toolcacheDestination ?? getTempExtractionDir(tempDir);
882+
const toolcacheDestination = getToolcacheDestination({ logger }, source);
883+
const extractedBundlePath = toolcacheDestination.isSuccess()
884+
? toolcacheDestination.value
885+
: getTempExtractionDir(tempDir);
885886

886887
const statusReport = await downloadAndExtract(
887888
codeqlURL,
@@ -893,16 +894,10 @@ export const downloadCodeQL = async function (
893894
logger,
894895
);
895896

896-
if (toolcacheDestination) {
897-
writeToolcacheMarkerFile(toolcacheDestination, logger);
897+
if (toolcacheDestination.isSuccess()) {
898+
writeToolcacheMarkerFile(toolcacheDestination.value, logger);
898899
} else {
899-
logger.debug(
900-
bundle.kind === "per-language"
901-
? "Not caching the CodeQL tools because they came from a bundle that contains only a " +
902-
"single language."
903-
: "Could not cache CodeQL tools because we could not determine the bundle version from the " +
904-
`URL ${codeqlURL}.`,
905-
);
900+
logger.debug(toolcacheDestination.value);
906901
}
907902

908903
return {
@@ -915,23 +910,32 @@ export const downloadCodeQL = async function (
915910
};
916911

917912
/**
918-
* Returns the canonical toolcache directory for a combined bundle with a known version.
919-
* Returns undefined for per-language bundles or unknown versions.
913+
* Returns the canonical toolcache directory, or the reason the bundle cannot be cached.
920914
*/
921915
function getToolcacheDestination(
916+
{ logger }: ActionState<["Logger"]>,
922917
source: CodeQLDownloadSource,
923-
logger: Logger,
924-
): string | undefined {
925-
// Per-language bundles must not be stored in the toolcache.
926-
if (source.bundle.kind !== "combined" || !source.bundleVersion) {
927-
return undefined;
918+
): util.Result<string, string> {
919+
if (source.bundle.kind !== "combined") {
920+
return new util.Failure(
921+
"Not caching the CodeQL tools because they came from a bundle that contains only a " +
922+
"single language.",
923+
);
924+
}
925+
if (!source.bundleVersion) {
926+
return new util.Failure(
927+
"Could not cache CodeQL tools because we could not determine the bundle version from the " +
928+
`URL ${source.bundle.url}.`,
929+
);
928930
}
929931

930-
return getToolcacheDirectory(
931-
getCanonicalToolcacheVersion(
932-
source.cliVersion,
933-
source.bundleVersion,
934-
logger,
932+
return new util.Success(
933+
getToolcacheDirectory(
934+
getCanonicalToolcacheVersion(
935+
source.cliVersion,
936+
source.bundleVersion,
937+
logger,
938+
),
935939
),
936940
);
937941
}

0 commit comments

Comments
 (0)