Ensure uniqueness of overlay-base database cache keys

This commit is contained in:
Kasper Svendsen
2025-10-24 10:48:01 +02:00
parent c4b73722ba
commit b4ce335286
3 changed files with 15 additions and 4 deletions

View File

@@ -271,10 +271,12 @@ test("overlay-base database cache keys remain stable", async (t) => {
sinon.stub(apiClient, "getAutomationID").resolves("test-automation-id/");
sinon.stub(gitUtils, "getCommitOid").resolves(commitOid);
sinon.stub(actionsUtil, "getWorkflowRunID").returns(12345);
sinon.stub(actionsUtil, "getWorkflowRunAttempt").returns(1);
const saveKey = await getCacheSaveKey(config, codeQlVersion, "checkout-path");
const expectedSaveKey =
"codeql-overlay-base-database-1-c5666c509a2d9895-javascript_python-2.23.0-abc123def456";
"codeql-overlay-base-database-1-c5666c509a2d9895-javascript_python-2.23.0-12345-1-abc123def456";
t.is(
saveKey,
expectedSaveKey,

View File

@@ -4,7 +4,12 @@ import * as path from "path";
import * as actionsCache from "@actions/cache";
import { getRequiredInput, getTemporaryDirectory } from "./actions-util";
import {
getRequiredInput,
getTemporaryDirectory,
getWorkflowRunAttempt,
getWorkflowRunID,
} from "./actions-util";
import { getAutomationID } from "./api-client";
import { type CodeQL } from "./codeql";
import { type Config } from "./config-utils";
@@ -453,12 +458,14 @@ export async function getCacheSaveKey(
codeQlVersion: string,
checkoutPath: string,
): Promise<string> {
const runId = getWorkflowRunID();
const attemptId = getWorkflowRunAttempt();
const sha = await getCommitOid(checkoutPath);
const restoreKeyPrefix = await getCacheRestoreKeyPrefix(
config,
codeQlVersion,
);
return `${restoreKeyPrefix}${sha}`;
return `${restoreKeyPrefix}${runId}-${attemptId}-${sha}`;
}
/**