From c4ba924625672d0f883e2e066fe7053871722ff7 Mon Sep 17 00:00:00 2001 From: Bruno Borges Date: Tue, 4 Aug 2026 19:44:02 -0400 Subject: [PATCH] Fix JDK cache CI validation Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- README.md | 2 ++ __tests__/distributors/base-installer.test.ts | 7 ++++++- dist/cleanup/314.index.js | 8 +++++--- dist/setup/242.index.js | 12 ++++++++++-- dist/setup/779.index.js | 8 +++++--- 5 files changed, 28 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index ffbd13df..ba0781e5 100644 --- a/README.md +++ b/README.md @@ -168,6 +168,8 @@ steps: | `mvn-toolchain-vendor` | Maven Toolchain vendor value. | `${distribution}` | | `show-download-progress` | Keep Maven artifact download and transfer progress in logs. When `false`, the action adds `-ntp` to `MAVEN_ARGS`. | `false` | +- `java-package`: Supported package types are `jdk`, `jre`, `jdk+fx`, `jre+fx`, `jdk+crac`, `jre+crac`, `jdk+jmods`, `jdk+jcef`, `jre+jcef`, `jdk+ft`, and `jre+ft`. Availability varies by distribution. + Deprecated aliases `jdkFile`, `server-username`, `server-password`, and `gpg-passphrase` remain accepted for compatibility, but should be replaced with the current input names. ## Outputs diff --git a/__tests__/distributors/base-installer.test.ts b/__tests__/distributors/base-installer.test.ts index 1e30d167..7a42136e 100644 --- a/__tests__/distributors/base-installer.test.ts +++ b/__tests__/distributors/base-installer.test.ts @@ -493,6 +493,11 @@ describe('setupJava', () => { }); it('restores the exact resolved JDK before downloading', async () => { + const toolCachePath = path.join('toolcache'); + jest.replaceProperty(process, 'env', { + ...process.env, + RUNNER_TOOL_CACHE: toolCachePath + }); mockJavaBase = new EmptyJavaBase({ version: '11', architecture: 'x86', @@ -517,7 +522,7 @@ describe('setupJava', () => { architecture: 'x86', version: actualJavaVersion, source: `some/random_url/java/${actualJavaVersion}`, - path: path.join('Java_Empty_jdk', actualJavaVersion) + path: path.join(toolCachePath, 'Java_Empty_jdk', actualJavaVersion) }); expect(downloadTool).not.toHaveBeenCalled(); expect(spyCoreInfo).not.toHaveBeenCalledWith('Trying to download...'); diff --git a/dist/cleanup/314.index.js b/dist/cleanup/314.index.js index b7725372..9ac584be 100644 --- a/dist/cleanup/314.index.js +++ b/dist/cleanup/314.index.js @@ -113,18 +113,20 @@ async function saveJdkCaches() { } } function buildJdkCacheKey(jdk) { + const runnerOs = process.env['RUNNER_OS'] ?? process.platform; + const normalizedArchitecture = jdk.architecture.toLowerCase(); const identity = JSON.stringify({ keyVersion: JDK_CACHE_KEY_VERSION, - runnerOs: process.env['RUNNER_OS'] ?? process.platform, + runnerOs, platform: process.platform, distribution: jdk.distribution.toLowerCase(), packageType: jdk.packageType.toLowerCase(), - architecture: jdk.architecture.toLowerCase(), + architecture: normalizedArchitecture, version: jdk.version, source: jdk.source }); const digest = createHash('sha256').update(identity).digest('hex'); - return `setup-java-jdk-v${JDK_CACHE_KEY_VERSION}-${process.env['RUNNER_OS'] ?? process.platform}-${jdk.architecture}-${digest}`; + return `setup-java-jdk-v${JDK_CACHE_KEY_VERSION}-${runnerOs}-${normalizedArchitecture}-${digest}`; } function parseJdkCacheState(state) { const value = JSON.parse(state); diff --git a/dist/setup/242.index.js b/dist/setup/242.index.js index 0a59bdb6..6845c473 100644 --- a/dist/setup/242.index.js +++ b/dist/setup/242.index.js @@ -460,10 +460,18 @@ class JavaBase { return version.replace('+', '-'); } getJdkCachePath(version) { - return external_path_default().join(process.env['RUNNER_TOOL_CACHE'] ?? '', this.toolcacheFolderName, this.getToolcacheVersionName(version)); + const toolCache = process.env['RUNNER_TOOL_CACHE']; + if (!toolCache) { + return ''; + } + return external_path_default().join(toolCache, this.toolcacheFolderName, this.getToolcacheVersionName(version)); } getRestoredJdkPath(version) { - const architecturePath = external_path_default().join(this.getJdkCachePath(version), this.architecture); + const basePath = this.getJdkCachePath(version); + if (!basePath) { + return null; + } + const architecturePath = external_path_default().join(basePath, this.architecture); return external_fs_.existsSync(architecturePath) && external_fs_.existsSync(`${architecturePath}.complete`) ? architecturePath diff --git a/dist/setup/779.index.js b/dist/setup/779.index.js index 86fa5a4b..376e43fd 100644 --- a/dist/setup/779.index.js +++ b/dist/setup/779.index.js @@ -117,18 +117,20 @@ async function saveJdkCaches() { } } function buildJdkCacheKey(jdk) { + const runnerOs = process.env['RUNNER_OS'] ?? process.platform; + const normalizedArchitecture = jdk.architecture.toLowerCase(); const identity = JSON.stringify({ keyVersion: JDK_CACHE_KEY_VERSION, - runnerOs: process.env['RUNNER_OS'] ?? process.platform, + runnerOs, platform: process.platform, distribution: jdk.distribution.toLowerCase(), packageType: jdk.packageType.toLowerCase(), - architecture: jdk.architecture.toLowerCase(), + architecture: normalizedArchitecture, version: jdk.version, source: jdk.source }); const digest = (0,crypto__WEBPACK_IMPORTED_MODULE_0__.createHash)('sha256').update(identity).digest('hex'); - return `setup-java-jdk-v${JDK_CACHE_KEY_VERSION}-${process.env['RUNNER_OS'] ?? process.platform}-${jdk.architecture}-${digest}`; + return `setup-java-jdk-v${JDK_CACHE_KEY_VERSION}-${runnerOs}-${normalizedArchitecture}-${digest}`; } function parseJdkCacheState(state) { const value = JSON.parse(state);