Skip to content

Commit b4ce335

Browse files
committed
Ensure uniqueness of overlay-base database cache keys
1 parent c4b7372 commit b4ce335

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-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
@@ -271,10 +271,12 @@ test("overlay-base database cache keys remain stable", async (t) => {
271271

272272
sinon.stub(apiClient, "getAutomationID").resolves("test-automation-id/");
273273
sinon.stub(gitUtils, "getCommitOid").resolves(commitOid);
274+
sinon.stub(actionsUtil, "getWorkflowRunID").returns(12345);
275+
sinon.stub(actionsUtil, "getWorkflowRunAttempt").returns(1);
274276

275277
const saveKey = await getCacheSaveKey(config, codeQlVersion, "checkout-path");
276278
const expectedSaveKey =
277-
"codeql-overlay-base-database-1-c5666c509a2d9895-javascript_python-2.23.0-abc123def456";
279+
"codeql-overlay-base-database-1-c5666c509a2d9895-javascript_python-2.23.0-12345-1-abc123def456";
278280
t.is(
279281
saveKey,
280282
expectedSaveKey,

src/overlay-database-utils.ts

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

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

7-
import { getRequiredInput, getTemporaryDirectory } from "./actions-util";
7+
import {
8+
getRequiredInput,
9+
getTemporaryDirectory,
10+
getWorkflowRunAttempt,
11+
getWorkflowRunID,
12+
} from "./actions-util";
813
import { getAutomationID } from "./api-client";
914
import { type CodeQL } from "./codeql";
1015
import { type Config } from "./config-utils";
@@ -453,12 +458,14 @@ export async function getCacheSaveKey(
453458
codeQlVersion: string,
454459
checkoutPath: string,
455460
): Promise<string> {
461+
const runId = getWorkflowRunID();
462+
const attemptId = getWorkflowRunAttempt();
456463
const sha = await getCommitOid(checkoutPath);
457464
const restoreKeyPrefix = await getCacheRestoreKeyPrefix(
458465
config,
459466
codeQlVersion,
460467
);
461-
return `${restoreKeyPrefix}${sha}`;
468+
return `${restoreKeyPrefix}${runId}-${attemptId}-${sha}`;
462469
}
463470

464471
/**

0 commit comments

Comments
 (0)