diff --git a/__tests__/distributors/microsoft-installer.test.ts b/__tests__/distributors/microsoft-installer.test.ts index 96314b445..e5b6e738a 100644 --- a/__tests__/distributors/microsoft-installer.test.ts +++ b/__tests__/distributors/microsoft-installer.test.ts @@ -1,34 +1,4 @@ import { MicrosoftDistributions } from '../../src/distributions/microsoft/installer'; -import { ArchitectureOptions } from '../../src/distributions/microsoft/models'; - -describe('getArchitectureOptions', () => { - it.each([ - ['x64', { bitness: '64', arch: 'x86' }], - ['aarch64', { bitness: '64', arch: 'arm' }] - ] as [string, ArchitectureOptions][])('parse architecture %s -> %s', (input, expected) => { - const distributions = new MicrosoftDistributions({ - architecture: input, - checkLatest: false, - packageType: '', - version: '' - }); - - expect(distributions['getArchitectureOptions']()).toEqual(expected); - }); - - it.each(['armv6', 's390x'])('not support architecture %s', input => { - const distributions = new MicrosoftDistributions({ - architecture: input, - checkLatest: false, - packageType: '', - version: '' - }); - - expect(() => distributions['getArchitectureOptions']()).toThrow( - /Architecture '\w+' is not supported\. Supported architectures: .*/ - ); - }); -}); describe('findPackageForDownload', () => { let distribution: MicrosoftDistributions; @@ -46,34 +16,39 @@ describe('findPackageForDownload', () => { [ '17.x', '17.0.1', - 'https://aka.ms/download-jdk/microsoft-jdk-17.0.1.12.1-{{OS_TYPE}}-x64.tar.gz' + 'https://aka.ms/download-jdk/microsoft-jdk-17.0.1.12.1-{{OS_TYPE}}-x64.{{ARCHIVE_TYPE}}' ], [ '16.0.x', '16.0.2', - 'https://aka.ms/download-jdk/microsoft-jdk-16.0.2.7.1-{{OS_TYPE}}-x64.tar.gz' + 'https://aka.ms/download-jdk/microsoft-jdk-16.0.2.7.1-{{OS_TYPE}}-x64.{{ARCHIVE_TYPE}}' ], [ '11.0.13', '11.0.13', - 'https://aka.ms/download-jdk/microsoft-jdk-11.0.13.8.1-{{OS_TYPE}}-x64.tar.gz' + 'https://aka.ms/download-jdk/microsoft-jdk-11.0.13.8.1-{{OS_TYPE}}-x64.{{ARCHIVE_TYPE}}' ] ])('version is %s -> %s', async (input, expectedVersion, expectedUrl) => { const result = await distribution['findPackageForDownload'](input); expect(result.version).toBe(expectedVersion); var os: string; + var archive: string; switch (process.platform) { case 'darwin': os = 'macos'; + archive = 'tar.gz'; break; case 'win32': os = 'windows'; + archive = 'zip'; break; default: os = process.platform.toString(); + archive = 'tar.gz'; break; } - expect(result.url).toBe(expectedUrl.replace('{{OS_TYPE}}', os)); + const url = expectedUrl.replace('{{OS_TYPE}}', os).replace('{{ARCHIVE_TYPE}}', archive); + expect(result.url).toBe(url); }); it('should throw an error', async () => { @@ -92,13 +67,14 @@ describe('getPlatformOption', () => { }); it.each([ - ['linux', 'linux'], - ['darwin', 'macos'], - ['win32', 'windows'] - ])('os version %s -> %s', (input, expected) => { + ['linux', 'tar.gz', 'linux'], + ['darwin', 'tar.gz', 'macos'], + ['win32', 'zip', 'windows'] + ])('os version %s -> %s', (input, expectedArchive, expectedOs) => { const actual = distributions['getPlatformOption'](input as NodeJS.Platform); - expect(actual).toEqual(expected); + expect(actual.archive).toEqual(expectedArchive); + expect(actual.os).toEqual(expectedOs); }); it.each(['aix', 'android', 'freebsd', 'openbsd', 'netbsd', 'solaris', 'cygwin'])( diff --git a/dist/setup/index.js b/dist/setup/index.js index 8e1587e1b..14ebafe63 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -14281,9 +14281,13 @@ class MicrosoftDistributions extends base_installer_1.JavaBase { } findPackageForDownload(range) { return __awaiter(this, void 0, void 0, function* () { + if (this.architecture !== 'x64' && this.architecture != 'aarch64') { + throw new Error(`Unsupported architecture: ${this.architecture}`); + } const availableVersionsRaw = yield this.getAvailableVersions(); + const opts = this.getPlatformOption(); const availableVersions = availableVersionsRaw.map(item => ({ - url: `https://aka.ms/download-jdk/microsoft-jdk-${item.fullVersion}-${this.getPlatformOption()}-${this.architecture}.tar.gz`, + url: `https://aka.ms/download-jdk/microsoft-jdk-${item.fullVersion}-${opts.os}-${this.architecture}.${opts.archive}`, version: this.convertVersionToSemver(item) })); const satisfiedVersion = availableVersions @@ -14315,35 +14319,28 @@ class MicrosoftDistributions extends base_installer_1.JavaBase { minorVersion: 0, patchVersion: 2, fullVersion: '16.0.2.7.1' - }, - { + } + ]; + // M1 is only supported for Java 16 & 17 + if (process.platform !== 'darwin' || this.architecture !== 'aarch64') { + jdkVersions.push({ majorVersion: 11, minorVersion: 0, patchVersion: 13, fullVersion: '11.0.13.8.1' - } - ]; + }); + } return jdkVersions; }); } - getArchitectureOptions() { - switch (this.architecture) { - case 'x64': - return { bitness: '64', arch: 'x86' }; - case 'aarch64': - return { bitness: '64', arch: 'arm' }; - default: - throw new Error(`Architecture '${this.architecture}' is not supported. Supported architectures: ${supportedArchitecture}`); - } - } getPlatformOption(platform = process.platform) { switch (platform) { case 'darwin': - return 'macos'; + return { archive: 'tar.gz', os: 'macos' }; case 'win32': - return 'windows'; + return { archive: 'zip', os: 'windows' }; case 'linux': - return 'linux'; + return { archive: 'tar.gz', os: 'linux' }; default: throw new Error(`Platform '${platform}' is not supported. Supported platforms: ${supportedPlatform}`); } diff --git a/src/distributions/microsoft/installer.ts b/src/distributions/microsoft/installer.ts index 356dabd79..d91643bcd 100644 --- a/src/distributions/microsoft/installer.ts +++ b/src/distributions/microsoft/installer.ts @@ -3,7 +3,7 @@ import { JavaDownloadRelease, JavaInstallerOptions, JavaInstallerResults } from import semver from 'semver'; import { extractJdkFile, getDownloadArchiveExtension, isVersionSatisfies } from '../../util'; import * as core from '@actions/core'; -import { ArchitectureOptions, MicrosoftVersion, OsVersions } from './models'; +import { MicrosoftVersion, PlatformOptions } from './models'; import * as tc from '@actions/tool-cache'; import fs from 'fs'; import path from 'path'; @@ -41,12 +41,14 @@ export class MicrosoftDistributions extends JavaBase { } protected async findPackageForDownload(range: string): Promise { + if (this.architecture !== 'x64' && this.architecture != 'aarch64') { + throw new Error(`Unsupported architecture: ${this.architecture}`); + } const availableVersionsRaw = await this.getAvailableVersions(); + const opts = this.getPlatformOption(); const availableVersions = availableVersionsRaw.map(item => ({ - url: `https://aka.ms/download-jdk/microsoft-jdk-${ - item.fullVersion - }-${this.getPlatformOption()}-${this.architecture}.tar.gz`, + url: `https://aka.ms/download-jdk/microsoft-jdk-${item.fullVersion}-${opts.os}-${this.architecture}.${opts.archive}`, version: this.convertVersionToSemver(item) })); @@ -83,39 +85,30 @@ export class MicrosoftDistributions extends JavaBase { minorVersion: 0, patchVersion: 2, fullVersion: '16.0.2.7.1' - }, - { + } + ]; + + // M1 is only supported for Java 16 & 17 + if (process.platform !== 'darwin' || this.architecture !== 'aarch64') { + jdkVersions.push({ majorVersion: 11, minorVersion: 0, patchVersion: 13, fullVersion: '11.0.13.8.1' - } - ]; + }); + } return jdkVersions; } - private getArchitectureOptions(): ArchitectureOptions { - switch (this.architecture) { - case 'x64': - return { bitness: '64', arch: 'x86' }; - case 'aarch64': - return { bitness: '64', arch: 'arm' }; - default: - throw new Error( - `Architecture '${this.architecture}' is not supported. Supported architectures: ${supportedArchitecture}` - ); - } - } - - private getPlatformOption(platform: NodeJS.Platform = process.platform): OsVersions { + private getPlatformOption(platform: NodeJS.Platform = process.platform): PlatformOptions { switch (platform) { case 'darwin': - return 'macos'; + return { archive: 'tar.gz', os: 'macos' }; case 'win32': - return 'windows'; + return { archive: 'zip', os: 'windows' }; case 'linux': - return 'linux'; + return { archive: 'tar.gz', os: 'linux' }; default: throw new Error( `Platform '${platform}' is not supported. Supported platforms: ${supportedPlatform}` diff --git a/src/distributions/microsoft/models.ts b/src/distributions/microsoft/models.ts index df969a310..7ee3a2df9 100644 --- a/src/distributions/microsoft/models.ts +++ b/src/distributions/microsoft/models.ts @@ -1,11 +1,9 @@ -export type Bitness = '32' | '64'; -export type ArchType = 'arm' | 'ppc' | 'sparc' | 'x86'; +export type OsVersions = 'linux' | 'macos' | 'windows'; +export type ArchiveType = 'tar.gz' | 'zip'; -export type OsVersions = 'linux' | 'linux-musl' | 'macos' | 'solaris' | 'windows'; - -export interface ArchitectureOptions { - bitness: Bitness; - arch: ArchType; +export interface PlatformOptions { + archive: ArchiveType; + os: OsVersions; } export interface MicrosoftVersion {