Skip to content

Commit

Permalink
Write toolcache marker file
Browse files Browse the repository at this point in the history
  • Loading branch information
Henry Mercer committed Dec 3, 2024
1 parent 028cece commit 0b20485
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 29 deletions.
22 changes: 14 additions & 8 deletions lib/setup-codeql.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/setup-codeql.js.map

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions lib/tools-download.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/tools-download.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 26 additions & 19 deletions src/setup-codeql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
downloadAndExtract,
getToolcacheDirectory,
ToolsDownloadStatusReport,
writeToolcacheMarkerFile,
} from "./tools-download";
import * as util from "./util";
import { cleanUpGlob, isGoodVersion } from "./util";
Expand Down Expand Up @@ -571,31 +572,37 @@ export const downloadCodeQL = async function (
};
}

logger.debug("Caching CodeQL bundle.");
const toolcacheStart = performance.now();
const toolcachedBundlePath = await toolcache.cacheDir(
extractedBundlePath,
"CodeQL",
toolcacheInfo.version,
);

logger.info(
`Added CodeQL bundle to the tool cache (${formatDuration(
performance.now() - toolcacheStart,
)}).`,
);
let codeqlFolder = extractedBundlePath;

// Defensive check: we expect `cacheDir` to copy the bundle to a new location.
if (toolcachedBundlePath !== extractedBundlePath) {
await cleanUpGlob(
if (extractToToolcache) {
writeToolcacheMarkerFile(toolcacheInfo.path, logger);
} else {
logger.debug("Caching CodeQL bundle.");
const toolcacheStart = performance.now();
codeqlFolder = await toolcache.cacheDir(
extractedBundlePath,
"CodeQL bundle from temporary directory",
logger,
"CodeQL",
toolcacheInfo.version,
);

logger.info(
`Added CodeQL bundle to the tool cache (${formatDuration(
performance.now() - toolcacheStart,
)}).`,
);

// Defensive check: we expect `cacheDir` to copy the bundle to a new location.
if (codeqlFolder !== extractedBundlePath) {
await cleanUpGlob(
extractedBundlePath,
"CodeQL bundle from temporary directory",
logger,
);
}
}

return {
codeqlFolder: toolcachedBundlePath,
codeqlFolder,
statusReport,
toolsVersion: maybeCliVersion ?? toolcacheInfo.version,
};
Expand Down
10 changes: 10 additions & 0 deletions src/tools-download.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as fs from "fs";
import { IncomingMessage, OutgoingHttpHeaders, RequestOptions } from "http";
import * as os from "os";
import * as path from "path";
Expand Down Expand Up @@ -217,6 +218,15 @@ export function getToolcacheDirectory(version: string): string {
);
}

export function writeToolcacheMarkerFile(
extractedPath: string,
logger: Logger,
): void {
const markerFilePath = `${extractedPath}.complete`;
fs.writeFileSync(markerFilePath, "");
logger.debug(`Wrote marker file to ${markerFilePath}`);
}

function sanitizeUrlForStatusReport(url: string): string {
return ["github/codeql-action", "dsp-testing/codeql-cli-nightlies"].some(
(repo) => url.startsWith(`https://github.com/${repo}/releases/download/`),
Expand Down

0 comments on commit 0b20485

Please sign in to comment.