mirror of
https://github.com/actions/setup-java.git
synced 2026-08-29 20:13:26 +01:00
Add conditional JDK caching (#1201)
* Add JDK caching Cache resolved JDK tool-cache entries by exact platform and release identity, with a default-on cache-jdk input and explicit opt-out. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Apply batched suggestions from code review Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Fix JDK cache CI validation Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Update brace-expansion security fix Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Refresh brace-expansion license metadata Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Refine JDK cache semantics Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Refine JDK cache documentation Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Simplify JDK cache identity Use one normalized runner OS dimension, reset the internal cache key schema for the unreleased feature, and align documentation, tests, and bundles. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Align JDK cache OS identity Use the established RUNNER_OS value directly and retain process.platform only as a non-Actions fallback. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Harden JDK cache saves and document tool-cache reuse Bind each JDK cache key to the installation identity it was computed for, keep post-job saves best-effort per entry, and state the real reuse and verification guarantee in the documentation. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * docs: restructure README caching section Rename '## Caching dependencies' to '## Caching' and add a what-gets-cached overview table covering the dependency, wrapper, and JDK caches. Lead with the common 'cache: maven' example and the dependency-cache material, and demote JDK caching into its own subsection. Also corrects the IMPORTANT callout, which implied JDK caching required an explicit opt-in; it is enabled implicitly whenever 'cache' is set. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * docs: fix caching documentation defects - Remove pull-request framing that compared behavior to `main`; state the tool-cache and `jdkfile` behavior directly and unconditionally. - Clarify that the JDK cache is a separate cache *entry* from the dependency and wrapper caches, while its *enablement* is coupled to `cache`, so the opening paragraph agrees with the enablement matrix. - Cite the actions/setup-java-benchmarks repository instead of an open PR and a self-referential PR comment, keeping the measured figures and caveats. - Keep the `cache`/`cache-jdk` matrix only in docs/advanced-usage.md and summarize the rules in prose in README.md to avoid divergence. - Describe the guarantee that a cache key is only saved with the installation it was computed for, instead of documenting inode/size/timestamp internals. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * docs: add V6 what's new entry for JDK caching Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: e2755464-4e83-47b6-ba71-731bb481b418 --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Copilot-Session: e2755464-4e83-47b6-ba71-731bb481b418
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
import * as core from '@actions/core';
|
||||
import * as gpg from './gpg.js';
|
||||
import * as constants from './constants.js';
|
||||
import {getBooleanInput, isJobStatusSuccess} from './util.js';
|
||||
import {
|
||||
getBooleanInput,
|
||||
isJdkCacheEnabled,
|
||||
isJobStatusSuccess
|
||||
} from './util.js';
|
||||
import {fileURLToPath} from 'url';
|
||||
|
||||
async function removePrivateKeyFromKeychain() {
|
||||
@@ -24,10 +28,11 @@ async function removePrivateKeyFromKeychain() {
|
||||
* Check given input and run a save process for the specified package manager
|
||||
* @returns Promise that will be resolved when the save process finishes
|
||||
*/
|
||||
async function saveCache() {
|
||||
async function saveCaches() {
|
||||
const jobStatus = isJobStatusSuccess();
|
||||
const cache = core.getInput(constants.INPUT_CACHE);
|
||||
if (!jobStatus || !cache) {
|
||||
const cacheJdk = isJdkCacheEnabled(cache);
|
||||
if (!jobStatus || (!cache && !cacheJdk)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -36,8 +41,16 @@ async function saveCache() {
|
||||
return;
|
||||
}
|
||||
|
||||
const {save} = await import('./cache.js');
|
||||
await save(cache);
|
||||
const saves: Promise<void>[] = [];
|
||||
if (cache) {
|
||||
const {save} = await import('./cache.js');
|
||||
saves.push(save(cache));
|
||||
}
|
||||
if (cacheJdk) {
|
||||
const {saveJdkCaches} = await import('./jdk-cache.js');
|
||||
saves.push(saveJdkCaches());
|
||||
}
|
||||
await Promise.all(saves);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,7 +72,7 @@ async function ignoreError(promise: Promise<void>) {
|
||||
|
||||
export async function run() {
|
||||
await removePrivateKeyFromKeychain();
|
||||
await ignoreError(saveCache());
|
||||
await ignoreError(saveCaches());
|
||||
}
|
||||
|
||||
if (process.argv[1] === fileURLToPath(import.meta.url)) {
|
||||
|
||||
Reference in New Issue
Block a user