Add CachingKind enum to control whether to restore or store caches

This commit is contained in:
Michael B. Gale 2024-10-14 09:51:23 +01:00
parent 668531eca8
commit 79faaf1396
No known key found for this signature in database
GPG key ID: FF5E2765BD00628F
15 changed files with 195 additions and 57 deletions

View file

@ -13,9 +13,12 @@ import {
getRequiredInput,
getTemporaryDirectory,
persistInputs,
isDefaultSetup,
} from "./actions-util";
import { getGitHubVersion } from "./api-client";
import {
getDependencyCachingEnabled,
shouldRestoreCache,
} from "./caching-utils";
import { CodeQL } from "./codeql";
import * as configUtils from "./config-utils";
import { downloadDependencyCaches } from "./dependency-caching";
@ -560,7 +563,7 @@ async function run() {
}
// Restore dependency cache(s), if they exist.
if (config.dependencyCachingEnabled) {
if (shouldRestoreCache(config.dependencyCachingEnabled)) {
await downloadDependencyCaches(config.languages, logger);
}
@ -724,24 +727,6 @@ async function recordZstdAvailability(
);
}
/** Determines whether dependency caching is enabled. */
function getDependencyCachingEnabled(): boolean {
// If the workflow specified something always respect that
const dependencyCaching =
getOptionalInput("dependency-caching") ||
process.env[EnvVar.DEPENDENCY_CACHING];
if (dependencyCaching !== undefined) return dependencyCaching === "true";
// On self-hosted runners which may have dependencies installed centrally, disable caching by default
if (!isHostedRunner()) return false;
// Disable in advanced workflows by default.
if (!isDefaultSetup()) return false;
// On hosted runners, enable dependency caching by default
return true;
}
async function runWrapper() {
try {
await run();