Skip to content

Commit 3617c43

Browse files
authored
Default to runner architecture (actions#376)
1 parent a82e6d0 commit 3617c43

16 files changed

+303
-42
lines changed

__tests__/distributors/adopt-installer.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { HttpClient } from '@actions/http-client';
33
import { AdoptDistribution, AdoptImplementation } from '../../src/distributions/adopt/installer';
44
import { JavaInstallerOptions } from '../../src/distributions/base-models';
55

6+
import os from 'os';
7+
68
let manifestData = require('../data/adopt.json') as [];
79

810
describe('getAvailableVersions', () => {
@@ -128,6 +130,35 @@ describe('getAvailableVersions', () => {
128130
expect(distribution.toolcacheFolderName).toBe(expected);
129131
}
130132
);
133+
134+
it.each([
135+
['amd64', 'x64'],
136+
['arm64', 'aarch64']
137+
])(
138+
'defaults to os.arch(): %s mapped to distro arch: %s',
139+
async (osArch: string, distroArch: string) => {
140+
jest.spyOn(os, 'arch').mockReturnValue(osArch);
141+
142+
const installerOptions: JavaInstallerOptions = {
143+
version: '17',
144+
architecture: '', // to get default value
145+
packageType: 'jdk',
146+
checkLatest: false
147+
};
148+
149+
const expectedParameters = `os=mac&architecture=${distroArch}&image_type=jdk&release_type=ga&jvm_impl=hotspot&page_size=20&page=0`;
150+
151+
const distribution = new AdoptDistribution(installerOptions, AdoptImplementation.Hotspot);
152+
const baseUrl = 'https://api.adoptopenjdk.net/v3/assets/version/%5B1.0,100.0%5D';
153+
const expectedUrl = `${baseUrl}?project=jdk&vendor=adoptopenjdk&heap_size=normal&sort_method=DEFAULT&sort_order=DESC&${expectedParameters}`;
154+
distribution['getPlatformOption'] = () => 'mac';
155+
156+
await distribution['getAvailableVersions']();
157+
158+
expect(spyHttpClient.mock.calls).toHaveLength(1);
159+
expect(spyHttpClient.mock.calls[0][0]).toBe(expectedUrl);
160+
}
161+
);
131162
});
132163

133164
describe('findPackageForDownload', () => {

__tests__/distributors/base-installer.test.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import {
1212
JavaInstallerResults
1313
} from '../../src/distributions/base-models';
1414

15+
import os from 'os';
16+
1517
class EmptyJavaBase extends JavaBase {
1618
constructor(installerOptions: JavaInstallerOptions) {
1719
super('Empty', installerOptions);
@@ -192,6 +194,8 @@ describe('setupJava', () => {
192194

193195
spyCoreSetOutput = jest.spyOn(core, 'setOutput');
194196
spyCoreSetOutput.mockImplementation(() => undefined);
197+
198+
jest.spyOn(os, 'arch').mockReturnValue('x86');
195199
});
196200

197201
afterEach(() => {
@@ -212,6 +216,10 @@ describe('setupJava', () => {
212216
[
213217
{ version: '11.0.8', architecture: 'x86', packageType: 'jdk', checkLatest: false },
214218
{ version: installedJavaVersion, path: javaPath }
219+
],
220+
[
221+
{ version: '11', architecture: '', packageType: 'jdk', checkLatest: false },
222+
{ version: installedJavaVersion, path: javaPath }
215223
]
216224
])('should find java locally for %s', (input, expected) => {
217225
mockJavaBase = new EmptyJavaBase(input);
@@ -237,6 +245,10 @@ describe('setupJava', () => {
237245
[
238246
{ version: '11', architecture: 'x64', packageType: 'jre', checkLatest: false },
239247
{ path: path.join('toolcache', 'Java_Empty_jre', '11.0.9', 'x64'), version: '11.0.9' }
248+
],
249+
[
250+
{ version: '11', architecture: '', packageType: 'jre', checkLatest: false },
251+
{ path: path.join('toolcache', 'Java_Empty_jre', '11.0.9', 'x86'), version: '11.0.9' }
240252
]
241253
])('download java with configuration %s', async (input, expected) => {
242254
mockJavaBase = new EmptyJavaBase(input);
@@ -245,7 +257,7 @@ describe('setupJava', () => {
245257
expect(spyCoreAddPath).toHaveBeenCalled();
246258
expect(spyCoreExportVariable).toHaveBeenCalled();
247259
expect(spyCoreExportVariable).toHaveBeenCalledWith(
248-
`JAVA_HOME_${input.version}_${input.architecture.toLocaleUpperCase()}`,
260+
`JAVA_HOME_${input.version}_${(input.architecture || 'x86').toLocaleUpperCase()}`,
249261
expected.path
250262
);
251263
expect(spyCoreSetOutput).toHaveBeenCalled();
@@ -260,6 +272,10 @@ describe('setupJava', () => {
260272
[
261273
{ version: '11.0.9', architecture: 'x86', packageType: 'jdk', checkLatest: true },
262274
{ version: '11.0.9', path: javaPathInstalled }
275+
],
276+
[
277+
{ version: '11.0.9', architecture: '', packageType: 'jdk', checkLatest: true },
278+
{ version: '11.0.9', path: javaPathInstalled }
263279
]
264280
])('should check the latest java version for %s and resolve locally', async (input, expected) => {
265281
mockJavaBase = new EmptyJavaBase(input);
@@ -283,6 +299,10 @@ describe('setupJava', () => {
283299
[
284300
{ version: '11.0.x', architecture: 'x86', packageType: 'jdk', checkLatest: true },
285301
{ version: actualJavaVersion, path: javaPathInstalled }
302+
],
303+
[
304+
{ version: '11', architecture: '', packageType: 'jdk', checkLatest: true },
305+
{ version: actualJavaVersion, path: javaPathInstalled }
286306
]
287307
])('should check the latest java version for %s and download', async (input, expected) => {
288308
mockJavaBase = new EmptyJavaBase(input);

__tests__/distributors/corretto-installer.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { JavaInstallerOptions } from '../../src/distributions/base-models';
33

44
import { CorrettoDistribution } from '../../src/distributions/corretto/installer';
55
import * as util from '../../src/util';
6+
import os from 'os';
7+
import { isGeneratorFunction } from 'util/types';
68

79
const manifestData = require('../data/corretto.json') as [];
810

@@ -142,6 +144,33 @@ describe('getAvailableVersions', () => {
142144
"Could not find satisfied version for SemVer '4'"
143145
);
144146
});
147+
148+
it.each([
149+
['arm64', 'aarch64'],
150+
['amd64', 'x64']
151+
])(
152+
'defaults to os.arch(): %s mapped to distro arch: %s',
153+
async (osArch: string, distroArch: string) => {
154+
jest.spyOn(os, 'arch').mockReturnValue(osArch);
155+
156+
const version = '17';
157+
const installerOptions: JavaInstallerOptions = {
158+
version,
159+
architecture: '', // to get default value
160+
packageType: 'jdk',
161+
checkLatest: false
162+
};
163+
164+
const distribution = new CorrettoDistribution(installerOptions);
165+
mockPlatform(distribution, 'macos');
166+
167+
const expectedLink = `https://corretto.aws/downloads/resources/17.0.2.8.1/amazon-corretto-17.0.2.8.1-macosx-${distroArch}.tar.gz`;
168+
169+
const availableVersion = await distribution['findPackageForDownload'](version);
170+
expect(availableVersion).not.toBeNull();
171+
expect(availableVersion.url).toBe(expectedLink);
172+
}
173+
);
145174
});
146175

147176
const mockPlatform = (distribution: CorrettoDistribution, platform: string) => {

__tests__/distributors/liberica-installer.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { LibericaDistributions } from '../../src/distributions/liberica/installer';
22
import { ArchitectureOptions, LibericaVersion } from '../../src/distributions/liberica/models';
33
import { HttpClient } from '@actions/http-client';
4+
import os from 'os';
45

56
const manifestData = require('../data/liberica.json') as LibericaVersion[];
67

@@ -61,6 +62,39 @@ describe('getAvailableVersions', () => {
6162
expect(spyHttpClient.mock.calls[0][0]).toBe(buildUrl);
6263
});
6364

65+
type DistroArch = {
66+
bitness: string;
67+
arch: string;
68+
};
69+
it.each([
70+
['amd64', { bitness: '64', arch: 'x86' }],
71+
['arm64', { bitness: '64', arch: 'arm' }]
72+
])(
73+
'defaults to os.arch(): %s mapped to distro arch: %s',
74+
async (osArch: string, distroArch: DistroArch) => {
75+
jest.spyOn(os, 'arch').mockReturnValue(osArch);
76+
77+
const distribution = new LibericaDistributions({
78+
version: '17',
79+
architecture: '', // to get default value
80+
packageType: 'jdk',
81+
checkLatest: false
82+
});
83+
84+
const additionalParams =
85+
'&installation-type=archive&fields=downloadUrl%2Cversion%2CfeatureVersion%2CinterimVersion%2C' +
86+
'updateVersion%2CbuildVersion';
87+
distribution['getPlatformOption'] = () => 'macos';
88+
89+
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}`;
90+
91+
await distribution['getAvailableVersions']();
92+
93+
expect(spyHttpClient.mock.calls).toHaveLength(1);
94+
expect(spyHttpClient.mock.calls[0][0]).toBe(buildUrl);
95+
}
96+
);
97+
6498
it('load available versions', async () => {
6599
const distribution = new LibericaDistributions({
66100
version: '11',

__tests__/distributors/microsoft-installer.test.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { MicrosoftDistributions } from '../../src/distributions/microsoft/installer';
2-
import * as tc from '@actions/tool-cache';
2+
import os from 'os';
33
import data from '../../src/distributions/microsoft/microsoft-openjdk-versions.json';
44
import * as httpm from '@actions/http-client';
55
import * as core from '@actions/core';
@@ -77,6 +77,30 @@ describe('findPackageForDownload', () => {
7777
expect(result.url).toBe(url);
7878
});
7979

80+
it.each([
81+
['amd64', 'x64'],
82+
['arm64', 'aarch64']
83+
])(
84+
'defaults to os.arch(): %s mapped to distro arch: %s',
85+
async (osArch: string, distroArch: string) => {
86+
jest.spyOn(os, 'arch').mockReturnValue(osArch);
87+
jest.spyOn(os, 'platform').mockReturnValue('linux');
88+
89+
const version = '17';
90+
const distro = new MicrosoftDistributions({
91+
version,
92+
architecture: '', // to get default value
93+
packageType: 'jdk',
94+
checkLatest: false
95+
});
96+
97+
const result = await distro['findPackageForDownload'](version);
98+
const expectedUrl = `https://aka.ms/download-jdk/microsoft-jdk-17.0.3-linux-${distroArch}.tar.gz`;
99+
100+
expect(result.url).toBe(expectedUrl);
101+
}
102+
);
103+
80104
it('should throw an error', async () => {
81105
await expect(distribution['findPackageForDownload']('8')).rejects.toThrow(
82106
/Could not find satisfied version for SemVer */

__tests__/distributors/temurin-installer.test.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { HttpClient } from '@actions/http-client';
2-
2+
import os from 'os';
33
import {
44
TemurinDistribution,
55
TemurinImplementation
@@ -109,6 +109,35 @@ describe('getAvailableVersions', () => {
109109
expect(distribution.toolcacheFolderName).toBe(expected);
110110
}
111111
);
112+
113+
it.each([
114+
['amd64', 'x64'],
115+
['arm64', 'aarch64']
116+
])(
117+
'defaults to os.arch(): %s mapped to distro arch: %s',
118+
async (osArch: string, distroArch: string) => {
119+
jest.spyOn(os, 'arch').mockReturnValue(distroArch);
120+
121+
const installerOptions: JavaInstallerOptions = {
122+
version: '17',
123+
architecture: '',
124+
packageType: 'jdk',
125+
checkLatest: false
126+
};
127+
128+
const expectedParameters = `os=mac&architecture=${distroArch}&image_type=jdk&release_type=ga&jvm_impl=hotspot&page_size=20&page=0`;
129+
130+
const distribution = new TemurinDistribution(installerOptions, TemurinImplementation.Hotspot);
131+
const baseUrl = 'https://api.adoptium.net/v3/assets/version/%5B1.0,100.0%5D';
132+
const expectedUrl = `${baseUrl}?project=jdk&vendor=adoptium&heap_size=normal&sort_method=DEFAULT&sort_order=DESC&${expectedParameters}`;
133+
distribution['getPlatformOption'] = () => 'mac';
134+
135+
await distribution['getAvailableVersions']();
136+
137+
expect(spyHttpClient.mock.calls).toHaveLength(1);
138+
expect(spyHttpClient.mock.calls[0][0]).toBe(expectedUrl);
139+
}
140+
);
112141
});
113142

114143
describe('findPackageForDownload', () => {

__tests__/distributors/zulu-installer.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as semver from 'semver';
33
import { ZuluDistribution } from '../../src/distributions/zulu/installer';
44
import { IZuluVersions } from '../../src/distributions/zulu/models';
55
import * as utils from '../../src/util';
6+
import os from 'os';
67

78
const manifestData = require('../data/zulu-releases-default.json') as [];
89

@@ -72,6 +73,34 @@ describe('getAvailableVersions', () => {
7273
expect(spyHttpClient.mock.calls[0][0]).toBe(buildUrl);
7374
});
7475

76+
type DistroArch = {
77+
bitness: string;
78+
arch: string;
79+
};
80+
it.each([
81+
['amd64', { bitness: '64', arch: 'x86' }],
82+
['arm64', { bitness: '64', arch: 'arm' }]
83+
])(
84+
'defaults to os.arch(): %s mapped to distro arch: %s',
85+
async (osArch: string, distroArch: DistroArch) => {
86+
jest.spyOn(os, 'arch').mockReturnValue(osArch);
87+
88+
const distribution = new ZuluDistribution({
89+
version: '17',
90+
architecture: '', // to get default value
91+
packageType: 'jdk',
92+
checkLatest: false
93+
});
94+
distribution['getPlatformOption'] = () => 'macos';
95+
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`;
96+
97+
await distribution['getAvailableVersions']();
98+
99+
expect(spyHttpClient.mock.calls).toHaveLength(1);
100+
expect(spyHttpClient.mock.calls[0][0]).toBe(buildUrl);
101+
}
102+
);
103+
75104
it('load available versions', async () => {
76105
const distribution = new ZuluDistribution({
77106
version: '11',

action.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ inputs:
1414
required: false
1515
default: 'jdk'
1616
architecture:
17-
description: 'The architecture of the package'
17+
description: "The architecture of the package (defaults to the action runner's architecture)"
1818
required: false
19-
default: 'x64'
2019
jdkFile:
2120
description: 'Path to where the compressed JDK is located'
2221
required: false

0 commit comments

Comments
 (0)