Skip to content

Commit 0f814be

Browse files
committed
Improve error handling for overlay-base cache key creation
1 parent cbcae45 commit 0f814be

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

lib/analyze-action.js

Lines changed: 11 additions & 4 deletions
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: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ test(
265265
);
266266

267267
test("overlay-base database cache keys remain stable", async (t) => {
268+
const logger = getRunnerLogger(true);
268269
const config = createTestConfig({ languages: ["python", "javascript"] });
269270
const codeQlVersion = "2.23.0";
270271
const commitOid = "abc123def456";
@@ -274,7 +275,12 @@ test("overlay-base database cache keys remain stable", async (t) => {
274275
sinon.stub(actionsUtil, "getWorkflowRunID").returns(12345);
275276
sinon.stub(actionsUtil, "getWorkflowRunAttempt").returns(1);
276277

277-
const saveKey = await getCacheSaveKey(config, codeQlVersion, "checkout-path");
278+
const saveKey = await getCacheSaveKey(
279+
config,
280+
codeQlVersion,
281+
"checkout-path",
282+
logger,
283+
);
278284
const expectedSaveKey =
279285
"codeql-overlay-base-database-1-c5666c509a2d9895-javascript_python-2.23.0-abc123def456-12345-1";
280286
t.is(

src/overlay-database-utils.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { type Config } from "./config-utils";
1616
import { getCommitOid, getFileOidsUnderPath } from "./git-utils";
1717
import { Logger, withGroupAsync } from "./logging";
1818
import {
19+
getErrorMessage,
1920
isInTestMode,
2021
tryGetFolderBytes,
2122
waitForResultWithTimeLimit,
@@ -276,6 +277,7 @@ export async function uploadOverlayBaseDatabaseToCache(
276277
config,
277278
codeQlVersion,
278279
checkoutPath,
280+
logger,
279281
);
280282
logger.info(
281283
`Uploading overlay-base database to Actions cache with key ${cacheSaveKey}`,
@@ -457,9 +459,18 @@ export async function getCacheSaveKey(
457459
config: Config,
458460
codeQlVersion: string,
459461
checkoutPath: string,
462+
logger: Logger,
460463
): Promise<string> {
461-
const runId = getWorkflowRunID();
462-
const attemptId = getWorkflowRunAttempt();
464+
let runId = 1;
465+
let attemptId = 1;
466+
try {
467+
runId = getWorkflowRunID();
468+
attemptId = getWorkflowRunAttempt();
469+
} catch (e) {
470+
logger.warning(
471+
`Failed to get workflow run ID or attempt ID. Reason: ${getErrorMessage(e)}`,
472+
);
473+
}
463474
const sha = await getCommitOid(checkoutPath);
464475
const restoreKeyPrefix = await getCacheRestoreKeyPrefix(
465476
config,

0 commit comments

Comments
 (0)