Skip to content

Commit 644a850

Browse files
electrumbrunoborgesCopilot
authored
Support exact Corretto release versions (#1310)
* Support exact Corretto release versions Corretto users cannot pin the release used by their local builds and production. Accept full release numbers so a workflow keeps using its chosen release after Amazon publishes a newer patch. * Fix Corretto release review findings Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Bruno Borges <brborges@microsoft.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent dade0c5 commit 644a850

8 files changed

Lines changed: 557 additions & 25 deletions

File tree

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

Lines changed: 268 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,19 +244,282 @@ describe('getAvailableVersions', () => {
244244
).rejects.toThrow('Early access versions are not supported');
245245
});
246246

247-
it('with non major version expect to throw not supported error', async () => {
248-
const version = '18.0.1';
247+
it.each(['18.0.1', '17.0.13.11', '17.0.13.11.1.1'])(
248+
'rejects partial or malformed release %s',
249+
async version => {
250+
const distribution = new CorrettoDistribution({
251+
version,
252+
architecture: 'x64',
253+
packageType: 'jdk',
254+
checkLatest: false
255+
});
256+
mockPlatform(distribution, 'linux');
257+
258+
await expect(
259+
distribution['findPackageForDownload'](version)
260+
).rejects.toThrow(
261+
'Specify a major version or a full Corretto release, such as 25.0.5.0.10'
262+
);
263+
}
264+
);
265+
266+
it.each([
267+
[
268+
'25.0.5.0.10',
269+
'linux',
270+
'x64',
271+
'jdk',
272+
'25.0.5+0.10',
273+
'https://corretto.aws/downloads/resources/25.0.5.0.10/amazon-corretto-25.0.5.0.10-linux-x64.tar.gz'
274+
],
275+
[
276+
'25.0.5+0.10',
277+
'macos',
278+
'arm64',
279+
'jdk',
280+
'25.0.5+0.10',
281+
'https://corretto.aws/downloads/resources/25.0.5.0.10/amazon-corretto-25.0.5.0.10-macosx-aarch64.tar.gz'
282+
],
283+
[
284+
'17.0.2.8.1',
285+
'windows',
286+
'x64',
287+
'jdk',
288+
'17.0.2+8.1',
289+
'https://corretto.aws/downloads/resources/17.0.2.8.1/amazon-corretto-17.0.2.8.1-windows-x64-jdk.zip'
290+
],
291+
[
292+
'25.0.5.0.10',
293+
'alpine',
294+
'aarch64',
295+
'jdk',
296+
'25.0.5+0.10',
297+
'https://corretto.aws/downloads/resources/25.0.5.0.10/amazon-corretto-25.0.5.0.10-alpine-linux-aarch64.tar.gz'
298+
],
299+
[
300+
'11.0.14.10.1',
301+
'linux',
302+
'armv7',
303+
'jdk',
304+
'11.0.14+10.1',
305+
'https://corretto.aws/downloads/resources/11.0.14.10.1/amazon-corretto-11.0.14.10.1-linux-armv7.tar.gz'
306+
],
307+
[
308+
'8.472.8+1',
309+
'linux',
310+
'x64',
311+
'jdk',
312+
'8.472.8+1',
313+
'https://corretto.aws/downloads/resources/8.472.08.1/amazon-corretto-8.472.08.1-linux-x64.tar.gz'
314+
],
315+
[
316+
'8.472.08.1',
317+
'linux',
318+
'x64',
319+
'jdk',
320+
'8.472.8+1',
321+
'https://corretto.aws/downloads/resources/8.472.08.1/amazon-corretto-8.472.08.1-linux-x64.tar.gz'
322+
],
323+
[
324+
'8.472.08.1',
325+
'windows',
326+
'x86',
327+
'jre',
328+
'8.472.8+1',
329+
'https://corretto.aws/downloads/resources/8.472.08.1/amazon-corretto-8.472.08.1-windows-x86-jre.zip'
330+
]
331+
])(
332+
'resolves exact release %s on %s/%s (%s)',
333+
async (
334+
requestedVersion,
335+
platform,
336+
architecture,
337+
packageType,
338+
expectedVersion,
339+
url
340+
) => {
341+
const checksum = 'a'.repeat(64);
342+
spyHttpClient.mockResolvedValue({
343+
statusCode: 200,
344+
headers: {},
345+
result: {
346+
body: `|JDK|[archive](${url})|\`md5\` /<br /> \`${checksum}\`|`
347+
}
348+
});
349+
const distribution = new CorrettoDistribution({
350+
version: requestedVersion,
351+
architecture,
352+
packageType,
353+
checkLatest: false
354+
});
355+
mockPlatform(distribution, platform);
356+
357+
const release = await distribution['findPackageForDownload'](
358+
distribution['version']
359+
);
360+
const rawVersion = new URL(url).pathname.split('/')[3];
361+
const source = `https://api.github.com/repos/corretto/corretto-${rawVersion.split('.')[0]}/releases/tags/${rawVersion}`;
362+
expect(release).toEqual({
363+
version: expectedVersion,
364+
url,
365+
checksum: {algorithm: 'sha256', value: checksum, source}
366+
});
367+
expect(spyHttpClient).toHaveBeenCalledTimes(1);
368+
expect(spyHttpClient).toHaveBeenCalledWith(
369+
source,
370+
expect.objectContaining({accept: 'application/vnd.github+json'})
371+
);
372+
}
373+
);
374+
375+
it('rejects exact releases without an archive for the requested platform', async () => {
376+
spyHttpClient.mockResolvedValueOnce({
377+
statusCode: 200,
378+
headers: {},
379+
result: {
380+
body:
381+
'|[other archive](https://example.com/archive)|`' +
382+
'a'.repeat(64) +
383+
'`|'
384+
}
385+
});
249386
const distribution = new CorrettoDistribution({
250-
version,
387+
version: '25.0.5.0.10',
251388
architecture: 'x64',
252389
packageType: 'jdk',
253390
checkLatest: false
254391
});
255392
mockPlatform(distribution, 'linux');
393+
await expect(
394+
distribution['findPackageForDownload'](distribution['version'])
395+
).rejects.toThrow(
396+
'No linux/x64 jdk archive is listed for Corretto 25.0.5.0.10'
397+
);
398+
});
256399

400+
it('rejects historical archives with only an MD5 checksum', async () => {
401+
spyHttpClient.mockResolvedValueOnce({
402+
statusCode: 200,
403+
headers: {},
404+
result: {
405+
body:
406+
'|[archive](https://corretto.aws/downloads/resources/17.0.1.12.1/amazon-corretto-17.0.1.12.1-linux-x64.tar.gz)|`' +
407+
'a'.repeat(32) +
408+
'`|'
409+
}
410+
});
411+
const distribution = new CorrettoDistribution({
412+
version: '17.0.1.12.1',
413+
architecture: 'x64',
414+
packageType: 'jdk',
415+
checkLatest: false
416+
});
417+
mockPlatform(distribution, 'linux');
257418
await expect(
258-
distribution['findPackageForDownload'](version)
259-
).rejects.toThrow('Only major versions are supported');
419+
distribution['findPackageForDownload'](distribution['version'])
420+
).rejects.toThrow(
421+
'No SHA-256 checksum is published for Corretto 17.0.1.12.1 (linux, x64, jdk)'
422+
);
423+
});
424+
425+
it('does not substitute a JDK for an exact Linux JRE request', async () => {
426+
const distribution = new CorrettoDistribution({
427+
version: '25.0.5.0.10',
428+
architecture: 'x64',
429+
packageType: 'jre',
430+
checkLatest: false
431+
});
432+
mockPlatform(distribution, 'linux');
433+
await expect(
434+
distribution['findPackageForDownload'](distribution['version'])
435+
).rejects.toThrow('Corretto JRE archives are only available for Windows');
436+
expect(spyHttpClient).not.toHaveBeenCalled();
437+
});
438+
439+
it('resolves catalog-only releases without a GitHub release', async () => {
440+
spyHttpClient.mockResolvedValueOnce({
441+
statusCode: 404,
442+
headers: {},
443+
result: null
444+
});
445+
const distribution = new CorrettoDistribution({
446+
version: '15.0.2.7.1',
447+
architecture: 'x64',
448+
packageType: 'jdk',
449+
checkLatest: false
450+
});
451+
mockPlatform(distribution, 'linux');
452+
expect(
453+
await distribution['findPackageForDownload'](distribution['version'])
454+
).toEqual({
455+
version: '15.0.2+7.1',
456+
url: 'https://corretto.aws/downloads/resources/15.0.2.7.1/amazon-corretto-15.0.2.7.1-linux-x64.tar.gz',
457+
checksum: {
458+
algorithm: 'sha256',
459+
value: manifestData.linux.x64.jdk['15']['tar.gz'].checksum_sha256,
460+
source:
461+
'https://corretto.github.io/corretto-downloads/latest_links/indexmap_with_checksum.json'
462+
}
463+
});
464+
});
465+
466+
it('falls back to the catalog when the GitHub lookup fails', async () => {
467+
spyHttpClient.mockRejectedValueOnce(new Error('GitHub rate limit'));
468+
const distribution = new CorrettoDistribution({
469+
version: '15.0.2.7.1',
470+
architecture: 'x64',
471+
packageType: 'jdk',
472+
checkLatest: false
473+
});
474+
mockPlatform(distribution, 'linux');
475+
476+
expect(
477+
await distribution['findPackageForDownload'](distribution['version'])
478+
).toEqual({
479+
version: '15.0.2+7.1',
480+
url: 'https://corretto.aws/downloads/resources/15.0.2.7.1/amazon-corretto-15.0.2.7.1-linux-x64.tar.gz',
481+
checksum: {
482+
algorithm: 'sha256',
483+
value: manifestData.linux.x64.jdk['15']['tar.gz'].checksum_sha256,
484+
source:
485+
'https://corretto.github.io/corretto-downloads/latest_links/indexmap_with_checksum.json'
486+
}
487+
});
488+
expect(spyHttpClient).toHaveBeenCalledTimes(2);
489+
});
490+
491+
it('reports missing release metadata without substituting the latest release', async () => {
492+
spyHttpClient.mockResolvedValueOnce({
493+
statusCode: 404,
494+
headers: {},
495+
result: null
496+
});
497+
const distribution = new CorrettoDistribution({
498+
version: '17.0.0.0.999',
499+
architecture: 'x64',
500+
packageType: 'jdk',
501+
checkLatest: false
502+
});
503+
mockPlatform(distribution, 'linux');
504+
await expect(
505+
distribution['findPackageForDownload'](distribution['version'])
506+
).rejects.toThrow(
507+
"Corretto release 17.0.0.0.999 was not found in Amazon's GitHub releases or current download catalog"
508+
);
509+
});
510+
511+
it('does not normalize zero-padded major-only inputs', () => {
512+
expect(
513+
() =>
514+
new CorrettoDistribution({
515+
version: '08',
516+
architecture: 'x64',
517+
packageType: 'jdk',
518+
checkLatest: false
519+
})
520+
).toThrow(
521+
"The string '08' is not valid SemVer notation for a Java version"
522+
);
260523
});
261524

262525
it('with unfound version throw could not find error', async () => {

‎__tests__/util.test.ts‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,28 @@ describe('validatePaginationUrl', () => {
278278
});
279279

280280
describe('getVersionFromFileContent', () => {
281+
it.each(['25.0.5.0.10', '8.472.08.1', '25.0.5+0.10'])(
282+
'preserves full Corretto release %s in .java-version',
283+
version => {
284+
expect(
285+
getVersionFromFileContent(version, 'corretto', '.java-version')
286+
).toEqual({version, distribution: undefined});
287+
}
288+
);
289+
290+
it.each([
291+
['17.0.3.1', '.java-version', '17'],
292+
['1.8.0.472.1', '.java-version', '8'],
293+
['8.0.472.08.1', '.java-version', '8'],
294+
['8.0.282+8', '.java-version', '8'],
295+
['java corretto-17.0.13.11.1-jre', '.tool-versions', '17'],
296+
['java corretto-17.0.13.11.1+1', '.tool-versions', '17']
297+
])('keeps the existing major selection for %s', (content, file, version) => {
298+
expect(getVersionFromFileContent(content, 'corretto', file)?.version).toBe(
299+
version
300+
);
301+
});
302+
281303
describe('.sdkmanrc', () => {
282304
it.each([
283305
['java=26-tem', '26', 'temurin'],
@@ -290,6 +312,8 @@ describe('getVersionFromFileContent', () => {
290312
['java=21.0.5-zulu', '21.0.5', 'zulu'],
291313
['java=17.0.13-albba', '17.0.13', 'dragonwell'],
292314
['java=17.0.13-amzn', '17', 'corretto'],
315+
['java=25.0.5.0.10-amzn', '25.0.5.0.10', 'corretto'],
316+
['java=8.472.08.1-amzn', '8.472.08.1', 'corretto'],
293317
['java=21.0.5-graal', '21.0.5', 'graalvm'],
294318
['java=17.0.9-graalce', '17.0.9', 'graalvm'],
295319
['java=11.0.25-librca', '11.0.25', 'liberica'],
@@ -368,7 +392,8 @@ describe('getVersionFromFileContent', () => {
368392
['java adoptopenjdk-11.0.16+8', '11.0.16+8', 'temurin'],
369393
['java adoptopenjdk-openj9-11.0.16+8', '11.0.16+8', 'temurin'],
370394
['java zulu-11.56.19', '11.56.19', 'zulu'],
371-
['java corretto-17.0.13.11.1', '17', 'corretto'], // corretto -> major only
395+
['java corretto-17.0.13.11.1', '17.0.13.11.1', 'corretto'],
396+
['java corretto-8.472.08.1', '8.472.08.1', 'corretto'],
372397
['java liberica-11.0.15+10', '11.0.15+10', 'liberica'],
373398
['java microsoft-11.0.13.8.1', '11.0.13', 'microsoft'],
374399
['java semeru-openj9-11.0.25+9', '11.0.25+9', 'semeru'],

‎dist/cleanup/index.js‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31220,7 +31220,7 @@ const DISTRIBUTIONS_ONLY_MAJOR_VERSION = (/* unused pure expression or super */
3122031220
/* harmony export */ Vt: () => (/* binding */ getBooleanInput),
3122131221
/* harmony export */ lN: () => (/* binding */ isJdkCacheEnabled)
3122231222
/* harmony export */ });
31223-
/* unused harmony exports getVersionFromToolcachePath, extractJdkFile, cacheJdkDir, getJavaVersionFromReleaseFile, getDownloadArchiveExtension, isVersionSatisfies, getToolcachePath, isGhes, getVersionFromFileContent, convertVersionToSemver, normalizeJavaVersionToSemver, getArtifactFingerprint, getGitHubToken, getGitHubHttpHeaders, MAX_PAGINATION_PAGES, getNextPageUrlFromLinkHeader, validatePaginationUrl, renameWinArchive, getLatestMajorVersion */
31223+
/* unused harmony exports getVersionFromToolcachePath, extractJdkFile, cacheJdkDir, getJavaVersionFromReleaseFile, getDownloadArchiveExtension, isVersionSatisfies, getToolcachePath, isGhes, getVersionFromFileContent, isExactCorrettoVersion, convertVersionToSemver, normalizeJavaVersionToSemver, getArtifactFingerprint, getGitHubToken, getGitHubHttpHeaders, MAX_PAGINATION_PAGES, getNextPageUrlFromLinkHeader, validatePaginationUrl, renameWinArchive, getLatestMajorVersion */
3122431224
/* harmony import */ var os__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(857);
3122531225
/* harmony import */ var os__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__nccwpck_require__.n(os__WEBPACK_IMPORTED_MODULE_0__);
3122631226
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_1__ = __nccwpck_require__(6928);
@@ -31527,6 +31527,15 @@ function getVersionFromFileContent(content, distributionName, versionFile) {
3152731527
}
3152831528
const tentativeVersion = avoidOldNotation(capturedVersion);
3152931529
const rawVersion = tentativeVersion.split('-')[0];
31530+
// Preserve Corretto's full vendor release before generic coercion drops its extra numeric fields.
31531+
if ((extractedDistribution || distributionName) === 'corretto' &&
31532+
capturedVersion === tentativeVersion &&
31533+
isExactCorrettoVersion(tentativeVersion)) {
31534+
return {
31535+
version: tentativeVersion,
31536+
distribution: extractedDistribution
31537+
};
31538+
}
3153031539
let version = semver.validRange(rawVersion)
3153131540
? tentativeVersion
3153231541
: semver.coerce(tentativeVersion);
@@ -31610,6 +31619,10 @@ function mapAsdfDistribution(asdfDist) {
3161031619
function avoidOldNotation(content) {
3161131620
return content.startsWith('1.') ? content.substring(2) : content;
3161231621
}
31622+
function isExactCorrettoVersion(version) {
31623+
// Java 8 releases have a nonzero update field; later releases use five numeric fields.
31624+
return /^(?:8\.(?!0+(?:\.|$))\d+(?:\.\d+){2}|(?!8\.)\d+(?:\.\d+){4})$/.test(version.replace('+', '.'));
31625+
}
3161331626
function convertVersionToSemver(version) {
3161431627
// Some distributions may use semver-like notation (12.10.2.1, 12.10.2.1.1)
3161531628
const versionArray = Array.isArray(version) ? version : version.split('.');

0 commit comments

Comments
 (0)