Skip to content

Commit 4dd50a2

Browse files
committed
Ensure uniqueness of overlay-base cache save keys
1 parent 2fbbe40 commit 4dd50a2

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

lib/analyze-action.js

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

src/overlay-database-utils.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,11 @@ test("overlay-base database cache keys remain stable", async (t) => {
270270
const commitOid = "abc123def456";
271271
sinon.stub(apiClient, "getAutomationID").resolves("test-automation-id/");
272272
sinon.stub(gitUtils, "getCommitOid").resolves(commitOid);
273+
sinon.stub(actionsUtil, "getWorkflowRunID").resolves("12345");
274+
sinon.stub(actionsUtil, "getWorkflowRunAttempt").resolves("1");
273275
const saveKey = await getCacheSaveKey(config, codeQlVersion, "checkout-path");
274276
const expectedSaveKey =
275-
"codeql-overlay-base-database-1-c5666c509a2d9895-javascript_python-2.23.0-abc123def456";
277+
"codeql-overlay-base-database-1-c5666c509a2d9895-javascript_python-2.23.0-12345-1-abc123def456";
276278
t.is(
277279
saveKey,
278280
expectedSaveKey,

src/overlay-database-utils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as path from "path";
44

55
import * as actionsCache from "@actions/cache";
66

7-
import { getRequiredInput, getTemporaryDirectory } from "./actions-util";
7+
import { getRequiredInput, getTemporaryDirectory, getWorkflowRunAttempt, getWorkflowRunID } from "./actions-util";
88
import { getAutomationID } from "./api-client";
99
import { type CodeQL } from "./codeql";
1010
import { type Config } from "./config-utils";
@@ -453,12 +453,14 @@ export async function getCacheSaveKey(
453453
codeQlVersion: string,
454454
checkoutPath: string,
455455
): Promise<string> {
456+
const runId = await getWorkflowRunID();
457+
const attemptId = await getWorkflowRunAttempt();
456458
const sha = await getCommitOid(checkoutPath);
457459
const restoreKeyPrefix = await getCacheRestoreKeyPrefix(
458460
config,
459461
codeQlVersion,
460462
);
461-
return `${restoreKeyPrefix}${sha}`;
463+
return `${restoreKeyPrefix}${runId}-${attemptId}-${sha}`;
462464
}
463465

464466
/**

0 commit comments

Comments
 (0)