Skip to content

Commit 9b5d335

Browse files
henrymercerCopilot
andcommitted
Warn when CODEQL_ACTION_CLEANUP_TRAP_CACHES is set
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 1a7b87e commit 9b5d335

4 files changed

Lines changed: 64 additions & 1 deletion

File tree

‎lib/entry-points.js‎

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/analyze-action.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ import {
4949
getActionsStatus,
5050
StatusReportBase,
5151
} from "./status-report";
52-
import { uploadTrapCaches } from "./trap-caching";
52+
import {
53+
uploadTrapCaches,
54+
warnIfTrapCacheCleanupEnvVarIsSet,
55+
} from "./trap-caching";
5356
import * as uploadLib from "./upload-lib";
5457
import { UploadResult } from "./upload-lib";
5558
import { postProcessAndUploadSarif } from "./upload-sarif";
@@ -270,6 +273,8 @@ async function run(action: ActionState<["Base", "Logger", "Env", "Actions"]>) {
270273
);
271274
}
272275

276+
warnIfTrapCacheCleanupEnvVarIsSet(action);
277+
273278
const apiDetails = getApiDetails();
274279
const outputDir = actionsUtil.getRequiredInput("output");
275280
action.env.export(EnvVar.SARIF_RESULTS_OUTPUT_DIR, outputDir);

‎src/trap-caching.test.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import * as configUtils from "./config-utils";
1515
import * as gitUtils from "./git-utils";
1616
import { BuiltInLanguage } from "./languages";
1717
import {
18+
callee,
1819
createTestConfig,
1920
getRecordingLogger,
2021
makeVersionInfo,
@@ -24,6 +25,7 @@ import {
2425
downloadTrapCaches,
2526
getLanguagesSupportingCaching,
2627
uploadTrapCaches,
28+
warnIfTrapCacheCleanupEnvVarIsSet,
2729
} from "./trap-caching";
2830
import * as util from "./util";
2931

@@ -194,3 +196,28 @@ test.serial(
194196
});
195197
},
196198
);
199+
200+
// `CODEQL_ACTION_CLEANUP_TRAP_CACHES` has no effect with either value, so we warn even when it's
201+
// set to `false`.
202+
for (const value of ["true", "false"]) {
203+
test(`warnIfTrapCacheCleanupEnvVarIsSet warns when CODEQL_ACTION_CLEANUP_TRAP_CACHES is '${value}'`, async (t) => {
204+
const target = callee(warnIfTrapCacheCleanupEnvVarIsSet)
205+
.withEnv((env) => env.set("CODEQL_ACTION_CLEANUP_TRAP_CACHES", value))
206+
.withArgs()
207+
.logs(
208+
t,
209+
"CODEQL_ACTION_CLEANUP_TRAP_CACHES environment variable no longer has any effect",
210+
);
211+
await target.passes(t.is, undefined);
212+
t.deepEqual(
213+
target.getLogger().messages.map((m) => m.type),
214+
["warning"],
215+
);
216+
});
217+
}
218+
219+
test("warnIfTrapCacheCleanupEnvVarIsSet doesn't warn when CODEQL_ACTION_CLEANUP_TRAP_CACHES is unset", async (t) => {
220+
const target = callee(warnIfTrapCacheCleanupEnvVarIsSet).withArgs();
221+
await target.passes(t.is, undefined);
222+
t.deepEqual(target.getLogger().messages, []);
223+
});

‎src/trap-caching.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as path from "path";
33

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

6+
import { type ActionState } from "./action-common";
67
import * as actionsUtil from "./actions-util";
78
import { type CodeQL } from "./codeql";
89
import { type Config } from "./config-utils";
@@ -169,6 +170,25 @@ export async function uploadTrapCaches(
169170
return true;
170171
}
171172

173+
/**
174+
* Warns if the `CODEQL_ACTION_CLEANUP_TRAP_CACHES` environment variable is set to a non-empty
175+
* value. That variable controlled the removed TRAP cache cleanup feature, so setting it has no
176+
* effect.
177+
*/
178+
export function warnIfTrapCacheCleanupEnvVarIsSet({
179+
env,
180+
logger,
181+
}: ActionState<["Logger", "ReadOnlyEnv"]>): void {
182+
if (env.getOptional("CODEQL_ACTION_CLEANUP_TRAP_CACHES") !== undefined) {
183+
logger.warning(
184+
"TRAP cache cleanup has been removed, so the CODEQL_ACTION_CLEANUP_TRAP_CACHES environment " +
185+
"variable no longer has any effect and can be removed from your workflow. If you used TRAP " +
186+
"cache cleanup to limit Actions cache usage, we recommend disabling TRAP caching instead by " +
187+
"passing the `trap-caching: false` input to the `init` Action.",
188+
);
189+
}
190+
}
191+
172192
export async function getLanguagesSupportingCaching(
173193
codeql: CodeQL,
174194
languages: Language[],

0 commit comments

Comments
 (0)