Skip to content

Commit 0b20485

Browse files
committed
Write toolcache marker file
1 parent 028cece commit 0b20485

File tree

6 files changed

+59
-29
lines changed

6 files changed

+59
-29
lines changed

lib/setup-codeql.js

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

lib/setup-codeql.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/tools-download.js

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

lib/tools-download.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/setup-codeql.ts

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
downloadAndExtract,
2424
getToolcacheDirectory,
2525
ToolsDownloadStatusReport,
26+
writeToolcacheMarkerFile,
2627
} from "./tools-download";
2728
import * as util from "./util";
2829
import { cleanUpGlob, isGoodVersion } from "./util";
@@ -571,31 +572,37 @@ export const downloadCodeQL = async function (
571572
};
572573
}
573574

574-
logger.debug("Caching CodeQL bundle.");
575-
const toolcacheStart = performance.now();
576-
const toolcachedBundlePath = await toolcache.cacheDir(
577-
extractedBundlePath,
578-
"CodeQL",
579-
toolcacheInfo.version,
580-
);
581-
582-
logger.info(
583-
`Added CodeQL bundle to the tool cache (${formatDuration(
584-
performance.now() - toolcacheStart,
585-
)}).`,
586-
);
575+
let codeqlFolder = extractedBundlePath;
587576

588-
// Defensive check: we expect `cacheDir` to copy the bundle to a new location.
589-
if (toolcachedBundlePath !== extractedBundlePath) {
590-
await cleanUpGlob(
577+
if (extractToToolcache) {
578+
writeToolcacheMarkerFile(toolcacheInfo.path, logger);
579+
} else {
580+
logger.debug("Caching CodeQL bundle.");
581+
const toolcacheStart = performance.now();
582+
codeqlFolder = await toolcache.cacheDir(
591583
extractedBundlePath,
592-
"CodeQL bundle from temporary directory",
593-
logger,
584+
"CodeQL",
585+
toolcacheInfo.version,
586+
);
587+
588+
logger.info(
589+
`Added CodeQL bundle to the tool cache (${formatDuration(
590+
performance.now() - toolcacheStart,
591+
)}).`,
594592
);
593+
594+
// Defensive check: we expect `cacheDir` to copy the bundle to a new location.
595+
if (codeqlFolder !== extractedBundlePath) {
596+
await cleanUpGlob(
597+
extractedBundlePath,
598+
"CodeQL bundle from temporary directory",
599+
logger,
600+
);
601+
}
595602
}
596603

597604
return {
598-
codeqlFolder: toolcachedBundlePath,
605+
codeqlFolder,
599606
statusReport,
600607
toolsVersion: maybeCliVersion ?? toolcacheInfo.version,
601608
};

src/tools-download.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as fs from "fs";
12
import { IncomingMessage, OutgoingHttpHeaders, RequestOptions } from "http";
23
import * as os from "os";
34
import * as path from "path";
@@ -217,6 +218,15 @@ export function getToolcacheDirectory(version: string): string {
217218
);
218219
}
219220

221+
export function writeToolcacheMarkerFile(
222+
extractedPath: string,
223+
logger: Logger,
224+
): void {
225+
const markerFilePath = `${extractedPath}.complete`;
226+
fs.writeFileSync(markerFilePath, "");
227+
logger.debug(`Wrote marker file to ${markerFilePath}`);
228+
}
229+
220230
function sanitizeUrlForStatusReport(url: string): string {
221231
return ["github/codeql-action", "dsp-testing/codeql-cli-nightlies"].some(
222232
(repo) => url.startsWith(`https://github.com/${repo}/releases/download/`),

0 commit comments

Comments
 (0)