From d0e61fe743b21ca96393d2eda4fadc698479ec67 Mon Sep 17 00:00:00 2001 From: Julien Dubois Date: Wed, 5 Aug 2026 18:45:11 +0200 Subject: [PATCH] Fix JDK resolution cache platform identity (#1210) * Fix JDK resolution cache platform identity Include the effective Linux libc platform in JDK resolution cache keys so Alpine/musl and glibc runners cannot restore each other's release metadata. Bump the cache namespace and share Alpine detection with affected distributors.\n\nCo-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>\nCopilot-Session: 4f95577c-567c-47a8-92f2-b4dced527866 * Update generated action bundles Regenerate setup and cleanup distributions for the platform-aware JDK resolution cache.\n\nCo-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>\nCopilot-Session: 4f95577c-567c-47a8-92f2-b4dced527866 * Cover the platform-identity fallback and Alpine short-circuit getJavaPlatformIdentity's `?? platform` fallback and the alias path for platforms other than linux/darwin/win32 had no coverage, and isAlpineLinux had no direct test at all. Verified by mutation: replacing the fallback with a constant, and dropping the `platform === 'linux'` short-circuit from isAlpineLinux, both left the existing suite fully green. The added cases fail on each. The short-circuit case matters beyond coverage bookkeeping: it is what keeps the /etc/alpine-release probe from running on non-Linux runners, so a stray file can never make Windows or macOS resolve as musl. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 74248bb0-72af-41d8-b85d-b0f5836e68db * Carry the platform identity into the floating resolution request Merging main brought in #1219, which added getFloatingResolutionRequest as a second construction site for JdkResolutionRequest. It predates the required `platform` field, so the merged tree did not compile. The floating request already carries `source`, which pins the artifact bytes, so this changes no lookup behaviour on its own -- it keeps the two request builders consistent and the tree building. Also refreshes dist/, which the textual merge left stale. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 74248bb0-72af-41d8-b85d-b0f5836e68db --------- Co-authored-by: Bruno Borges Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 74248bb0-72af-41d8-b85d-b0f5836e68db --- __tests__/distributors/base-installer.test.ts | 4 ++ __tests__/java-platform-contract.test.ts | 34 +++++++++++ __tests__/jdk-resolution-cache.test.ts | 31 +++++++--- dist/cleanup/348.index.js | 3 +- dist/setup/242.index.js | 2 + dist/setup/348.index.js | 3 +- dist/setup/463.index.js | 5 +- dist/setup/557.index.js | 4 +- dist/setup/index.js | 61 ++++++++++++------- src/distributions/base-installer.ts | 7 ++- src/distributions/platform-types.ts | 23 +++++++ src/distributions/sapmachine/installer.ts | 3 +- src/distributions/temurin/installer.ts | 3 +- src/jdk-resolution-cache.ts | 4 +- 14 files changed, 149 insertions(+), 38 deletions(-) diff --git a/__tests__/distributors/base-installer.test.ts b/__tests__/distributors/base-installer.test.ts index 3e2f0a2e..825d792a 100644 --- a/__tests__/distributors/base-installer.test.ts +++ b/__tests__/distributors/base-installer.test.ts @@ -101,6 +101,8 @@ const tc = await import('@actions/tool-cache'); const util = await import('../../src/util.js'); const jdkCache = await import('../../src/jdk-cache.js'); const jdkResolutionCache = await import('../../src/jdk-resolution-cache.js'); +const {getJavaPlatformIdentity} = + await import('../../src/distributions/platform-types.js'); const {JavaBase} = await import('../../src/distributions/base-installer.js'); class EmptyJavaBase extends JavaBase { @@ -1290,6 +1292,7 @@ describe('setupJava', () => { const expectedRequest = { distribution: 'Empty', packageType: 'jdk', + platform: getJavaPlatformIdentity(), architecture: 'x86', versionSpec: '11.0.9', stable: true @@ -1406,6 +1409,7 @@ describe('setupJava', () => { { distribution: 'Empty', packageType: 'jdk', + platform: getJavaPlatformIdentity(), architecture: 'x86', versionSpec: '11.0.9', stable: true, diff --git a/__tests__/java-platform-contract.test.ts b/__tests__/java-platform-contract.test.ts index 6eeaa2b2..187a54a4 100644 --- a/__tests__/java-platform-contract.test.ts +++ b/__tests__/java-platform-contract.test.ts @@ -1,6 +1,8 @@ import fs from 'fs'; import path from 'path'; import { + getJavaPlatformIdentity, + isAlpineLinux, JAVA_PLATFORM_CAPABILITIES, normalizeArchitecture, validateJavaPlatform @@ -28,6 +30,38 @@ describe('Java platform capabilities', () => { expect(normalizeArchitecture(input)).toBe(expected); }); + it.each([ + ['linux', false, 'linux-glibc'], + ['linux', true, 'linux-musl'], + ['darwin', false, 'macos'], + ['win32', false, 'windows'], + // Exercises the normalizePlatform alias path and the `?? platform` + // fallback for a platform that has no Java alias. + ['sunos', false, 'solaris'], + ['aix', false, 'aix'] + ] as const)( + 'identifies %s with Alpine release %s as %s', + (platform, alpineReleaseExists, expected) => { + expect(getJavaPlatformIdentity(platform, alpineReleaseExists)).toBe( + expected + ); + } + ); + + // The platform check has to short-circuit before the filesystem probe, so a + // stray /etc/alpine-release can never make a non-Linux runner look like musl. + it.each([ + ['linux', true, true], + ['linux', false, false], + ['darwin', true, false], + ['win32', true, false] + ] as const)( + 'treats %s with Alpine release %s as Alpine: %s', + (platform, alpineReleaseExists, expected) => { + expect(isAlpineLinux(platform, alpineReleaseExists)).toBe(expected); + } + ); + it('uses the normalized architecture for validation', () => { expect(validateJavaPlatform('microsoft', 'linux', 'arm64', '25')).toBe( 'aarch64' diff --git a/__tests__/jdk-resolution-cache.test.ts b/__tests__/jdk-resolution-cache.test.ts index f3e8af9b..9c6703fc 100644 --- a/__tests__/jdk-resolution-cache.test.ts +++ b/__tests__/jdk-resolution-cache.test.ts @@ -25,6 +25,7 @@ const {restoreJdkResolution, registerJdkResolution, saveJdkResolutionCaches} = const request = { distribution: 'Temurin-Hotspot', packageType: 'jdk', + platform: 'linux-glibc', architecture: 'x64', versionSpec: '21', stable: true @@ -102,10 +103,24 @@ describe('JDK resolution cache', () => { expect(paths[0]).not.toContain(bucket()); expect(primaryKey).toBe(`${restoreKeys[0]}${bucket()}`); expect(restoreKeys[0]).toMatch( - /^setup-java-jdkres-v1-Linux-x64-[0-9a-f]{64}-$/ + /^setup-java-jdkres-v2-Linux-x64-[0-9a-f]{64}-$/ ); }); + it('separates glibc and musl Linux resolutions', async () => { + createRunnerTemp(); + await restoreJdkResolution(request); + const [glibcPaths, glibcKey] = jest.mocked(cache.restoreCache).mock + .calls[0] as [string[], string]; + + await restoreJdkResolution({...request, platform: 'linux-musl'}); + const [muslPaths, muslKey] = jest.mocked(cache.restoreCache).mock + .calls[1] as [string[], string]; + + expect(muslKey).not.toBe(glibcKey); + expect(muslPaths).not.toEqual(glibcPaths); + }); + it('holds the key steady for a week and then rolls it', async () => { createRunnerTemp(); const nowSpy = jest.spyOn(Date, 'now'); @@ -129,7 +144,7 @@ describe('JDK resolution cache', () => { it('reports a hit on the current bucket as fresh', async () => { createRunnerTemp(); - const key = `setup-java-jdkres-v1-Linux-x64-${'0'.repeat(64)}-${bucket()}`; + const key = `setup-java-jdkres-v2-Linux-x64-${'0'.repeat(64)}-${bucket()}`; restoreWith(JSON.stringify(release), key); // The key the module computes is the one it passes to restoreCache, so @@ -152,7 +167,7 @@ describe('JDK resolution cache', () => { it('reports a hit on an older bucket as stale', async () => { createRunnerTemp(); - restoreWith(JSON.stringify(release), 'setup-java-jdkres-v1-old'); + restoreWith(JSON.stringify(release), 'setup-java-jdkres-v2-old'); const restored = await restoreJdkResolution(request); expect(restored?.fresh).toBe(false); @@ -233,7 +248,7 @@ describe('JDK resolution cache', () => { ] ])('rejects an entry with %s', async (_name, contents) => { createRunnerTemp(); - restoreWith(contents, 'setup-java-jdkres-v1-old'); + restoreWith(contents, 'setup-java-jdkres-v2-old'); await expect(restoreJdkResolution(request)).resolves.toBeUndefined(); }); @@ -251,7 +266,7 @@ describe('JDK resolution cache', () => { }, floating: true }; - restoreWith(JSON.stringify(full), 'setup-java-jdkres-v1-old'); + restoreWith(JSON.stringify(full), 'setup-java-jdkres-v2-old'); const restored = await restoreJdkResolution(request); expect(restored?.release).toEqual(full); @@ -261,7 +276,7 @@ describe('JDK resolution cache', () => { createRunnerTemp(); restoreWith( JSON.stringify({...release, evil: 'payload'}), - 'setup-java-jdkres-v1-old' + 'setup-java-jdkres-v2-old' ); const restored = await restoreJdkResolution(request); @@ -332,7 +347,7 @@ describe('JDK resolution cache', () => { const stateFor = (cachePath: string) => JSON.stringify([ { - key: 'setup-java-jdkres-v1-key', + key: 'setup-java-jdkres-v2-key', path: cachePath, release: JSON.stringify(release) } @@ -350,7 +365,7 @@ describe('JDK resolution cache', () => { await saveJdkResolutionCaches(); expect(cache.saveCache).toHaveBeenCalledWith( [root], - 'setup-java-jdkres-v1-key' + 'setup-java-jdkres-v2-key' ); }); diff --git a/dist/cleanup/348.index.js b/dist/cleanup/348.index.js index 67801456..d178a94b 100644 --- a/dist/cleanup/348.index.js +++ b/dist/cleanup/348.index.js @@ -23,7 +23,7 @@ export const modules = { const STATE_JDK_RESOLUTIONS = 'jdk-resolutions'; -const JDK_RESOLUTION_KEY_VERSION = 1; +const JDK_RESOLUTION_KEY_VERSION = 2; const RESOLUTION_DIRECTORY = 'setup-java-jdk-resolution'; const RESOLUTION_FILE_NAME = 'release.json'; const pendingResolutions = (/* unused pure expression or super */ null && ([])); @@ -146,6 +146,7 @@ function getResolutionIdentity(request) { runnerOs: getRunnerOs(), distribution: request.distribution.toLowerCase(), packageType: request.packageType.toLowerCase(), + platform: request.platform.toLowerCase(), architecture: request.architecture.toLowerCase(), versionSpec: request.versionSpec, stable: request.stable, diff --git a/dist/setup/242.index.js b/dist/setup/242.index.js index 2be41731..f16b5903 100644 --- a/dist/setup/242.index.js +++ b/dist/setup/242.index.js @@ -441,6 +441,7 @@ class JavaBase { const request = { distribution: this.distribution, packageType: this.packageType, + platform: (0,platform_types/* getJavaPlatformIdentity */.U)(), architecture: this.architecture, versionSpec: this.version, stable: this.stable @@ -517,6 +518,7 @@ class JavaBase { return { distribution: this.distribution, packageType: this.packageType, + platform: (0,platform_types/* getJavaPlatformIdentity */.U)(), architecture: this.architecture, versionSpec: this.version, stable: this.stable, diff --git a/dist/setup/348.index.js b/dist/setup/348.index.js index c92c4de7..cc1b3fe5 100644 --- a/dist/setup/348.index.js +++ b/dist/setup/348.index.js @@ -24,7 +24,7 @@ export const modules = { const STATE_JDK_RESOLUTIONS = 'jdk-resolutions'; -const JDK_RESOLUTION_KEY_VERSION = 1; +const JDK_RESOLUTION_KEY_VERSION = 2; const RESOLUTION_DIRECTORY = 'setup-java-jdk-resolution'; const RESOLUTION_FILE_NAME = 'release.json'; const pendingResolutions = []; @@ -147,6 +147,7 @@ function getResolutionIdentity(request) { runnerOs: getRunnerOs(), distribution: request.distribution.toLowerCase(), packageType: request.packageType.toLowerCase(), + platform: request.platform.toLowerCase(), architecture: request.architecture.toLowerCase(), versionSpec: request.versionSpec, stable: request.stable, diff --git a/dist/setup/463.index.js b/dist/setup/463.index.js index c0578ee6..7d792fd4 100644 --- a/dist/setup/463.index.js +++ b/dist/setup/463.index.js @@ -68,6 +68,8 @@ var base_installer = __webpack_require__(6242); var constants = __webpack_require__(7242); // EXTERNAL MODULE: ./src/util.ts var util = __webpack_require__(4527); +// EXTERNAL MODULE: ./src/distributions/platform-types.ts +var platform_types = __webpack_require__(7444); ;// CONCATENATED MODULE: ./src/distributions/temurin/installer.ts @@ -79,6 +81,7 @@ var util = __webpack_require__(4527); + var TemurinImplementation; (function (TemurinImplementation) { TemurinImplementation["Hotspot"] = "Hotspot"; @@ -246,7 +249,7 @@ class TemurinDistribution extends base_installer/* JavaBase */.O { case 'win32': return 'windows'; case 'linux': - if (external_fs_default().existsSync('/etc/alpine-release')) { + if ((0,platform_types/* isAlpineLinux */.G6)()) { return 'alpine-linux'; } return 'linux'; diff --git a/dist/setup/557.index.js b/dist/setup/557.index.js index 1e8e610a..e2df254c 100644 --- a/dist/setup/557.index.js +++ b/dist/setup/557.index.js @@ -17,6 +17,8 @@ export const modules = { /* harmony import */ var path__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_3__); /* harmony import */ var _util_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(4527); /* harmony import */ var _base_installer_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(6242); +/* harmony import */ var _platform_types_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(7444); + @@ -163,7 +165,7 @@ class SapMachineDistribution extends _base_installer_js__WEBPACK_IMPORTED_MODULE return 'macos'; case 'linux': // figure out if alpine/musl - if (fs__WEBPACK_IMPORTED_MODULE_2___default().existsSync('/etc/alpine-release')) { + if ((0,_platform_types_js__WEBPACK_IMPORTED_MODULE_6__/* .isAlpineLinux */ .G6)()) { return 'linux-musl'; } return 'linux'; diff --git a/dist/setup/index.js b/dist/setup/index.js index 992717c7..76992792 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -30988,33 +30988,38 @@ function createUnsupportedPackageError(distributionName, packageType, supportedP /***/ ((__unused_webpack_module, __webpack_exports__, __nccwpck_require__) => { /* harmony export */ __nccwpck_require__.d(__webpack_exports__, { +/* harmony export */ G6: () => (/* binding */ isAlpineLinux), +/* harmony export */ U: () => (/* binding */ getJavaPlatformIdentity), /* harmony export */ dV: () => (/* binding */ normalizeArchitecture), /* harmony export */ sZ: () => (/* binding */ validateJavaPlatform) /* harmony export */ }); /* unused harmony exports JAVA_PLATFORM_CAPABILITIES, normalizePlatform */ -/* harmony import */ var semver__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(2088); -/* harmony import */ var semver__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__nccwpck_require__.n(semver__WEBPACK_IMPORTED_MODULE_0__); -/* harmony import */ var _package_types_js__WEBPACK_IMPORTED_MODULE_1__ = __nccwpck_require__(7835); +/* harmony import */ var fs__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(9896); +/* harmony import */ var fs__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__nccwpck_require__.n(fs__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var semver__WEBPACK_IMPORTED_MODULE_1__ = __nccwpck_require__(2088); +/* harmony import */ var semver__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__nccwpck_require__.n(semver__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _package_types_js__WEBPACK_IMPORTED_MODULE_2__ = __nccwpck_require__(7835); + const X64_ARM64 = ['x64', 'aarch64']; const STANDARD_LINUX = ['x64', 'x86', 'aarch64', 'ppc64le', 's390x']; const JAVA_PLATFORM_CAPABILITIES = { - [_package_types_js__WEBPACK_IMPORTED_MODULE_1__/* .JavaDistribution */ .zS.Temurin]: { + [_package_types_js__WEBPACK_IMPORTED_MODULE_2__/* .JavaDistribution */ .zS.Temurin]: { platforms: { linux: [...STANDARD_LINUX, { architecture: 'armv7', versionRange: '<18' }], macos: X64_ARM64, windows: ['x64', 'x86', 'aarch64'] } }, - [_package_types_js__WEBPACK_IMPORTED_MODULE_1__/* .JavaDistribution */ .zS.Zulu]: { + [_package_types_js__WEBPACK_IMPORTED_MODULE_2__/* .JavaDistribution */ .zS.Zulu]: { platforms: { linux: ['x64', 'x86', 'armv7', 'aarch64'], macos: X64_ARM64, windows: ['x64', 'x86', 'aarch64'] } }, - [_package_types_js__WEBPACK_IMPORTED_MODULE_1__/* .JavaDistribution */ .zS.Liberica]: { + [_package_types_js__WEBPACK_IMPORTED_MODULE_2__/* .JavaDistribution */ .zS.Liberica]: { platforms: { linux: ['x64', 'x86', 'armv7', 'aarch64', 'ppc64le'], macos: X64_ARM64, @@ -31022,31 +31027,31 @@ const JAVA_PLATFORM_CAPABILITIES = { solaris: ['x64'] } }, - [_package_types_js__WEBPACK_IMPORTED_MODULE_1__/* .JavaDistribution */ .zS.LibericaNik]: { + [_package_types_js__WEBPACK_IMPORTED_MODULE_2__/* .JavaDistribution */ .zS.LibericaNik]: { platforms: { linux: X64_ARM64, macos: X64_ARM64, windows: X64_ARM64 } }, - [_package_types_js__WEBPACK_IMPORTED_MODULE_1__/* .JavaDistribution */ .zS.JdkFile]: { + [_package_types_js__WEBPACK_IMPORTED_MODULE_2__/* .JavaDistribution */ .zS.JdkFile]: { unrestricted: true }, - [_package_types_js__WEBPACK_IMPORTED_MODULE_1__/* .JavaDistribution */ .zS.Microsoft]: { + [_package_types_js__WEBPACK_IMPORTED_MODULE_2__/* .JavaDistribution */ .zS.Microsoft]: { platforms: { linux: X64_ARM64, macos: X64_ARM64, windows: X64_ARM64 } }, - [_package_types_js__WEBPACK_IMPORTED_MODULE_1__/* .JavaDistribution */ .zS.Semeru]: { + [_package_types_js__WEBPACK_IMPORTED_MODULE_2__/* .JavaDistribution */ .zS.Semeru]: { platforms: { linux: ['x64', 'x86', 'ppc64le', 'ppc64', 's390x', 'aarch64'], macos: X64_ARM64, windows: ['x64', 'aarch64'] } }, - [_package_types_js__WEBPACK_IMPORTED_MODULE_1__/* .JavaDistribution */ .zS.Corretto]: { + [_package_types_js__WEBPACK_IMPORTED_MODULE_2__/* .JavaDistribution */ .zS.Corretto]: { platforms: { linux: [ 'x64', @@ -31058,55 +31063,55 @@ const JAVA_PLATFORM_CAPABILITIES = { windows: ['x64', { architecture: 'x86', versionRange: '<12' }] } }, - [_package_types_js__WEBPACK_IMPORTED_MODULE_1__/* .JavaDistribution */ .zS.Oracle]: { + [_package_types_js__WEBPACK_IMPORTED_MODULE_2__/* .JavaDistribution */ .zS.Oracle]: { platforms: { linux: X64_ARM64, macos: X64_ARM64, windows: ['x64'] } }, - [_package_types_js__WEBPACK_IMPORTED_MODULE_1__/* .JavaDistribution */ .zS.Dragonwell]: { + [_package_types_js__WEBPACK_IMPORTED_MODULE_2__/* .JavaDistribution */ .zS.Dragonwell]: { platforms: { linux: X64_ARM64, windows: ['x64'] } }, - [_package_types_js__WEBPACK_IMPORTED_MODULE_1__/* .JavaDistribution */ .zS.SapMachine]: { + [_package_types_js__WEBPACK_IMPORTED_MODULE_2__/* .JavaDistribution */ .zS.SapMachine]: { platforms: { linux: ['x64', 'aarch64', 'ppc64le'], macos: X64_ARM64, windows: X64_ARM64 } }, - [_package_types_js__WEBPACK_IMPORTED_MODULE_1__/* .JavaDistribution */ .zS.GraalVM]: { + [_package_types_js__WEBPACK_IMPORTED_MODULE_2__/* .JavaDistribution */ .zS.GraalVM]: { platforms: { linux: X64_ARM64, macos: X64_ARM64, windows: ['x64'] } }, - [_package_types_js__WEBPACK_IMPORTED_MODULE_1__/* .JavaDistribution */ .zS.GraalVMCommunity]: { + [_package_types_js__WEBPACK_IMPORTED_MODULE_2__/* .JavaDistribution */ .zS.GraalVMCommunity]: { platforms: { linux: X64_ARM64, macos: X64_ARM64, windows: ['x64'] } }, - [_package_types_js__WEBPACK_IMPORTED_MODULE_1__/* .JavaDistribution */ .zS.JetBrains]: { + [_package_types_js__WEBPACK_IMPORTED_MODULE_2__/* .JavaDistribution */ .zS.JetBrains]: { platforms: { linux: X64_ARM64, macos: X64_ARM64, windows: X64_ARM64 } }, - [_package_types_js__WEBPACK_IMPORTED_MODULE_1__/* .JavaDistribution */ .zS.Kona]: { + [_package_types_js__WEBPACK_IMPORTED_MODULE_2__/* .JavaDistribution */ .zS.Kona]: { platforms: { linux: X64_ARM64, macos: X64_ARM64, windows: ['x64'] } }, - [_package_types_js__WEBPACK_IMPORTED_MODULE_1__/* .JavaDistribution */ .zS.OracleOpenJdk]: { + [_package_types_js__WEBPACK_IMPORTED_MODULE_2__/* .JavaDistribution */ .zS.OracleOpenJdk]: { platforms: { linux: X64_ARM64, macos: X64_ARM64, @@ -31146,6 +31151,18 @@ function normalizeArchitecture(architecture) { function normalizePlatform(platform) { return PLATFORM_ALIASES[platform]; } +function isAlpineLinux(platform = process.platform, alpineReleaseExists) { + return (platform === 'linux' && + (alpineReleaseExists ?? fs__WEBPACK_IMPORTED_MODULE_0___default().existsSync('/etc/alpine-release'))); +} +function getJavaPlatformIdentity(platform = process.platform, alpineReleaseExists) { + if (platform === 'linux') { + return isAlpineLinux(platform, alpineReleaseExists) + ? 'linux-musl' + : 'linux-glibc'; + } + return normalizePlatform(platform) ?? platform; +} function validateJavaPlatform(distributionName, platform, architecture, version) { const normalizedArchitecture = normalizeArchitecture(architecture); if (!isJavaDistribution(distributionName)) { @@ -31181,8 +31198,8 @@ function isVersionCompatible(version, supportedRange) { if (/^\d+(\.\d+){3,}$/.test(normalizedVersion)) { normalizedVersion = normalizeExtendedVersionToSemver(normalizedVersion); } - const requestedRange = semver__WEBPACK_IMPORTED_MODULE_0___default().validRange(normalizedVersion.replace(/-ea$/, '')); - const capabilityRange = semver__WEBPACK_IMPORTED_MODULE_0___default().validRange(supportedRange); + const requestedRange = semver__WEBPACK_IMPORTED_MODULE_1___default().validRange(normalizedVersion.replace(/-ea$/, '')); + const capabilityRange = semver__WEBPACK_IMPORTED_MODULE_1___default().validRange(supportedRange); if (!requestedRange || !capabilityRange) { return true; } @@ -31194,7 +31211,7 @@ function isVersionCompatible(version, supportedRange) { } return version; } - return semver__WEBPACK_IMPORTED_MODULE_0___default().intersects(requestedRange, capabilityRange, { + return semver__WEBPACK_IMPORTED_MODULE_1___default().intersects(requestedRange, capabilityRange, { includePrerelease: true }); } diff --git a/src/distributions/base-installer.ts b/src/distributions/base-installer.ts index 18fd5318..7add83f3 100644 --- a/src/distributions/base-installer.ts +++ b/src/distributions/base-installer.ts @@ -20,7 +20,10 @@ import {MACOS_JAVA_CONTENT_POSTFIX} from '../constants.js'; import {RetryingHttpClient} from '../retrying-http-client.js'; import os from 'os'; import {expectedDigestLength, verifyChecksum} from '../checksum.js'; -import {normalizeArchitecture} from './platform-types.js'; +import { + getJavaPlatformIdentity, + normalizeArchitecture +} from './platform-types.js'; import type {JdkCache} from '../jdk-cache.js'; export abstract class JavaBase { @@ -313,6 +316,7 @@ export abstract class JavaBase { const request = { distribution: this.distribution, packageType: this.packageType, + platform: getJavaPlatformIdentity(), architecture: this.architecture, versionSpec: this.version, stable: this.stable @@ -428,6 +432,7 @@ export abstract class JavaBase { return { distribution: this.distribution, packageType: this.packageType, + platform: getJavaPlatformIdentity(), architecture: this.architecture, versionSpec: this.version, stable: this.stable, diff --git a/src/distributions/platform-types.ts b/src/distributions/platform-types.ts index 5e579a7e..9806d53c 100644 --- a/src/distributions/platform-types.ts +++ b/src/distributions/platform-types.ts @@ -1,3 +1,4 @@ +import fs from 'fs'; import semver from 'semver'; import {JavaDistribution} from './package-types.js'; @@ -191,6 +192,28 @@ export function normalizePlatform( return PLATFORM_ALIASES[platform]; } +export function isAlpineLinux( + platform: NodeJS.Platform = process.platform, + alpineReleaseExists?: boolean +): boolean { + return ( + platform === 'linux' && + (alpineReleaseExists ?? fs.existsSync('/etc/alpine-release')) + ); +} + +export function getJavaPlatformIdentity( + platform: NodeJS.Platform = process.platform, + alpineReleaseExists?: boolean +): string { + if (platform === 'linux') { + return isAlpineLinux(platform, alpineReleaseExists) + ? 'linux-musl' + : 'linux-glibc'; + } + return normalizePlatform(platform) ?? platform; +} + export function validateJavaPlatform( distributionName: string, platform: NodeJS.Platform, diff --git a/src/distributions/sapmachine/installer.ts b/src/distributions/sapmachine/installer.ts index c4e45345..19b24a95 100644 --- a/src/distributions/sapmachine/installer.ts +++ b/src/distributions/sapmachine/installer.ts @@ -17,6 +17,7 @@ import { JavaInstallerOptions, JavaInstallerResults } from '../base-models.js'; +import {isAlpineLinux} from '../platform-types.js'; import {ISapMachineAllVersions, ISapMachineVersions} from './models.js'; export class SapMachineDistribution extends JavaBase { @@ -242,7 +243,7 @@ export class SapMachineDistribution extends JavaBase { return 'macos'; case 'linux': // figure out if alpine/musl - if (fs.existsSync('/etc/alpine-release')) { + if (isAlpineLinux()) { return 'linux-musl'; } return 'linux'; diff --git a/src/distributions/temurin/installer.ts b/src/distributions/temurin/installer.ts index 833b92cf..ab7238e3 100644 --- a/src/distributions/temurin/installer.ts +++ b/src/distributions/temurin/installer.ts @@ -24,6 +24,7 @@ import { MAX_PAGINATION_PAGES, validatePaginationUrl } from '../../util.js'; +import {isAlpineLinux} from '../platform-types.js'; export {ADOPTIUM_PUBLIC_KEY} from './adoptium-key.js'; @@ -274,7 +275,7 @@ export class TemurinDistribution extends JavaBase { case 'win32': return 'windows'; case 'linux': - if (fs.existsSync('/etc/alpine-release')) { + if (isAlpineLinux()) { return 'alpine-linux'; } return 'linux'; diff --git a/src/jdk-resolution-cache.ts b/src/jdk-resolution-cache.ts index b23b0122..86c80934 100644 --- a/src/jdk-resolution-cache.ts +++ b/src/jdk-resolution-cache.ts @@ -9,7 +9,7 @@ import { } from './distributions/base-models.js'; const STATE_JDK_RESOLUTIONS = 'jdk-resolutions'; -const JDK_RESOLUTION_KEY_VERSION = 1; +const JDK_RESOLUTION_KEY_VERSION = 2; const RESOLUTION_DIRECTORY = 'setup-java-jdk-resolution'; const RESOLUTION_FILE_NAME = 'release.json'; @@ -22,6 +22,7 @@ const RESOLUTION_FILE_NAME = 'release.json'; export interface JdkResolutionRequest { distribution: string; packageType: string; + platform: string; architecture: string; versionSpec: string; stable: boolean; @@ -214,6 +215,7 @@ function getResolutionIdentity(request: JdkResolutionRequest): string { runnerOs: getRunnerOs(), distribution: request.distribution.toLowerCase(), packageType: request.packageType.toLowerCase(), + platform: request.platform.toLowerCase(), architecture: request.architecture.toLowerCase(), versionSpec: request.versionSpec, stable: request.stable,