Skip to content
4 changes: 4 additions & 0 deletions __tests__/distributors/base-installer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -1290,6 +1292,7 @@ describe('setupJava', () => {
const expectedRequest = {
distribution: 'Empty',
packageType: 'jdk',
platform: getJavaPlatformIdentity(),
architecture: 'x86',
versionSpec: '11.0.9',
stable: true
Expand Down Expand Up @@ -1406,6 +1409,7 @@ describe('setupJava', () => {
{
distribution: 'Empty',
packageType: 'jdk',
platform: getJavaPlatformIdentity(),
architecture: 'x86',
versionSpec: '11.0.9',
stable: true,
Expand Down
34 changes: 34 additions & 0 deletions __tests__/java-platform-contract.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import fs from 'fs';
import path from 'path';
import {
getJavaPlatformIdentity,
isAlpineLinux,
JAVA_PLATFORM_CAPABILITIES,
normalizeArchitecture,
validateJavaPlatform
Expand Down Expand Up @@ -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'
Expand Down
31 changes: 23 additions & 8 deletions __tests__/jdk-resolution-cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const {restoreJdkResolution, registerJdkResolution, saveJdkResolutionCaches} =
const request = {
distribution: 'Temurin-Hotspot',
packageType: 'jdk',
platform: 'linux-glibc',
architecture: 'x64',
versionSpec: '21',
stable: true
Expand Down Expand Up @@ -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');
Expand All @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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();
});
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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)
}
Expand All @@ -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'
);
});

Expand Down
3 changes: 2 additions & 1 deletion dist/cleanup/348.index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 && ([]));
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions dist/setup/242.index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion dist/setup/348.index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion dist/setup/463.index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -79,6 +81,7 @@ var util = __webpack_require__(4527);




var TemurinImplementation;
(function (TemurinImplementation) {
TemurinImplementation["Hotspot"] = "Hotspot";
Expand Down Expand Up @@ -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';
Expand Down
4 changes: 3 additions & 1 deletion dist/setup/557.index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);




Expand Down Expand Up @@ -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';
Expand Down
Loading
Loading