mirror of
https://github.com/github/codeql-action.git
synced 2026-11-09 06:29:52 +00:00
Warn when CODEQL_ACTION_CLEANUP_TRAP_CACHES is set
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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, []);
|
||||
});
|
||||
|
||||
@@ -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[],
|
||||
|
||||
Reference in New Issue
Block a user