From 73887824bb07a384ee5011b84146449cef335287 Mon Sep 17 00:00:00 2001 From: Wes Morgan Date: Mon, 29 Aug 2022 10:37:16 -0600 Subject: [PATCH 01/21] Default architecture param to os.arch() --- src/setup-java.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/setup-java.ts b/src/setup-java.ts index 8274be938..6ec8efa57 100644 --- a/src/setup-java.ts +++ b/src/setup-java.ts @@ -6,12 +6,13 @@ import { restore } from './cache'; import * as path from 'path'; import { getJavaDistribution } from './distributions/distribution-factory'; import { JavaInstallerOptions } from './distributions/base-models'; +import * as os from 'os'; async function run() { try { const version = core.getInput(constants.INPUT_JAVA_VERSION, { required: true }); const distributionName = core.getInput(constants.INPUT_DISTRIBUTION, { required: true }); - const architecture = core.getInput(constants.INPUT_ARCHITECTURE); + const architecture = core.getInput(constants.INPUT_ARCHITECTURE) || os.arch(); const packageType = core.getInput(constants.INPUT_JAVA_PACKAGE); const jdkFile = core.getInput(constants.INPUT_JDK_FILE); const cache = core.getInput(constants.INPUT_CACHE); From b09076439442fb2d4561096fc5fef61be951f2fc Mon Sep 17 00:00:00 2001 From: Wes Morgan Date: Mon, 29 Aug 2022 10:37:31 -0600 Subject: [PATCH 02/21] Map temurin arch names to node os.arch() names --- src/distributions/temurin/installer.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/distributions/temurin/installer.ts b/src/distributions/temurin/installer.ts index db3e3209c..c4bab90df 100644 --- a/src/distributions/temurin/installer.ts +++ b/src/distributions/temurin/installer.ts @@ -20,6 +20,7 @@ export class TemurinDistribution extends JavaBase { private readonly jvmImpl: TemurinImplementation ) { super(`Temurin-${jvmImpl}`, installerOptions); + installerOptions.architecture = this.osArchToDistributionArch(installerOptions.architecture); } protected async findPackageForDownload(version: string): Promise { @@ -152,4 +153,15 @@ export class TemurinDistribution extends JavaBase { return process.platform; } } + + private osArchToDistributionArch(osArch: string): string { + let dArch; + switch (osArch) { + case 'amd64': dArch = 'x64'; break; + case 'ia32': dArch = 'x32'; break; + case 'arm64': dArch = 'aarch64'; break; + default: dArch = osArch; + } + return dArch; + } } From 7e83eb111a90bf252a863163b10d88a5f6eb182a Mon Sep 17 00:00:00 2001 From: Wes Morgan Date: Tue, 30 Aug 2022 09:06:12 -0600 Subject: [PATCH 03/21] Simplify osArchToDistributionArch switch statement --- src/distributions/temurin/installer.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/distributions/temurin/installer.ts b/src/distributions/temurin/installer.ts index c4bab90df..49a2364bb 100644 --- a/src/distributions/temurin/installer.ts +++ b/src/distributions/temurin/installer.ts @@ -155,13 +155,11 @@ export class TemurinDistribution extends JavaBase { } private osArchToDistributionArch(osArch: string): string { - let dArch; switch (osArch) { - case 'amd64': dArch = 'x64'; break; - case 'ia32': dArch = 'x32'; break; - case 'arm64': dArch = 'aarch64'; break; - default: dArch = osArch; + case 'amd64': return 'x64'; + case 'ia32': return 'x32'; + case 'arm64': return 'aarch64'; + default: return osArch; } - return dArch; } } From 148d9af0a66cbf3f2923711153a7d9f37d1f83c6 Mon Sep 17 00:00:00 2001 From: Wes Morgan Date: Tue, 30 Aug 2022 09:34:26 -0600 Subject: [PATCH 04/21] Format my code w/ prettier --- src/distributions/temurin/installer.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/distributions/temurin/installer.ts b/src/distributions/temurin/installer.ts index 49a2364bb..ad61faee5 100644 --- a/src/distributions/temurin/installer.ts +++ b/src/distributions/temurin/installer.ts @@ -156,10 +156,14 @@ export class TemurinDistribution extends JavaBase { private osArchToDistributionArch(osArch: string): string { switch (osArch) { - case 'amd64': return 'x64'; - case 'ia32': return 'x32'; - case 'arm64': return 'aarch64'; - default: return osArch; + case 'amd64': + return 'x64'; + case 'ia32': + return 'x32'; + case 'arm64': + return 'aarch64'; + default: + return osArch; } } } From a115f58891349a8e7c43695c98bad059d262ea8d Mon Sep 17 00:00:00 2001 From: Wes Morgan Date: Wed, 31 Aug 2022 07:12:42 -0600 Subject: [PATCH 05/21] Commit build artifact --- dist/setup/index.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 92cf879e6..26a58b8b8 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -102555,6 +102555,7 @@ class TemurinDistribution extends base_installer_1.JavaBase { constructor(installerOptions, jvmImpl) { super(`Temurin-${jvmImpl}`, installerOptions); this.jvmImpl = jvmImpl; + installerOptions.architecture = this.osArchToDistributionArch(installerOptions.architecture); } findPackageForDownload(version) { return __awaiter(this, void 0, void 0, function* () { @@ -102666,6 +102667,18 @@ class TemurinDistribution extends base_installer_1.JavaBase { return process.platform; } } + osArchToDistributionArch(osArch) { + switch (osArch) { + case 'amd64': + return 'x64'; + case 'ia32': + return 'x32'; + case 'arm64': + return 'aarch64'; + default: + return osArch; + } + } } exports.TemurinDistribution = TemurinDistribution; @@ -102965,12 +102978,13 @@ const constants = __importStar(__nccwpck_require__(9042)); const cache_1 = __nccwpck_require__(4810); const path = __importStar(__nccwpck_require__(1017)); const distribution_factory_1 = __nccwpck_require__(924); +const os = __importStar(__nccwpck_require__(2037)); function run() { return __awaiter(this, void 0, void 0, function* () { try { const version = core.getInput(constants.INPUT_JAVA_VERSION, { required: true }); const distributionName = core.getInput(constants.INPUT_DISTRIBUTION, { required: true }); - const architecture = core.getInput(constants.INPUT_ARCHITECTURE); + const architecture = core.getInput(constants.INPUT_ARCHITECTURE) || os.arch(); const packageType = core.getInput(constants.INPUT_JAVA_PACKAGE); const jdkFile = core.getInput(constants.INPUT_JDK_FILE); const cache = core.getInput(constants.INPUT_CACHE); From cca7653671ea7cbce30e735f11df9da3d07813fd Mon Sep 17 00:00:00 2001 From: Wes Morgan Date: Wed, 31 Aug 2022 13:03:49 -0600 Subject: [PATCH 06/21] Move os.arch() defaulter to JavaBase constructor --- src/distributions/base-installer.ts | 3 ++- src/setup-java.ts | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/distributions/base-installer.ts b/src/distributions/base-installer.ts index a07db43dc..65e2f3b22 100644 --- a/src/distributions/base-installer.ts +++ b/src/distributions/base-installer.ts @@ -7,6 +7,7 @@ import * as httpm from '@actions/http-client'; import { getToolcachePath, isVersionSatisfies } from '../util'; import { JavaDownloadRelease, JavaInstallerOptions, JavaInstallerResults } from './base-models'; import { MACOS_JAVA_CONTENT_POSTFIX } from '../constants'; +import os from 'os'; export abstract class JavaBase { protected http: httpm.HttpClient; @@ -25,7 +26,7 @@ export abstract class JavaBase { ({ version: this.version, stable: this.stable } = this.normalizeVersion( installerOptions.version )); - this.architecture = installerOptions.architecture; + this.architecture = installerOptions.architecture || os.arch(); this.packageType = installerOptions.packageType; this.checkLatest = installerOptions.checkLatest; } diff --git a/src/setup-java.ts b/src/setup-java.ts index 6ec8efa57..8274be938 100644 --- a/src/setup-java.ts +++ b/src/setup-java.ts @@ -6,13 +6,12 @@ import { restore } from './cache'; import * as path from 'path'; import { getJavaDistribution } from './distributions/distribution-factory'; import { JavaInstallerOptions } from './distributions/base-models'; -import * as os from 'os'; async function run() { try { const version = core.getInput(constants.INPUT_JAVA_VERSION, { required: true }); const distributionName = core.getInput(constants.INPUT_DISTRIBUTION, { required: true }); - const architecture = core.getInput(constants.INPUT_ARCHITECTURE) || os.arch(); + const architecture = core.getInput(constants.INPUT_ARCHITECTURE); const packageType = core.getInput(constants.INPUT_JAVA_PACKAGE); const jdkFile = core.getInput(constants.INPUT_JDK_FILE); const cache = core.getInput(constants.INPUT_CACHE); From e169777d50c486014ebcb377f0cda7ae3bee5584 Mon Sep 17 00:00:00 2001 From: Wes Morgan Date: Wed, 31 Aug 2022 13:05:33 -0600 Subject: [PATCH 07/21] Refactor arch mapping to distributionArchitecture method --- src/distributions/base-installer.ts | 4 ++++ src/distributions/temurin/installer.ts | 10 +++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/distributions/base-installer.ts b/src/distributions/base-installer.ts index 65e2f3b22..fe5fcdc60 100644 --- a/src/distributions/base-installer.ts +++ b/src/distributions/base-installer.ts @@ -149,4 +149,8 @@ export abstract class JavaBase { core.setOutput('path', toolPath); core.setOutput('version', version); } + + protected distributionArchitecture(): string { + return this.architecture; + } } diff --git a/src/distributions/temurin/installer.ts b/src/distributions/temurin/installer.ts index ad61faee5..598cdba9d 100644 --- a/src/distributions/temurin/installer.ts +++ b/src/distributions/temurin/installer.ts @@ -20,7 +20,6 @@ export class TemurinDistribution extends JavaBase { private readonly jvmImpl: TemurinImplementation ) { super(`Temurin-${jvmImpl}`, installerOptions); - installerOptions.architecture = this.osArchToDistributionArch(installerOptions.architecture); } protected async findPackageForDownload(version: string): Promise { @@ -87,7 +86,7 @@ export class TemurinDistribution extends JavaBase { private async getAvailableVersions(): Promise { const platform = this.getPlatformOption(); - const arch = this.architecture; + const arch = this.distributionArchitecture(); const imageType = this.packageType; const versionRange = encodeURI('[1.0,100.0]'); // retrieve all available versions const releaseType = this.stable ? 'ga' : 'ea'; @@ -154,8 +153,9 @@ export class TemurinDistribution extends JavaBase { } } - private osArchToDistributionArch(osArch: string): string { - switch (osArch) { + protected distributionArchitecture(): string { + // Temurin has own architecture names so need to map them + switch (this.architecture) { case 'amd64': return 'x64'; case 'ia32': @@ -163,7 +163,7 @@ export class TemurinDistribution extends JavaBase { case 'arm64': return 'aarch64'; default: - return osArch; + return this.architecture; } } } From c22bb804ce5f791eb4e1ee60eccc711b54d9f165 Mon Sep 17 00:00:00 2001 From: Wes Morgan Date: Wed, 31 Aug 2022 13:05:54 -0600 Subject: [PATCH 08/21] Add tests for os.arch() default behavior --- __tests__/distributors/base-installer.test.ts | 20 ++++++++++++++ .../distributors/temurin-installer.test.ts | 26 ++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/__tests__/distributors/base-installer.test.ts b/__tests__/distributors/base-installer.test.ts index 177c7aced..174460745 100644 --- a/__tests__/distributors/base-installer.test.ts +++ b/__tests__/distributors/base-installer.test.ts @@ -12,6 +12,8 @@ import { JavaInstallerResults } from '../../src/distributions/base-models'; +import os from 'os'; + class EmptyJavaBase extends JavaBase { constructor(installerOptions: JavaInstallerOptions) { super('Empty', installerOptions); @@ -192,6 +194,8 @@ describe('setupJava', () => { spyCoreSetOutput = jest.spyOn(core, 'setOutput'); spyCoreSetOutput.mockImplementation(() => undefined); + + jest.spyOn(os, 'arch').mockReturnValue('x86'); }); afterEach(() => { @@ -212,6 +216,10 @@ describe('setupJava', () => { [ { version: '11.0.8', architecture: 'x86', packageType: 'jdk', checkLatest: false }, { version: installedJavaVersion, path: javaPath } + ], + [ + { version: '11', architecture: '', packageType: 'jdk', checkLatest: false }, + { version: installedJavaVersion, path: javaPath } ] ])('should find java locally for %s', (input, expected) => { mockJavaBase = new EmptyJavaBase(input); @@ -237,6 +245,10 @@ describe('setupJava', () => { [ { version: '11', architecture: 'x64', packageType: 'jre', checkLatest: false }, { path: path.join('toolcache', 'Java_Empty_jre', '11.0.9', 'x64'), version: '11.0.9' } + ], + [ + { version: '11', architecture: '', packageType: 'jre', checkLatest: false }, + { path: path.join('toolcache', 'Java_Empty_jre', '11.0.9', 'x86'), version: '11.0.9' } ] ])('download java with configuration %s', async (input, expected) => { mockJavaBase = new EmptyJavaBase(input); @@ -256,6 +268,10 @@ describe('setupJava', () => { [ { version: '11.0.9', architecture: 'x86', packageType: 'jdk', checkLatest: true }, { version: '11.0.9', path: javaPathInstalled } + ], + [ + { version: '11.0.9', architecture: '', packageType: 'jdk', checkLatest: true }, + { version: '11.0.9', path: javaPathInstalled } ] ])('should check the latest java version for %s and resolve locally', async (input, expected) => { mockJavaBase = new EmptyJavaBase(input); @@ -279,6 +295,10 @@ describe('setupJava', () => { [ { version: '11.0.x', architecture: 'x86', packageType: 'jdk', checkLatest: true }, { version: actualJavaVersion, path: javaPathInstalled } + ], + [ + { version: '11', architecture: '', packageType: 'jdk', checkLatest: true }, + { version: actualJavaVersion, path: javaPathInstalled } ] ])('should check the latest java version for %s and download', async (input, expected) => { mockJavaBase = new EmptyJavaBase(input); diff --git a/__tests__/distributors/temurin-installer.test.ts b/__tests__/distributors/temurin-installer.test.ts index c8904f8fd..581696501 100644 --- a/__tests__/distributors/temurin-installer.test.ts +++ b/__tests__/distributors/temurin-installer.test.ts @@ -1,5 +1,5 @@ import { HttpClient } from '@actions/http-client'; - +import os from 'os'; import { TemurinDistribution, TemurinImplementation @@ -109,6 +109,30 @@ describe('getAvailableVersions', () => { expect(distribution.toolcacheFolderName).toBe(expected); } ); + + it('defaults to os.arch() mapped to temurin arch', async () => { + jest.spyOn(os, 'arch').mockReturnValue('amd64'); + + const installerOptions: JavaInstallerOptions = { + version: '17', + architecture: '', + packageType: 'jdk', + checkLatest: false + }; + + const expectedParameters = + 'os=mac&architecture=x64&image_type=jdk&release_type=ga&jvm_impl=hotspot&page_size=20&page=0'; + + const distribution = new TemurinDistribution(installerOptions, TemurinImplementation.Hotspot); + const baseUrl = 'https://api.adoptium.net/v3/assets/version/%5B1.0,100.0%5D'; + const expectedUrl = `${baseUrl}?project=jdk&vendor=adoptium&heap_size=normal&sort_method=DEFAULT&sort_order=DESC&${expectedParameters}`; + distribution['getPlatformOption'] = () => 'mac'; + + await distribution['getAvailableVersions'](); + + expect(spyHttpClient.mock.calls).toHaveLength(1); + expect(spyHttpClient.mock.calls[0][0]).toBe(expectedUrl); + }); }); describe('findPackageForDownload', () => { From 46869be4a8e4fd37ba147394791da7a8cec3038d Mon Sep 17 00:00:00 2001 From: Wes Morgan Date: Wed, 31 Aug 2022 13:14:09 -0600 Subject: [PATCH 09/21] Commit build artifact --- dist/setup/index.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 26a58b8b8..49807d6c3 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -101753,6 +101753,7 @@ const path_1 = __importDefault(__nccwpck_require__(1017)); const httpm = __importStar(__nccwpck_require__(9925)); const util_1 = __nccwpck_require__(2629); const constants_1 = __nccwpck_require__(9042); +const os_1 = __importDefault(__nccwpck_require__(2037)); class JavaBase { constructor(distribution, installerOptions) { this.distribution = distribution; @@ -101761,7 +101762,7 @@ class JavaBase { maxRetries: 3 }); ({ version: this.version, stable: this.stable } = this.normalizeVersion(installerOptions.version)); - this.architecture = installerOptions.architecture; + this.architecture = installerOptions.architecture || os_1.default.arch(); this.packageType = installerOptions.packageType; this.checkLatest = installerOptions.checkLatest; } @@ -101870,6 +101871,9 @@ class JavaBase { core.setOutput('path', toolPath); core.setOutput('version', version); } + distributionArchitecture() { + return this.architecture; + } } exports.JavaBase = JavaBase; @@ -102555,7 +102559,6 @@ class TemurinDistribution extends base_installer_1.JavaBase { constructor(installerOptions, jvmImpl) { super(`Temurin-${jvmImpl}`, installerOptions); this.jvmImpl = jvmImpl; - installerOptions.architecture = this.osArchToDistributionArch(installerOptions.architecture); } findPackageForDownload(version) { return __awaiter(this, void 0, void 0, function* () { @@ -102610,7 +102613,7 @@ class TemurinDistribution extends base_installer_1.JavaBase { getAvailableVersions() { return __awaiter(this, void 0, void 0, function* () { const platform = this.getPlatformOption(); - const arch = this.architecture; + const arch = this.distributionArchitecture(); const imageType = this.packageType; const versionRange = encodeURI('[1.0,100.0]'); // retrieve all available versions const releaseType = this.stable ? 'ga' : 'ea'; @@ -102667,8 +102670,9 @@ class TemurinDistribution extends base_installer_1.JavaBase { return process.platform; } } - osArchToDistributionArch(osArch) { - switch (osArch) { + distributionArchitecture() { + // Temurin has own architecture names so need to map them + switch (this.architecture) { case 'amd64': return 'x64'; case 'ia32': @@ -102676,7 +102680,7 @@ class TemurinDistribution extends base_installer_1.JavaBase { case 'arm64': return 'aarch64'; default: - return osArch; + return this.architecture; } } } @@ -102978,13 +102982,12 @@ const constants = __importStar(__nccwpck_require__(9042)); const cache_1 = __nccwpck_require__(4810); const path = __importStar(__nccwpck_require__(1017)); const distribution_factory_1 = __nccwpck_require__(924); -const os = __importStar(__nccwpck_require__(2037)); function run() { return __awaiter(this, void 0, void 0, function* () { try { const version = core.getInput(constants.INPUT_JAVA_VERSION, { required: true }); const distributionName = core.getInput(constants.INPUT_DISTRIBUTION, { required: true }); - const architecture = core.getInput(constants.INPUT_ARCHITECTURE) || os.arch(); + const architecture = core.getInput(constants.INPUT_ARCHITECTURE); const packageType = core.getInput(constants.INPUT_JAVA_PACKAGE); const jdkFile = core.getInput(constants.INPUT_JDK_FILE); const cache = core.getInput(constants.INPUT_CACHE); From f21b8ec265729b49104e78620277a0650f3ddfc4 Mon Sep 17 00:00:00 2001 From: Wes Morgan Date: Tue, 13 Sep 2022 08:43:08 -0600 Subject: [PATCH 10/21] Move distributionArchitecture method to base class They are mostly all the same, and this can still be overridden when needed --- src/distributions/base-installer.ts | 18 +++++++++++++++++- src/distributions/temurin/installer.ts | 14 -------------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/distributions/base-installer.ts b/src/distributions/base-installer.ts index fe5fcdc60..ea63e8aa4 100644 --- a/src/distributions/base-installer.ts +++ b/src/distributions/base-installer.ts @@ -151,6 +151,22 @@ export abstract class JavaBase { } protected distributionArchitecture(): string { - return this.architecture; + // default mappings of config architectures to distribution architectures + // override if a distribution uses any different names; see liberica for an example + + // node's os.arch() - which this defaults to - can return any of: + // 'arm', 'arm64', 'ia32', 'mips', 'mipsel', 'ppc', 'ppc64', 's390', 's390x', and 'x64' + // so we need to map these to java distribution architectures + // 'amd64' is included here too b/c it's a common alias for 'x64' people might use explicitly + switch (this.architecture) { + case 'amd64': + return 'x64'; + case 'ia32': + return 'x86'; + case 'arm64': + return 'aarch64'; + default: + return this.architecture; + } } } diff --git a/src/distributions/temurin/installer.ts b/src/distributions/temurin/installer.ts index 598cdba9d..11658576c 100644 --- a/src/distributions/temurin/installer.ts +++ b/src/distributions/temurin/installer.ts @@ -152,18 +152,4 @@ export class TemurinDistribution extends JavaBase { return process.platform; } } - - protected distributionArchitecture(): string { - // Temurin has own architecture names so need to map them - switch (this.architecture) { - case 'amd64': - return 'x64'; - case 'ia32': - return 'x32'; - case 'arm64': - return 'aarch64'; - default: - return this.architecture; - } - } } From 0b04eaf6bbcca245649fc09abcdacfd485578ef0 Mon Sep 17 00:00:00 2001 From: Wes Morgan Date: Tue, 13 Sep 2022 08:44:05 -0600 Subject: [PATCH 11/21] Map OS arch to distro arch for other distros --- src/distributions/adopt/installer.ts | 2 +- src/distributions/corretto/installer.ts | 2 +- src/distributions/liberica/installer.ts | 17 ++++++++++++++--- src/distributions/microsoft/installer.ts | 10 +++++----- src/distributions/zulu/installer.ts | 19 +++++++++++-------- 5 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/distributions/adopt/installer.ts b/src/distributions/adopt/installer.ts index 97a2d3293..f5fb477d0 100644 --- a/src/distributions/adopt/installer.ts +++ b/src/distributions/adopt/installer.ts @@ -88,7 +88,7 @@ export class AdoptDistribution extends JavaBase { private async getAvailableVersions(): Promise { const platform = this.getPlatformOption(); - const arch = this.architecture; + const arch = this.distributionArchitecture(); const imageType = this.packageType; const versionRange = encodeURI('[1.0,100.0]'); // retrieve all available versions const releaseType = this.stable ? 'ga' : 'ea'; diff --git a/src/distributions/corretto/installer.ts b/src/distributions/corretto/installer.ts index 207bf1649..f207ecc73 100644 --- a/src/distributions/corretto/installer.ts +++ b/src/distributions/corretto/installer.ts @@ -68,7 +68,7 @@ export class CorrettoDistribution extends JavaBase { private async getAvailableVersions(): Promise { const platform = this.getPlatformOption(); - const arch = this.architecture; + const arch = this.distributionArchitecture(); const imageType = this.packageType; console.time('coretto-retrieve-available-versions'); diff --git a/src/distributions/liberica/installer.ts b/src/distributions/liberica/installer.ts index d4b32add1..7f8e57cb9 100644 --- a/src/distributions/liberica/installer.ts +++ b/src/distributions/liberica/installer.ts @@ -10,7 +10,7 @@ import path from 'path'; const supportedPlatform = `'linux', 'linux-musl', 'macos', 'solaris', 'windows'`; -const supportedArchitecture = `'x86', 'x64', 'armv7', 'aarch64', 'ppc64le'`; +const supportedArchitectures = `'x86', 'x64', 'armv7', 'aarch64', 'ppc64le'`; export class LibericaDistributions extends JavaBase { constructor(installerOptions: JavaInstallerOptions) { @@ -110,7 +110,8 @@ export class LibericaDistributions extends JavaBase { } private getArchitectureOptions(): ArchitectureOptions { - switch (this.architecture) { + const arch = this.distributionArchitecture(); + switch (arch) { case 'x86': return { bitness: '32', arch: 'x86' }; case 'x64': @@ -123,7 +124,7 @@ export class LibericaDistributions extends JavaBase { return { bitness: '64', arch: 'ppc' }; default: throw new Error( - `Architecture '${this.architecture}' is not supported. Supported architectures: ${supportedArchitecture}` + `Architecture '${this.architecture}' is not supported. Supported architectures: ${supportedArchitectures}` ); } } @@ -154,4 +155,14 @@ export class LibericaDistributions extends JavaBase { } return mainVersion; } + + protected distributionArchitecture(): string { + let arch = super.distributionArchitecture(); + switch (arch) { + case 'arm': + return 'armv7'; + default: + return arch; + } + } } diff --git a/src/distributions/microsoft/installer.ts b/src/distributions/microsoft/installer.ts index 4ceb4285b..8fba1349b 100644 --- a/src/distributions/microsoft/installer.ts +++ b/src/distributions/microsoft/installer.ts @@ -37,7 +37,8 @@ export class MicrosoftDistributions extends JavaBase { } protected async findPackageForDownload(range: string): Promise { - if (this.architecture !== 'x64' && this.architecture !== 'aarch64') { + const arch = this.distributionArchitecture(); + if (arch !== 'x64' && arch !== 'aarch64') { throw new Error(`Unsupported architecture: ${this.architecture}`); } @@ -53,9 +54,8 @@ export class MicrosoftDistributions extends JavaBase { const opts = this.getPlatformOption(); const availableVersions = availableVersionsRaw.map(item => ({ - url: `https://aka.ms/download-jdk/microsoft-jdk-${item.version.join('.')}-${opts.os}-${ - this.architecture - }.${opts.archive}`, + url: `https://aka.ms/download-jdk/microsoft-jdk-${item.version.join('.')}-${opts.os}-${arch + }.${opts.archive}`, version: this.convertVersionToSemver(item) })); @@ -95,7 +95,7 @@ export class MicrosoftDistributions extends JavaBase { ]; // M1 is only supported for Java 16 & 17 - if (process.platform !== 'darwin' || this.architecture !== 'aarch64') { + if (process.platform !== 'darwin' || this.distributionArchitecture() !== 'aarch64') { jdkVersions.push({ version: [11, 0, 13, 8, 1] }); diff --git a/src/distributions/zulu/installer.ts b/src/distributions/zulu/installer.ts index 34679bbd5..8b3b00a44 100644 --- a/src/distributions/zulu/installer.ts +++ b/src/distributions/zulu/installer.ts @@ -129,14 +129,17 @@ export class ZuluDistribution extends JavaBase { hw_bitness: string; abi: string; } { - if (this.architecture == 'x64') { - return { arch: 'x86', hw_bitness: '64', abi: '' }; - } else if (this.architecture == 'x86') { - return { arch: 'x86', hw_bitness: '32', abi: '' }; - } else if (this.architecture == 'arm64') { - return { arch: 'arm', hw_bitness: '64', abi: '' }; - } else { - return { arch: this.architecture, hw_bitness: '', abi: '' }; + const arch = this.distributionArchitecture(); + switch (arch) { + case 'x64': + return { arch: 'x86', hw_bitness: '64', abi: '' }; + case 'x86': + return { arch: 'x86', hw_bitness: '32', abi: '' }; + case 'aarch64': + case 'arm64': + return { arch: 'arm', hw_bitness: '64', abi: '' }; + default: + return { arch: arch, hw_bitness: '', abi: '' }; } } From 7284eeee349352707abf537f03cbe7495d77dfb1 Mon Sep 17 00:00:00 2001 From: Wes Morgan Date: Tue, 13 Sep 2022 09:06:26 -0600 Subject: [PATCH 12/21] Run format --- src/distributions/microsoft/installer.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/distributions/microsoft/installer.ts b/src/distributions/microsoft/installer.ts index 8fba1349b..1c2fdf720 100644 --- a/src/distributions/microsoft/installer.ts +++ b/src/distributions/microsoft/installer.ts @@ -54,8 +54,9 @@ export class MicrosoftDistributions extends JavaBase { const opts = this.getPlatformOption(); const availableVersions = availableVersionsRaw.map(item => ({ - url: `https://aka.ms/download-jdk/microsoft-jdk-${item.version.join('.')}-${opts.os}-${arch - }.${opts.archive}`, + url: `https://aka.ms/download-jdk/microsoft-jdk-${item.version.join('.')}-${ + opts.os + }-${arch}.${opts.archive}`, version: this.convertVersionToSemver(item) })); From 43c9a22bb368ffb2a97ea2ee49b2e608ea270c17 Mon Sep 17 00:00:00 2001 From: Wes Morgan Date: Tue, 13 Sep 2022 09:06:41 -0600 Subject: [PATCH 13/21] Run build --- dist/setup/index.js | 79 ++++++++++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 33 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 49807d6c3..3a1fccec3 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -101644,7 +101644,7 @@ class AdoptDistribution extends base_installer_1.JavaBase { getAvailableVersions() { return __awaiter(this, void 0, void 0, function* () { const platform = this.getPlatformOption(); - const arch = this.architecture; + const arch = this.distributionArchitecture(); const imageType = this.packageType; const versionRange = encodeURI('[1.0,100.0]'); // retrieve all available versions const releaseType = this.stable ? 'ga' : 'ea'; @@ -101872,7 +101872,22 @@ class JavaBase { core.setOutput('version', version); } distributionArchitecture() { - return this.architecture; + // default mappings of config architectures to distribution architectures + // override if a distribution uses any different names; see liberica for an example + // node's os.arch() - which this defaults to - can return any of: + // 'arm', 'arm64', 'ia32', 'mips', 'mipsel', 'ppc', 'ppc64', 's390', 's390x', and 'x64' + // so we need to map these to java distribution architectures + // 'amd64' is included here too b/c it's a common alias for 'x64' people might use explicitly + switch (this.architecture) { + case 'amd64': + return 'x64'; + case 'ia32': + return 'x86'; + case 'arm64': + return 'aarch64'; + default: + return this.architecture; + } } } exports.JavaBase = JavaBase; @@ -101973,7 +101988,7 @@ class CorrettoDistribution extends base_installer_1.JavaBase { var _a, _b; return __awaiter(this, void 0, void 0, function* () { const platform = this.getPlatformOption(); - const arch = this.architecture; + const arch = this.distributionArchitecture(); const imageType = this.packageType; console.time('coretto-retrieve-available-versions'); const availableVersionsUrl = 'https://corretto.github.io/corretto-downloads/latest_links/indexmap_with_checksum.json'; @@ -102146,7 +102161,7 @@ const tc = __importStar(__nccwpck_require__(7784)); const fs_1 = __importDefault(__nccwpck_require__(7147)); const path_1 = __importDefault(__nccwpck_require__(1017)); const supportedPlatform = `'linux', 'linux-musl', 'macos', 'solaris', 'windows'`; -const supportedArchitecture = `'x86', 'x64', 'armv7', 'aarch64', 'ppc64le'`; +const supportedArchitectures = `'x86', 'x64', 'armv7', 'aarch64', 'ppc64le'`; class LibericaDistributions extends base_installer_1.JavaBase { constructor(installerOptions) { super('Liberica', installerOptions); @@ -102216,7 +102231,8 @@ class LibericaDistributions extends base_installer_1.JavaBase { return bundleType; } getArchitectureOptions() { - switch (this.architecture) { + const arch = this.distributionArchitecture(); + switch (arch) { case 'x86': return { bitness: '32', arch: 'x86' }; case 'x64': @@ -102228,7 +102244,7 @@ class LibericaDistributions extends base_installer_1.JavaBase { case 'ppc64le': return { bitness: '64', arch: 'ppc' }; default: - throw new Error(`Architecture '${this.architecture}' is not supported. Supported architectures: ${supportedArchitecture}`); + throw new Error(`Architecture '${this.architecture}' is not supported. Supported architectures: ${supportedArchitectures}`); } } getPlatformOption(platform = process.platform) { @@ -102254,6 +102270,15 @@ class LibericaDistributions extends base_installer_1.JavaBase { } return mainVersion; } + distributionArchitecture() { + let arch = super.distributionArchitecture(); + switch (arch) { + case 'arm': + return 'armv7'; + default: + return arch; + } + } } exports.LibericaDistributions = LibericaDistributions; @@ -102427,7 +102452,8 @@ class MicrosoftDistributions extends base_installer_1.JavaBase { } findPackageForDownload(range) { return __awaiter(this, void 0, void 0, function* () { - if (this.architecture !== 'x64' && this.architecture !== 'aarch64') { + const arch = this.distributionArchitecture(); + if (arch !== 'x64' && arch !== 'aarch64') { throw new Error(`Unsupported architecture: ${this.architecture}`); } if (!this.stable) { @@ -102439,7 +102465,7 @@ class MicrosoftDistributions extends base_installer_1.JavaBase { const availableVersionsRaw = yield this.getAvailableVersions(); const opts = this.getPlatformOption(); const availableVersions = availableVersionsRaw.map(item => ({ - url: `https://aka.ms/download-jdk/microsoft-jdk-${item.version.join('.')}-${opts.os}-${this.architecture}.${opts.archive}`, + url: `https://aka.ms/download-jdk/microsoft-jdk-${item.version.join('.')}-${opts.os}-${arch}.${opts.archive}`, version: this.convertVersionToSemver(item) })); const satisfiedVersion = availableVersions @@ -102474,7 +102500,7 @@ class MicrosoftDistributions extends base_installer_1.JavaBase { } ]; // M1 is only supported for Java 16 & 17 - if (process.platform !== 'darwin' || this.architecture !== 'aarch64') { + if (process.platform !== 'darwin' || this.distributionArchitecture() !== 'aarch64') { jdkVersions.push({ version: [11, 0, 13, 8, 1] }); @@ -102670,19 +102696,6 @@ class TemurinDistribution extends base_installer_1.JavaBase { return process.platform; } } - distributionArchitecture() { - // Temurin has own architecture names so need to map them - switch (this.architecture) { - case 'amd64': - return 'x64'; - case 'ia32': - return 'x32'; - case 'arm64': - return 'aarch64'; - default: - return this.architecture; - } - } } exports.TemurinDistribution = TemurinDistribution; @@ -102826,17 +102839,17 @@ class ZuluDistribution extends base_installer_1.JavaBase { }); } getArchitectureOptions() { - if (this.architecture == 'x64') { - return { arch: 'x86', hw_bitness: '64', abi: '' }; - } - else if (this.architecture == 'x86') { - return { arch: 'x86', hw_bitness: '32', abi: '' }; - } - else if (this.architecture == 'arm64') { - return { arch: 'arm', hw_bitness: '64', abi: '' }; - } - else { - return { arch: this.architecture, hw_bitness: '', abi: '' }; + const arch = this.distributionArchitecture(); + switch (arch) { + case 'x64': + return { arch: 'x86', hw_bitness: '64', abi: '' }; + case 'x86': + return { arch: 'x86', hw_bitness: '32', abi: '' }; + case 'aarch64': + case 'arm64': + return { arch: 'arm', hw_bitness: '64', abi: '' }; + default: + return { arch: arch, hw_bitness: '', abi: '' }; } } getPlatformOption() { From f83416a0807675ca3a367b5187fa2080688b93cd Mon Sep 17 00:00:00 2001 From: Wes Morgan Date: Mon, 19 Sep 2022 09:16:19 -0600 Subject: [PATCH 14/21] Default architecture to x86 in test --- __tests__/distributors/base-installer.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__tests__/distributors/base-installer.test.ts b/__tests__/distributors/base-installer.test.ts index 344f16cd0..44ec50bb7 100644 --- a/__tests__/distributors/base-installer.test.ts +++ b/__tests__/distributors/base-installer.test.ts @@ -257,7 +257,7 @@ describe('setupJava', () => { expect(spyCoreAddPath).toHaveBeenCalled(); expect(spyCoreExportVariable).toHaveBeenCalled(); expect(spyCoreExportVariable).toHaveBeenCalledWith( - `JAVA_HOME_${input.version}_${input.architecture.toLocaleUpperCase()}`, + `JAVA_HOME_${input.version}_${(input.architecture || 'x86').toLocaleUpperCase()}`, expected.path ); expect(spyCoreSetOutput).toHaveBeenCalled(); From c041f7cce2c4052df3b4135c295379b071592d00 Mon Sep 17 00:00:00 2001 From: Wes Morgan Date: Tue, 20 Sep 2022 10:03:12 -0600 Subject: [PATCH 15/21] Add arch default tests to all distros ...and update temurin's to test 2 architectures instead of 1. --- .../distributors/adopt-installer.test.ts | 31 ++++++++++++++ .../distributors/corretto-installer.test.ts | 29 +++++++++++++ .../distributors/liberica-installer.test.ts | 34 +++++++++++++++ .../distributors/microsoft-installer.test.ts | 28 +++++++++++++ .../distributors/temurin-installer.test.ts | 41 +++++++++++-------- __tests__/distributors/zulu-installer.test.ts | 29 +++++++++++++ 6 files changed, 174 insertions(+), 18 deletions(-) diff --git a/__tests__/distributors/adopt-installer.test.ts b/__tests__/distributors/adopt-installer.test.ts index ce862c26f..a900f858c 100644 --- a/__tests__/distributors/adopt-installer.test.ts +++ b/__tests__/distributors/adopt-installer.test.ts @@ -3,6 +3,8 @@ import { HttpClient } from '@actions/http-client'; import { AdoptDistribution, AdoptImplementation } from '../../src/distributions/adopt/installer'; import { JavaInstallerOptions } from '../../src/distributions/base-models'; +import os from 'os'; + let manifestData = require('../data/adopt.json') as []; describe('getAvailableVersions', () => { @@ -128,6 +130,35 @@ describe('getAvailableVersions', () => { expect(distribution.toolcacheFolderName).toBe(expected); } ); + + it.each([ + ['amd64', 'x64'], + ['arm64', 'aarch64'] + ])( + 'defaults to os.arch(): %s mapped to distro arch: %s', + async (osArch: string, distroArch: string) => { + jest.spyOn(os, 'arch').mockReturnValue(osArch); + + const installerOptions: JavaInstallerOptions = { + version: '17', + architecture: '', // to get default value + packageType: 'jdk', + checkLatest: false + }; + + const expectedParameters = `os=mac&architecture=${distroArch}&image_type=jdk&release_type=ga&jvm_impl=hotspot&page_size=20&page=0`; + + const distribution = new AdoptDistribution(installerOptions, AdoptImplementation.Hotspot); + const baseUrl = 'https://api.adoptopenjdk.net/v3/assets/version/%5B1.0,100.0%5D'; + const expectedUrl = `${baseUrl}?project=jdk&vendor=adoptopenjdk&heap_size=normal&sort_method=DEFAULT&sort_order=DESC&${expectedParameters}`; + distribution['getPlatformOption'] = () => 'mac'; + + await distribution['getAvailableVersions'](); + + expect(spyHttpClient.mock.calls).toHaveLength(1); + expect(spyHttpClient.mock.calls[0][0]).toBe(expectedUrl); + } + ); }); describe('findPackageForDownload', () => { diff --git a/__tests__/distributors/corretto-installer.test.ts b/__tests__/distributors/corretto-installer.test.ts index 3e3322feb..eae259da0 100644 --- a/__tests__/distributors/corretto-installer.test.ts +++ b/__tests__/distributors/corretto-installer.test.ts @@ -3,6 +3,8 @@ import { JavaInstallerOptions } from '../../src/distributions/base-models'; import { CorrettoDistribution } from '../../src/distributions/corretto/installer'; import * as util from '../../src/util'; +import os from 'os'; +import { isGeneratorFunction } from 'util/types'; const manifestData = require('../data/corretto.json') as []; @@ -142,6 +144,33 @@ describe('getAvailableVersions', () => { "Could not find satisfied version for SemVer '4'" ); }); + + it.each([ + ['arm64', 'aarch64'], + ['amd64', 'x64'] + ])( + 'defaults to os.arch(): %s mapped to distro arch: %s', + async (osArch: string, distroArch: string) => { + jest.spyOn(os, 'arch').mockReturnValue(osArch); + + const version = '17'; + const installerOptions: JavaInstallerOptions = { + version, + architecture: '', // to get default value + packageType: 'jdk', + checkLatest: false + }; + + const distribution = new CorrettoDistribution(installerOptions); + mockPlatform(distribution, 'macos'); + + const expectedLink = `https://corretto.aws/downloads/resources/17.0.2.8.1/amazon-corretto-17.0.2.8.1-macosx-${distroArch}.tar.gz`; + + const availableVersion = await distribution['findPackageForDownload'](version); + expect(availableVersion).not.toBeNull(); + expect(availableVersion.url).toBe(expectedLink); + } + ); }); const mockPlatform = (distribution: CorrettoDistribution, platform: string) => { diff --git a/__tests__/distributors/liberica-installer.test.ts b/__tests__/distributors/liberica-installer.test.ts index 1044e7f48..18135f29a 100644 --- a/__tests__/distributors/liberica-installer.test.ts +++ b/__tests__/distributors/liberica-installer.test.ts @@ -1,6 +1,7 @@ import { LibericaDistributions } from '../../src/distributions/liberica/installer'; import { ArchitectureOptions, LibericaVersion } from '../../src/distributions/liberica/models'; import { HttpClient } from '@actions/http-client'; +import os from 'os'; const manifestData = require('../data/liberica.json') as LibericaVersion[]; @@ -61,6 +62,39 @@ describe('getAvailableVersions', () => { expect(spyHttpClient.mock.calls[0][0]).toBe(buildUrl); }); + type DistroArch = { + bitness: string; + arch: string; + }; + it.each([ + ['amd64', { bitness: '64', arch: 'x86' }], + ['arm64', { bitness: '64', arch: 'arm' }] + ])( + 'defaults to os.arch(): %s mapped to distro arch: %s', + async (osArch: string, distroArch: DistroArch) => { + jest.spyOn(os, 'arch').mockReturnValue(osArch); + + const distribution = new LibericaDistributions({ + version: '17', + architecture: '', // to get default value + packageType: 'jdk', + checkLatest: false + }); + + const additionalParams = + '&installation-type=archive&fields=downloadUrl%2Cversion%2CfeatureVersion%2CinterimVersion%2C' + + 'updateVersion%2CbuildVersion'; + distribution['getPlatformOption'] = () => 'macos'; + + const buildUrl = `https://api.bell-sw.com/v1/liberica/releases?os=macos&bundle-type=jdk&bitness=${distroArch.bitness}&arch=${distroArch.arch}&build-type=all${additionalParams}`; + + await distribution['getAvailableVersions'](); + + expect(spyHttpClient.mock.calls).toHaveLength(1); + expect(spyHttpClient.mock.calls[0][0]).toBe(buildUrl); + } + ); + it('load available versions', async () => { const distribution = new LibericaDistributions({ version: '11', diff --git a/__tests__/distributors/microsoft-installer.test.ts b/__tests__/distributors/microsoft-installer.test.ts index 9be0f50ea..eca3ccfa6 100644 --- a/__tests__/distributors/microsoft-installer.test.ts +++ b/__tests__/distributors/microsoft-installer.test.ts @@ -1,4 +1,5 @@ import { MicrosoftDistributions } from '../../src/distributions/microsoft/installer'; +import os from 'os'; describe('findPackageForDownload', () => { let distribution: MicrosoftDistributions; @@ -61,6 +62,33 @@ describe('findPackageForDownload', () => { expect(result.url).toBe(url); }); + it.each([ + ['amd64', 'x64'], + ['arm64', 'aarch64'] + ])( + 'defaults to os.arch(): %s mapped to distro arch: %s', + async (osArch: string, distroArch: string) => { + jest.spyOn(os, 'arch').mockReturnValue(osArch); + + const version = '17'; + const distro = new MicrosoftDistributions({ + version, + architecture: '', // to get default value + packageType: 'jdk', + checkLatest: false + }); + + distribution['getPlatformOption'] = () => { + return { archive: 'tar.gz', os: 'macos' }; + }; + + const result = await distro['findPackageForDownload'](version); + const expectedUrl = `https://aka.ms/download-jdk/microsoft-jdk-17.0.3-macos-${distroArch}.tar.gz`; + + expect(result.url).toBe(expectedUrl); + } + ); + it('should throw an error', async () => { await expect(distribution['findPackageForDownload']('8')).rejects.toThrow( /Could not find satisfied version for SemVer */ diff --git a/__tests__/distributors/temurin-installer.test.ts b/__tests__/distributors/temurin-installer.test.ts index 581696501..554668ba7 100644 --- a/__tests__/distributors/temurin-installer.test.ts +++ b/__tests__/distributors/temurin-installer.test.ts @@ -110,29 +110,34 @@ describe('getAvailableVersions', () => { } ); - it('defaults to os.arch() mapped to temurin arch', async () => { - jest.spyOn(os, 'arch').mockReturnValue('amd64'); + it.each([ + ['amd64', 'x64'], + ['arm64', 'aarch64'] + ])( + 'defaults to os.arch(): %s mapped to distro arch: %s', + async (osArch: string, distroArch: string) => { + jest.spyOn(os, 'arch').mockReturnValue(distroArch); - const installerOptions: JavaInstallerOptions = { - version: '17', - architecture: '', - packageType: 'jdk', - checkLatest: false - }; + const installerOptions: JavaInstallerOptions = { + version: '17', + architecture: '', + packageType: 'jdk', + checkLatest: false + }; - const expectedParameters = - 'os=mac&architecture=x64&image_type=jdk&release_type=ga&jvm_impl=hotspot&page_size=20&page=0'; + const expectedParameters = `os=mac&architecture=${distroArch}&image_type=jdk&release_type=ga&jvm_impl=hotspot&page_size=20&page=0`; - const distribution = new TemurinDistribution(installerOptions, TemurinImplementation.Hotspot); - const baseUrl = 'https://api.adoptium.net/v3/assets/version/%5B1.0,100.0%5D'; - const expectedUrl = `${baseUrl}?project=jdk&vendor=adoptium&heap_size=normal&sort_method=DEFAULT&sort_order=DESC&${expectedParameters}`; - distribution['getPlatformOption'] = () => 'mac'; + const distribution = new TemurinDistribution(installerOptions, TemurinImplementation.Hotspot); + const baseUrl = 'https://api.adoptium.net/v3/assets/version/%5B1.0,100.0%5D'; + const expectedUrl = `${baseUrl}?project=jdk&vendor=adoptium&heap_size=normal&sort_method=DEFAULT&sort_order=DESC&${expectedParameters}`; + distribution['getPlatformOption'] = () => 'mac'; - await distribution['getAvailableVersions'](); + await distribution['getAvailableVersions'](); - expect(spyHttpClient.mock.calls).toHaveLength(1); - expect(spyHttpClient.mock.calls[0][0]).toBe(expectedUrl); - }); + expect(spyHttpClient.mock.calls).toHaveLength(1); + expect(spyHttpClient.mock.calls[0][0]).toBe(expectedUrl); + } + ); }); describe('findPackageForDownload', () => { diff --git a/__tests__/distributors/zulu-installer.test.ts b/__tests__/distributors/zulu-installer.test.ts index 8f73192dd..4a43c7898 100644 --- a/__tests__/distributors/zulu-installer.test.ts +++ b/__tests__/distributors/zulu-installer.test.ts @@ -3,6 +3,7 @@ import * as semver from 'semver'; import { ZuluDistribution } from '../../src/distributions/zulu/installer'; import { IZuluVersions } from '../../src/distributions/zulu/models'; import * as utils from '../../src/util'; +import os from 'os'; const manifestData = require('../data/zulu-releases-default.json') as []; @@ -72,6 +73,34 @@ describe('getAvailableVersions', () => { expect(spyHttpClient.mock.calls[0][0]).toBe(buildUrl); }); + type DistroArch = { + bitness: string; + arch: string; + }; + it.each([ + ['amd64', { bitness: '64', arch: 'x86' }], + ['arm64', { bitness: '64', arch: 'arm' }] + ])( + 'defaults to os.arch(): %s mapped to distro arch: %s', + async (osArch: string, distroArch: DistroArch) => { + jest.spyOn(os, 'arch').mockReturnValue(osArch); + + const distribution = new ZuluDistribution({ + version: '17', + architecture: '', // to get default value + packageType: 'jdk', + checkLatest: false + }); + distribution['getPlatformOption'] = () => 'macos'; + const buildUrl = `https://api.azul.com/zulu/download/community/v1.0/bundles/?os=macos&ext=tar.gz&bundle_type=jdk&javafx=false&arch=${distroArch.arch}&hw_bitness=${distroArch.bitness}&release_status=ga`; + + await distribution['getAvailableVersions'](); + + expect(spyHttpClient.mock.calls).toHaveLength(1); + expect(spyHttpClient.mock.calls[0][0]).toBe(buildUrl); + } + ); + it('load available versions', async () => { const distribution = new ZuluDistribution({ version: '11', From 06bcb9d3c7523eae8e8697f20c4d440391060586 Mon Sep 17 00:00:00 2001 From: Wes Morgan Date: Wed, 21 Sep 2022 08:29:29 -0600 Subject: [PATCH 16/21] Fix microsoft installer test on non-macOS platforms --- __tests__/distributors/microsoft-installer.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__tests__/distributors/microsoft-installer.test.ts b/__tests__/distributors/microsoft-installer.test.ts index eca3ccfa6..e051d034f 100644 --- a/__tests__/distributors/microsoft-installer.test.ts +++ b/__tests__/distributors/microsoft-installer.test.ts @@ -78,7 +78,7 @@ describe('findPackageForDownload', () => { checkLatest: false }); - distribution['getPlatformOption'] = () => { + distro['getPlatformOption'] = () => { return { archive: 'tar.gz', os: 'macos' }; }; From da9079a72d32911cbcf26f75cda27ec63785d267 Mon Sep 17 00:00:00 2001 From: Wes Morgan Date: Fri, 23 Sep 2022 10:25:09 -0600 Subject: [PATCH 17/21] Run npm format --- __tests__/distributors/microsoft-installer.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__tests__/distributors/microsoft-installer.test.ts b/__tests__/distributors/microsoft-installer.test.ts index 6bfef1023..e35d8c8c3 100644 --- a/__tests__/distributors/microsoft-installer.test.ts +++ b/__tests__/distributors/microsoft-installer.test.ts @@ -25,7 +25,7 @@ describe('findPackageForDownload', () => { }); spyDebug = jest.spyOn(core, 'debug'); - spyDebug.mockImplementation(() => { }); + spyDebug.mockImplementation(() => {}); }); it.each([ From df9446d789058024b149b92381b0e4f94e47278f Mon Sep 17 00:00:00 2001 From: Wes Morgan Date: Wed, 5 Oct 2022 10:52:34 -0600 Subject: [PATCH 18/21] Remove default architecture value ...so that it can default to the runner's architecture. --- action.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 499eae3f5..d8669d564 100644 --- a/action.yml +++ b/action.yml @@ -14,9 +14,8 @@ inputs: required: false default: 'jdk' architecture: - description: 'The architecture of the package' + description: 'The architecture of the package (defaults to the action runner's architecture)' required: false - default: 'x64' jdkFile: description: 'Path to where the compressed JDK is located' required: false From 2f647ea8f98c39c2ce7bc8c6cf926320e422b89c Mon Sep 17 00:00:00 2001 From: Wes Morgan Date: Wed, 5 Oct 2022 11:27:19 -0600 Subject: [PATCH 19/21] Use blank string for architecture default value --- action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/action.yml b/action.yml index d8669d564..3677d4b9b 100644 --- a/action.yml +++ b/action.yml @@ -16,6 +16,7 @@ inputs: architecture: description: 'The architecture of the package (defaults to the action runner's architecture)' required: false + default: '' jdkFile: description: 'Path to where the compressed JDK is located' required: false From a1a9075fb8694ce5eeda9bdddf2ef99059348e19 Mon Sep 17 00:00:00 2001 From: Wes Morgan Date: Thu, 6 Oct 2022 09:15:29 -0600 Subject: [PATCH 20/21] Revert "Use blank string for architecture default value" This reverts commit 2f647ea8f98c39c2ce7bc8c6cf926320e422b89c. --- action.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/action.yml b/action.yml index 3677d4b9b..d8669d564 100644 --- a/action.yml +++ b/action.yml @@ -16,7 +16,6 @@ inputs: architecture: description: 'The architecture of the package (defaults to the action runner's architecture)' required: false - default: '' jdkFile: description: 'Path to where the compressed JDK is located' required: false From 04e13d1cf926be4bd9cda98a4dd5c96de4228900 Mon Sep 17 00:00:00 2001 From: Wes Morgan Date: Fri, 7 Oct 2022 07:45:46 -0600 Subject: [PATCH 21/21] Use double quotes in architecture description --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index ec11180a1..3ace2c663 100644 --- a/action.yml +++ b/action.yml @@ -14,7 +14,7 @@ inputs: required: false default: 'jdk' architecture: - description: 'The architecture of the package (defaults to the action runner's architecture)' + description: "The architecture of the package (defaults to the action runner's architecture)" required: false jdkFile: description: 'Path to where the compressed JDK is located'