From 9b5d335b995d625719d424b7041ad3331c3f4cf9 Mon Sep 17 00:00:00 2001 From: Henry Mercer Date: Thu, 15 Oct 2026 21:48:34 +0100 Subject: [PATCH] Warn when `CODEQL_ACTION_CLEANUP_TRAP_CACHES` is set Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- lib/entry-points.js | 11 +++++++++++ src/analyze-action.ts | 7 ++++++- src/trap-caching.test.ts | 27 +++++++++++++++++++++++++++ src/trap-caching.ts | 20 ++++++++++++++++++++ 4 files changed, 64 insertions(+), 1 deletion(-) diff --git a/lib/entry-points.js b/lib/entry-points.js index fb4ca4736..180ce0bff 100644 --- a/lib/entry-points.js +++ b/lib/entry-points.js @@ -174237,6 +174237,16 @@ async function uploadTrapCaches(codeql, config, logger2) { } return true; } +function warnIfTrapCacheCleanupEnvVarIsSet({ + env, + logger: logger2 +}) { + if (env.getOptional("CODEQL_ACTION_CLEANUP_TRAP_CACHES") !== void 0) { + logger2.warning( + "TRAP cache cleanup has been removed, so the CODEQL_ACTION_CLEANUP_TRAP_CACHES environment variable no longer has any effect and can be removed from your workflow. If you used TRAP cache cleanup to limit Actions cache usage, we recommend disabling TRAP caching instead by passing the `trap-caching: false` input to the `init` Action." + ); + } +} async function getLanguagesSupportingCaching(codeql, languages, logger2) { const result = []; const resolveResult = await codeql.resolveLanguages(); @@ -180697,6 +180707,7 @@ async function run(action) { "The 'cleanup-level' input is ignored since the CodeQL Action now automatically manages database cleanup. This input can safely be removed from your workflow." ); } + warnIfTrapCacheCleanupEnvVarIsSet(action); const apiDetails = getApiDetails(); const outputDir = getRequiredInput("output"); action.env.export("CODEQL_ACTION_SARIF_RESULTS_OUTPUT_DIR" /* SARIF_RESULTS_OUTPUT_DIR */, outputDir); diff --git a/src/analyze-action.ts b/src/analyze-action.ts index 5478d818e..f273dbbd8 100644 --- a/src/analyze-action.ts +++ b/src/analyze-action.ts @@ -49,7 +49,10 @@ import { getActionsStatus, StatusReportBase, } from "./status-report"; -import { uploadTrapCaches } from "./trap-caching"; +import { + uploadTrapCaches, + warnIfTrapCacheCleanupEnvVarIsSet, +} from "./trap-caching"; import * as uploadLib from "./upload-lib"; import { UploadResult } from "./upload-lib"; import { postProcessAndUploadSarif } from "./upload-sarif"; @@ -270,6 +273,8 @@ async function run(action: ActionState<["Base", "Logger", "Env", "Actions"]>) { ); } + warnIfTrapCacheCleanupEnvVarIsSet(action); + const apiDetails = getApiDetails(); const outputDir = actionsUtil.getRequiredInput("output"); action.env.export(EnvVar.SARIF_RESULTS_OUTPUT_DIR, outputDir); diff --git a/src/trap-caching.test.ts b/src/trap-caching.test.ts index 6ec3d5aba..99dc59706 100644 --- a/src/trap-caching.test.ts +++ b/src/trap-caching.test.ts @@ -15,6 +15,7 @@ import * as configUtils from "./config-utils"; import * as gitUtils from "./git-utils"; import { BuiltInLanguage } from "./languages"; import { + callee, createTestConfig, getRecordingLogger, makeVersionInfo, @@ -24,6 +25,7 @@ import { downloadTrapCaches, getLanguagesSupportingCaching, uploadTrapCaches, + warnIfTrapCacheCleanupEnvVarIsSet, } from "./trap-caching"; import * as util from "./util"; @@ -194,3 +196,28 @@ test.serial( }); }, ); + +// `CODEQL_ACTION_CLEANUP_TRAP_CACHES` has no effect with either value, so we warn even when it's +// set to `false`. +for (const value of ["true", "false"]) { + test(`warnIfTrapCacheCleanupEnvVarIsSet warns when CODEQL_ACTION_CLEANUP_TRAP_CACHES is '${value}'`, async (t) => { + const target = callee(warnIfTrapCacheCleanupEnvVarIsSet) + .withEnv((env) => env.set("CODEQL_ACTION_CLEANUP_TRAP_CACHES", value)) + .withArgs() + .logs( + t, + "CODEQL_ACTION_CLEANUP_TRAP_CACHES environment variable no longer has any effect", + ); + await target.passes(t.is, undefined); + t.deepEqual( + target.getLogger().messages.map((m) => m.type), + ["warning"], + ); + }); +} + +test("warnIfTrapCacheCleanupEnvVarIsSet doesn't warn when CODEQL_ACTION_CLEANUP_TRAP_CACHES is unset", async (t) => { + const target = callee(warnIfTrapCacheCleanupEnvVarIsSet).withArgs(); + await target.passes(t.is, undefined); + t.deepEqual(target.getLogger().messages, []); +}); diff --git a/src/trap-caching.ts b/src/trap-caching.ts index fd920600b..58d96890f 100644 --- a/src/trap-caching.ts +++ b/src/trap-caching.ts @@ -3,6 +3,7 @@ import * as path from "path"; import * as actionsCache from "@actions/cache"; +import { type ActionState } from "./action-common"; import * as actionsUtil from "./actions-util"; import { type CodeQL } from "./codeql"; import { type Config } from "./config-utils"; @@ -169,6 +170,25 @@ export async function uploadTrapCaches( return true; } +/** + * Warns if the `CODEQL_ACTION_CLEANUP_TRAP_CACHES` environment variable is set to a non-empty + * value. That variable controlled the removed TRAP cache cleanup feature, so setting it has no + * effect. + */ +export function warnIfTrapCacheCleanupEnvVarIsSet({ + env, + logger, +}: ActionState<["Logger", "ReadOnlyEnv"]>): void { + if (env.getOptional("CODEQL_ACTION_CLEANUP_TRAP_CACHES") !== undefined) { + logger.warning( + "TRAP cache cleanup has been removed, so the CODEQL_ACTION_CLEANUP_TRAP_CACHES environment " + + "variable no longer has any effect and can be removed from your workflow. If you used TRAP " + + "cache cleanup to limit Actions cache usage, we recommend disabling TRAP caching instead by " + + "passing the `trap-caching: false` input to the `init` Action.", + ); + } +} + export async function getLanguagesSupportingCaching( codeql: CodeQL, languages: Language[],