mirror of
https://github.com/actions/setup-java.git
synced 2026-07-30 09:10:01 +08:00
Add dependency cache path overrides (#1175)
* Add dependency cache path overrides Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: dd650d36-9c97-4ca4-9ec8-39b37f99a07c * Clarify supported dependency cache managers Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: dd650d36-9c97-4ca4-9ec8-39b37f99a07c * Fix custom cache path CI checks Align the custom cache save and restore key inputs and use the workflow hash to avoid a previously populated cache entry. Rebuild the distribution bundles. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: dd650d36-9c97-4ca4-9ec8-39b37f99a07c --------- Copilot-Session: dd650d36-9c97-4ca4-9ec8-39b37f99a07c
This commit is contained in:
Vendored
+27
-6
@@ -97338,6 +97338,7 @@ const MAVEN_GPG_PASSPHRASE_DEFAULT_ENV = 'MAVEN_GPG_PASSPHRASE';
|
||||
const GPG_PASSPHRASE_PROFILE_ID = 'setup-java-gpg';
|
||||
const INPUT_CACHE = 'cache';
|
||||
const INPUT_CACHE_DEPENDENCY_PATH = 'cache-dependency-path';
|
||||
const INPUT_CACHE_PATH = 'cache-path';
|
||||
const INPUT_CACHE_READ_ONLY = 'cache-read-only';
|
||||
const INPUT_JOB_STATUS = 'job-status';
|
||||
const STATE_GPG_PRIVATE_KEY_FINGERPRINT = 'gpg-private-key-fingerprint';
|
||||
@@ -97771,6 +97772,7 @@ async function verifyPackageSignature(archivePath, signatureUrl, publicKeyConten
|
||||
|
||||
|
||||
const STATE_CACHE_PRIMARY_KEY = 'cache-primary-key';
|
||||
const STATE_CACHE_PATHS = 'cache-paths';
|
||||
const CACHE_MATCHED_KEY = 'cache-matched-key';
|
||||
const CACHE_KEY_PREFIX = 'setup-java';
|
||||
const supportedPackageManager = [
|
||||
@@ -97852,6 +97854,21 @@ function findPackageManager(id) {
|
||||
}
|
||||
return packageManager;
|
||||
}
|
||||
function resolveCachePaths(packageManager, cachePaths) {
|
||||
return cachePaths.length > 0 ? cachePaths : packageManager.path;
|
||||
}
|
||||
function getCachePathsFromState(packageManager) {
|
||||
const cachePathsState = getState(STATE_CACHE_PATHS);
|
||||
if (!cachePathsState) {
|
||||
return packageManager.path;
|
||||
}
|
||||
const cachePaths = JSON.parse(cachePathsState);
|
||||
if (!Array.isArray(cachePaths) ||
|
||||
!cachePaths.every(cachePath => typeof cachePath === 'string')) {
|
||||
throw new Error('Invalid cache paths retrieved from state.');
|
||||
}
|
||||
return cachePaths;
|
||||
}
|
||||
/**
|
||||
* State keys used to carry an additional cache's restore-time information over
|
||||
* to the post (save) action, scoped by the additional cache name.
|
||||
@@ -97894,30 +97911,33 @@ async function computeAdditionalCacheKey(additionalCache) {
|
||||
}
|
||||
/**
|
||||
* Restore the dependency cache
|
||||
* @param id ID of the package manager, should be "maven" or "gradle"
|
||||
* @param id ID of the package manager, should be "maven", "gradle", or "sbt"
|
||||
* @param cacheDependencyPath The path to a dependency file
|
||||
* @param cachePaths Paths to cache instead of the package manager defaults
|
||||
*/
|
||||
async function restore(id, cacheDependencyPath) {
|
||||
async function restore(id, cacheDependencyPath, cachePaths = []) {
|
||||
const packageManager = findPackageManager(id);
|
||||
const resolvedCachePaths = resolveCachePaths(packageManager, cachePaths);
|
||||
const [primaryKey, preparedAdditionalCaches] = await Promise.all([
|
||||
computeCacheKey(packageManager, cacheDependencyPath),
|
||||
prepareAdditionalCaches(packageManager.additionalCaches ?? [])
|
||||
]);
|
||||
core.debug(`primary key is ${primaryKey}`);
|
||||
core.saveState(STATE_CACHE_PRIMARY_KEY, primaryKey);
|
||||
core.saveState(STATE_CACHE_PATHS, JSON.stringify(resolvedCachePaths));
|
||||
core.setOutput(STATE_CACHE_PRIMARY_KEY, primaryKey);
|
||||
for (const preparedCache of preparedAdditionalCaches) {
|
||||
core.debug(`${preparedCache.cache.name} primary key is ${preparedCache.primaryKey}`);
|
||||
core.saveState(additionalCachePrimaryKeyState(preparedCache.cache.name), preparedCache.primaryKey);
|
||||
}
|
||||
await Promise.all([
|
||||
restorePrimaryCache(packageManager, primaryKey),
|
||||
restorePrimaryCache(packageManager, resolvedCachePaths, primaryKey),
|
||||
...preparedAdditionalCaches.map(preparedCache => restoreAdditionalCache(preparedCache))
|
||||
]);
|
||||
}
|
||||
async function restorePrimaryCache(packageManager, primaryKey) {
|
||||
async function restorePrimaryCache(packageManager, cachePaths, primaryKey) {
|
||||
// No "restoreKeys" is set, to start with a clear cache after dependency update (see https://github.com/actions/setup-java/issues/269)
|
||||
const matchedKey = await cache.restoreCache(packageManager.path, primaryKey);
|
||||
const matchedKey = await cache.restoreCache(cachePaths, primaryKey);
|
||||
if (matchedKey) {
|
||||
core.saveState(CACHE_MATCHED_KEY, matchedKey);
|
||||
core.setOutput('cache-hit', matchedKey === primaryKey);
|
||||
@@ -97963,6 +97983,7 @@ async function restoreAdditionalCache(preparedCache) {
|
||||
*/
|
||||
async function save(id) {
|
||||
const packageManager = findPackageManager(id);
|
||||
const cachePaths = getCachePathsFromState(packageManager);
|
||||
const matchedKey = getState(CACHE_MATCHED_KEY);
|
||||
// Inputs are re-evaluated before the post action, so we want the original key used for restore
|
||||
const primaryKey = getState(STATE_CACHE_PRIMARY_KEY);
|
||||
@@ -97985,7 +98006,7 @@ async function save(id) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const cacheId = await cache_saveCache(packageManager.path, primaryKey);
|
||||
const cacheId = await cache_saveCache(cachePaths, primaryKey);
|
||||
if (cacheId === -1) {
|
||||
// saveCache returns -1 without throwing when the cache was not saved,
|
||||
// e.g. a reserve collision or a read-only token (fork PR). @actions/cache
|
||||
|
||||
Vendored
+29
-7
@@ -72120,6 +72120,7 @@ const MAVEN_GPG_PASSPHRASE_DEFAULT_ENV = 'MAVEN_GPG_PASSPHRASE';
|
||||
const GPG_PASSPHRASE_PROFILE_ID = 'setup-java-gpg';
|
||||
const INPUT_CACHE = 'cache';
|
||||
const INPUT_CACHE_DEPENDENCY_PATH = 'cache-dependency-path';
|
||||
const INPUT_CACHE_PATH = 'cache-path';
|
||||
const INPUT_CACHE_READ_ONLY = 'cache-read-only';
|
||||
const constants_INPUT_JOB_STATUS = 'job-status';
|
||||
const STATE_GPG_PRIVATE_KEY_FINGERPRINT = 'gpg-private-key-fingerprint';
|
||||
@@ -129026,6 +129027,7 @@ async function writeToolchainsFileToDisk(directory, settings) {
|
||||
|
||||
|
||||
const STATE_CACHE_PRIMARY_KEY = 'cache-primary-key';
|
||||
const STATE_CACHE_PATHS = 'cache-paths';
|
||||
const CACHE_MATCHED_KEY = 'cache-matched-key';
|
||||
const CACHE_KEY_PREFIX = 'setup-java';
|
||||
const supportedPackageManager = [
|
||||
@@ -129107,6 +129109,21 @@ function findPackageManager(id) {
|
||||
}
|
||||
return packageManager;
|
||||
}
|
||||
function resolveCachePaths(packageManager, cachePaths) {
|
||||
return cachePaths.length > 0 ? cachePaths : packageManager.path;
|
||||
}
|
||||
function getCachePathsFromState(packageManager) {
|
||||
const cachePathsState = core.getState(STATE_CACHE_PATHS);
|
||||
if (!cachePathsState) {
|
||||
return packageManager.path;
|
||||
}
|
||||
const cachePaths = JSON.parse(cachePathsState);
|
||||
if (!Array.isArray(cachePaths) ||
|
||||
!cachePaths.every(cachePath => typeof cachePath === 'string')) {
|
||||
throw new Error('Invalid cache paths retrieved from state.');
|
||||
}
|
||||
return cachePaths;
|
||||
}
|
||||
/**
|
||||
* State keys used to carry an additional cache's restore-time information over
|
||||
* to the post (save) action, scoped by the additional cache name.
|
||||
@@ -129149,30 +129166,33 @@ async function computeAdditionalCacheKey(additionalCache) {
|
||||
}
|
||||
/**
|
||||
* Restore the dependency cache
|
||||
* @param id ID of the package manager, should be "maven" or "gradle"
|
||||
* @param id ID of the package manager, should be "maven", "gradle", or "sbt"
|
||||
* @param cacheDependencyPath The path to a dependency file
|
||||
* @param cachePaths Paths to cache instead of the package manager defaults
|
||||
*/
|
||||
async function restore(id, cacheDependencyPath) {
|
||||
async function restore(id, cacheDependencyPath, cachePaths = []) {
|
||||
const packageManager = findPackageManager(id);
|
||||
const resolvedCachePaths = resolveCachePaths(packageManager, cachePaths);
|
||||
const [primaryKey, preparedAdditionalCaches] = await Promise.all([
|
||||
computeCacheKey(packageManager, cacheDependencyPath),
|
||||
prepareAdditionalCaches(packageManager.additionalCaches ?? [])
|
||||
]);
|
||||
core_debug(`primary key is ${primaryKey}`);
|
||||
saveState(STATE_CACHE_PRIMARY_KEY, primaryKey);
|
||||
saveState(STATE_CACHE_PATHS, JSON.stringify(resolvedCachePaths));
|
||||
setOutput(STATE_CACHE_PRIMARY_KEY, primaryKey);
|
||||
for (const preparedCache of preparedAdditionalCaches) {
|
||||
core_debug(`${preparedCache.cache.name} primary key is ${preparedCache.primaryKey}`);
|
||||
saveState(additionalCachePrimaryKeyState(preparedCache.cache.name), preparedCache.primaryKey);
|
||||
}
|
||||
await Promise.all([
|
||||
restorePrimaryCache(packageManager, primaryKey),
|
||||
restorePrimaryCache(packageManager, resolvedCachePaths, primaryKey),
|
||||
...preparedAdditionalCaches.map(preparedCache => restoreAdditionalCache(preparedCache))
|
||||
]);
|
||||
}
|
||||
async function restorePrimaryCache(packageManager, primaryKey) {
|
||||
async function restorePrimaryCache(packageManager, cachePaths, primaryKey) {
|
||||
// No "restoreKeys" is set, to start with a clear cache after dependency update (see https://github.com/actions/setup-java/issues/269)
|
||||
const matchedKey = await restoreCache(packageManager.path, primaryKey);
|
||||
const matchedKey = await restoreCache(cachePaths, primaryKey);
|
||||
if (matchedKey) {
|
||||
saveState(CACHE_MATCHED_KEY, matchedKey);
|
||||
setOutput('cache-hit', matchedKey === primaryKey);
|
||||
@@ -129218,6 +129238,7 @@ async function restoreAdditionalCache(preparedCache) {
|
||||
*/
|
||||
async function save(id) {
|
||||
const packageManager = findPackageManager(id);
|
||||
const cachePaths = getCachePathsFromState(packageManager);
|
||||
const matchedKey = core.getState(CACHE_MATCHED_KEY);
|
||||
// Inputs are re-evaluated before the post action, so we want the original key used for restore
|
||||
const primaryKey = core.getState(STATE_CACHE_PRIMARY_KEY);
|
||||
@@ -129240,7 +129261,7 @@ async function save(id) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const cacheId = await cache.saveCache(packageManager.path, primaryKey);
|
||||
const cacheId = await cache.saveCache(cachePaths, primaryKey);
|
||||
if (cacheId === -1) {
|
||||
// saveCache returns -1 without throwing when the cache was not saved,
|
||||
// e.g. a reserve collision or a read-only token (fork PR). @actions/cache
|
||||
@@ -132608,6 +132629,7 @@ async function run() {
|
||||
const jdkFile = getJdkFileInput();
|
||||
const cache = getInput(INPUT_CACHE);
|
||||
const cacheDependencyPath = getInput(INPUT_CACHE_DEPENDENCY_PATH);
|
||||
const cachePath = getMultilineInput(INPUT_CACHE_PATH);
|
||||
const checkLatest = util_getBooleanInput(INPUT_CHECK_LATEST, false);
|
||||
const forceDownload = util_getBooleanInput(INPUT_FORCE_DOWNLOAD, false);
|
||||
const setDefault = util_getBooleanInput(INPUT_SET_DEFAULT, true);
|
||||
@@ -132676,7 +132698,7 @@ async function run() {
|
||||
await configureAuthentication();
|
||||
configureMavenArgs();
|
||||
if (cache && isCacheFeatureAvailable()) {
|
||||
await restore(cache, cacheDependencyPath);
|
||||
await restore(cache, cacheDependencyPath, cachePath);
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user