Fix JDK resolution cache platform identity (#1210) · actions/setup-java@d0e61fe · GitHub
Skip to content

Commit d0e61fe

Browse files
jduboisbrunoborgesCopilot
authored
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 <brborges@microsoft.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 74248bb0-72af-41d8-b85d-b0f5836e68db
1 parent fb58a66 commit d0e61fe

14 files changed

Lines changed: 149 additions & 38 deletions

‎__tests__/distributors/base-installer.test.ts‎

Lines changed: 4 additions & 0 deletions

‎__tests__/java-platform-contract.test.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import fs from 'fs';
22
import path from 'path';
33
import {
4+
getJavaPlatformIdentity,
5+
isAlpineLinux,
46
JAVA_PLATFORM_CAPABILITIES,
57
normalizeArchitecture,
68
validateJavaPlatform
@@ -28,6 +30,38 @@ describe('Java platform capabilities', () => {
2830
expect(normalizeArchitecture(input)).toBe(expected);
2931
});
3032

33+
it.each([
34+
['linux', false, 'linux-glibc'],
35+
['linux', true, 'linux-musl'],
36+
['darwin', false, 'macos'],
37+
['win32', false, 'windows'],
38+
// Exercises the normalizePlatform alias path and the `?? platform`
39+
// fallback for a platform that has no Java alias.
40+
['sunos', false, 'solaris'],
41+
['aix', false, 'aix']
42+
] as const)(
43+
'identifies %s with Alpine release %s as %s',
44+
(platform, alpineReleaseExists, expected) => {
45+
expect(getJavaPlatformIdentity(platform, alpineReleaseExists)).toBe(
46+
expected
47+
);
48+
}
49+
);
50+
51+
// The platform check has to short-circuit before the filesystem probe, so a
52+
// stray /etc/alpine-release can never make a non-Linux runner look like musl.
53+
it.each([
54+
['linux', true, true],
55+
['linux', false, false],
56+
['darwin', true, false],
57+
['win32', true, false]
58+
] as const)(
59+
'treats %s with Alpine release %s as Alpine: %s',
60+
(platform, alpineReleaseExists, expected) => {
61+
expect(isAlpineLinux(platform, alpineReleaseExists)).toBe(expected);
62+
}
63+
);
64+
3165
it('uses the normalized architecture for validation', () => {
3266
expect(validateJavaPlatform('microsoft', 'linux', 'arm64', '25')).toBe(
3367
'aarch64'

‎__tests__/jdk-resolution-cache.test.ts‎

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const {restoreJdkResolution, registerJdkResolution, saveJdkResolutionCaches} =
2525
const request = {
2626
distribution: 'Temurin-Hotspot',
2727
packageType: 'jdk',
28+
platform: 'linux-glibc',
2829
architecture: 'x64',
2930
versionSpec: '21',
3031
stable: true
@@ -102,10 +103,24 @@ describe('JDK resolution cache', () => {
102103
expect(paths[0]).not.toContain(bucket());
103104
expect(primaryKey).toBe(`${restoreKeys[0]}${bucket()}`);
104105
expect(restoreKeys[0]).toMatch(
105-
/^setup-java-jdkres-v1-Linux-x64-[0-9a-f]{64}-$/
106+
/^setup-java-jdkres-v2-Linux-x64-[0-9a-f]{64}-$/
106107
);
107108
});
108109

110+
it('separates glibc and musl Linux resolutions', async () => {
111+
createRunnerTemp();
112+
await restoreJdkResolution(request);
113+
const [glibcPaths, glibcKey] = jest.mocked(cache.restoreCache).mock
114+
.calls[0] as [string[], string];
115+
116+
await restoreJdkResolution({...request, platform: 'linux-musl'});
117+
const [muslPaths, muslKey] = jest.mocked(cache.restoreCache).mock
118+
.calls[1] as [string[], string];
119+
120+
expect(muslKey).not.toBe(glibcKey);
121+
expect(muslPaths).not.toEqual(glibcPaths);
122+
});
123+
109124
it('holds the key steady for a week and then rolls it', async () => {
110125
createRunnerTemp();
111126
const nowSpy = jest.spyOn(Date, 'now');
@@ -129,7 +144,7 @@ describe('JDK resolution cache', () => {
129144

130145
it('reports a hit on the current bucket as fresh', async () => {
131146
createRunnerTemp();
132-
const key = `setup-java-jdkres-v1-Linux-x64-${'0'.repeat(64)}-${bucket()}`;
147+
const key = `setup-java-jdkres-v2-Linux-x64-${'0'.repeat(64)}-${bucket()}`;
133148
restoreWith(JSON.stringify(release), key);
134149

135150
// The key the module computes is the one it passes to restoreCache, so
@@ -152,7 +167,7 @@ describe('JDK resolution cache', () => {
152167

153168
it('reports a hit on an older bucket as stale', async () => {
154169
createRunnerTemp();
155-
restoreWith(JSON.stringify(release), 'setup-java-jdkres-v1-old');
170+
restoreWith(JSON.stringify(release), 'setup-java-jdkres-v2-old');
156171

157172
const restored = await restoreJdkResolution(request);
158173
expect(restored?.fresh).toBe(false);
@@ -233,7 +248,7 @@ describe('JDK resolution cache', () => {
233248
]
234249
])('rejects an entry with %s', async (_name, contents) => {
235250
createRunnerTemp();
236-
restoreWith(contents, 'setup-java-jdkres-v1-old');
251+
restoreWith(contents, 'setup-java-jdkres-v2-old');
237252

238253
await expect(restoreJdkResolution(request)).resolves.toBeUndefined();
239254
});
@@ -251,7 +266,7 @@ describe('JDK resolution cache', () => {
251266
},
252267
floating: true
253268
};
254-
restoreWith(JSON.stringify(full), 'setup-java-jdkres-v1-old');
269+
restoreWith(JSON.stringify(full), 'setup-java-jdkres-v2-old');
255270

256271
const restored = await restoreJdkResolution(request);
257272
expect(restored?.release).toEqual(full);
@@ -261,7 +276,7 @@ describe('JDK resolution cache', () => {
261276
createRunnerTemp();
262277
restoreWith(
263278
JSON.stringify({...release, evil: 'payload'}),
264-
'setup-java-jdkres-v1-old'
279+
'setup-java-jdkres-v2-old'
265280
);
266281

267282
const restored = await restoreJdkResolution(request);
@@ -332,7 +347,7 @@ describe('JDK resolution cache', () => {
332347
const stateFor = (cachePath: string) =>
333348
JSON.stringify([
334349
{
335-
key: 'setup-java-jdkres-v1-key',
350+
key: 'setup-java-jdkres-v2-key',
336351
path: cachePath,
337352
release: JSON.stringify(release)
338353
}
@@ -350,7 +365,7 @@ describe('JDK resolution cache', () => {
350365
await saveJdkResolutionCaches();
351366
expect(cache.saveCache).toHaveBeenCalledWith(
352367
[root],
353-
'setup-java-jdkres-v1-key'
368+
'setup-java-jdkres-v2-key'
354369
);
355370
});
356371

‎dist/cleanup/348.index.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const modules = {
2323

2424

2525
const STATE_JDK_RESOLUTIONS = 'jdk-resolutions';
26-
const JDK_RESOLUTION_KEY_VERSION = 1;
26+
const JDK_RESOLUTION_KEY_VERSION = 2;
2727
const RESOLUTION_DIRECTORY = 'setup-java-jdk-resolution';
2828
const RESOLUTION_FILE_NAME = 'release.json';
2929
const pendingResolutions = (/* unused pure expression or super */ null && ([]));
@@ -146,6 +146,7 @@ function getResolutionIdentity(request) {
146146
runnerOs: getRunnerOs(),
147147
distribution: request.distribution.toLowerCase(),
148148
packageType: request.packageType.toLowerCase(),
149+
platform: request.platform.toLowerCase(),
149150
architecture: request.architecture.toLowerCase(),
150151
versionSpec: request.versionSpec,
151152
stable: request.stable,

‎dist/setup/242.index.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ class JavaBase {
441441
const request = {
442442
distribution: this.distribution,
443443
packageType: this.packageType,
444+
platform: (0,platform_types/* getJavaPlatformIdentity */.U)(),
444445
architecture: this.architecture,
445446
versionSpec: this.version,
446447
stable: this.stable
@@ -517,6 +518,7 @@ class JavaBase {
517518
return {
518519
distribution: this.distribution,
519520
packageType: this.packageType,
521+
platform: (0,platform_types/* getJavaPlatformIdentity */.U)(),
520522
architecture: this.architecture,
521523
versionSpec: this.version,
522524
stable: this.stable,

‎dist/setup/348.index.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const modules = {
2424

2525

2626
const STATE_JDK_RESOLUTIONS = 'jdk-resolutions';
27-
const JDK_RESOLUTION_KEY_VERSION = 1;
27+
const JDK_RESOLUTION_KEY_VERSION = 2;
2828
const RESOLUTION_DIRECTORY = 'setup-java-jdk-resolution';
2929
const RESOLUTION_FILE_NAME = 'release.json';
3030
const pendingResolutions = [];
@@ -147,6 +147,7 @@ function getResolutionIdentity(request) {
147147
runnerOs: getRunnerOs(),
148148
distribution: request.distribution.toLowerCase(),
149149
packageType: request.packageType.toLowerCase(),
150+
platform: request.platform.toLowerCase(),
150151
architecture: request.architecture.toLowerCase(),
151152
versionSpec: request.versionSpec,
152153
stable: request.stable,

‎dist/setup/463.index.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ var base_installer = __webpack_require__(6242);
6868
var constants = __webpack_require__(7242);
6969
// EXTERNAL MODULE: ./src/util.ts
7070
var util = __webpack_require__(4527);
71+
// EXTERNAL MODULE: ./src/distributions/platform-types.ts
72+
var platform_types = __webpack_require__(7444);
7173
;// CONCATENATED MODULE: ./src/distributions/temurin/installer.ts
7274

7375

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

8082

8183

84+
8285
var TemurinImplementation;
8386
(function (TemurinImplementation) {
8487
TemurinImplementation["Hotspot"] = "Hotspot";
@@ -246,7 +249,7 @@ class TemurinDistribution extends base_installer/* JavaBase */.O {
246249
case 'win32':
247250
return 'windows';
248251
case 'linux':
249-
if (external_fs_default().existsSync('/etc/alpine-release')) {
252+
if ((0,platform_types/* isAlpineLinux */.G6)()) {
250253
return 'alpine-linux';
251254
}
252255
return 'linux';

‎dist/setup/557.index.js‎

Lines changed: 3 additions & 1 deletion

0 commit comments

Comments
 (0)