Skip to content

Commit bae3140

Browse files
authored
Add Amazon Corretto distribution (actions#312)
1 parent dd80852 commit bae3140

File tree

9 files changed

+1699
-9
lines changed

9 files changed

+1699
-9
lines changed

.github/workflows/e2e-versions.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
fail-fast: false
2121
matrix:
2222
os: [macos-latest, windows-latest, ubuntu-latest]
23-
distribution: ['temurin', 'adopt', 'adopt-openj9', 'zulu', 'liberica', 'microsoft' ] # internally 'adopt-hotspot' is the same as 'adopt'
23+
distribution: ['temurin', 'adopt', 'adopt-openj9', 'zulu', 'liberica', 'microsoft', 'corretto' ] # internally 'adopt-hotspot' is the same as 'adopt'
2424
version: ['8', '11', '16']
2525
exclude:
2626
- distribution: microsoft
@@ -141,7 +141,7 @@ jobs:
141141
os: [macos-latest, windows-latest, ubuntu-latest]
142142
distribution: ['temurin', 'zulu', 'liberica']
143143
java-package: ['jre']
144-
version: ['16.0']
144+
version: ['17.0']
145145
include:
146146
- distribution: 'zulu'
147147
java-package: jre+fx
@@ -159,10 +159,10 @@ jobs:
159159
java-package: jre+fx
160160
version: '11'
161161
os: ubuntu-latest
162-
exclude:
163-
# Eclipse Temurin currently doesn't publish JREs, only JDKs
164-
- distribution: 'temurin'
165-
java-package: 'jre'
162+
- distribution: 'corretto'
163+
java-package: jre
164+
version: '8'
165+
os: windows-latest
166166
steps:
167167
- name: Checkout
168168
uses: actions/checkout@v3
@@ -187,7 +187,7 @@ jobs:
187187
matrix:
188188
# x86 is not supported on macOS
189189
os: [windows-latest, ubuntu-latest]
190-
distribution: ['liberica', 'zulu']
190+
distribution: ['liberica', 'zulu', 'corretto']
191191
version: ['11']
192192
steps:
193193
- name: Checkout

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ Currently, the following distributions are supported:
6060
| `adopt-openj9` | Adopt OpenJDK OpenJ9 | [Link](https://adoptopenjdk.net/) | [Link](https://adoptopenjdk.net/about.html) |
6161
| `liberica` | Liberica JDK | [Link](https://bell-sw.com/) | [Link](https://bell-sw.com/liberica_eula/) |
6262
| `microsoft` | Microsoft Build of OpenJDK | [Link](https://www.microsoft.com/openjdk) | [Link](https://docs.microsoft.com/java/openjdk/faq)
63+
| `corretto` | Amazon Corretto Build of OpenJDK | [Link](https://aws.amazon.com/corretto/) | [Link](https://aws.amazon.com/corretto/faqs/)
6364

6465
**NOTE:** The different distributors can provide discrepant list of available versions / supported configurations. Please refer to the official documentation to see the list of supported versions.
6566

__tests__/data/corretto.json

Lines changed: 1183 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
import { HttpClient } from '@actions/http-client';
2+
import { JavaInstallerOptions } from '../../src/distributions/base-models';
3+
4+
import { CorrettoDistribution } from '../../src/distributions/corretto/installer';
5+
import * as util from '../../src/util';
6+
7+
const manifestData = require('../data/corretto.json') as [];
8+
9+
describe('getAvailableVersions', () => {
10+
let spyHttpClient: jest.SpyInstance;
11+
let spyGetDownloadArchiveExtension: jest.SpyInstance;
12+
13+
beforeEach(() => {
14+
spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson');
15+
spyHttpClient.mockReturnValue({
16+
statusCode: 200,
17+
headers: {},
18+
result: manifestData
19+
});
20+
spyGetDownloadArchiveExtension = jest.spyOn(util, 'getDownloadArchiveExtension');
21+
});
22+
23+
afterEach(() => {
24+
jest.resetAllMocks();
25+
jest.clearAllMocks();
26+
jest.restoreAllMocks();
27+
});
28+
29+
describe('getAvailableVersions', () => {
30+
it('load available versions', async () => {
31+
const distribution = new CorrettoDistribution({
32+
version: '11',
33+
architecture: 'x64',
34+
packageType: 'jdk',
35+
checkLatest: false
36+
});
37+
mockPlatform(distribution, 'linux');
38+
39+
const availableVersions = await distribution['getAvailableVersions']();
40+
expect(availableVersions).not.toBeNull();
41+
expect(availableVersions.length).toBe(6);
42+
});
43+
44+
it.each([
45+
[{ version: '16', architecture: 'x64', packageType: 'jdk', checkLatest: false }, 'macos', 6],
46+
[{ version: '16', architecture: 'x86', packageType: 'jdk', checkLatest: false }, 'macos', 0],
47+
[{ version: '16', architecture: 'x64', packageType: 'jre', checkLatest: false }, 'macos', 0],
48+
[{ version: '16', architecture: 'x64', packageType: 'jdk', checkLatest: false }, 'linux', 6],
49+
[
50+
{ version: '18', architecture: 'x64', packageType: 'jdk', checkLatest: false },
51+
'windows',
52+
6
53+
],
54+
[{ version: '18', architecture: 'x64', packageType: 'jre', checkLatest: false }, 'windows', 1]
55+
])(
56+
'fetch expected amount of available versions for %s',
57+
async (
58+
installerOptions: JavaInstallerOptions,
59+
platform: string,
60+
expectedAmountOfAvailableVersions
61+
) => {
62+
const distribution = new CorrettoDistribution(installerOptions);
63+
mockPlatform(distribution, platform);
64+
65+
const availableVersions = await distribution['getAvailableVersions']();
66+
expect(availableVersions).not.toBeNull();
67+
expect(availableVersions.length).toBe(expectedAmountOfAvailableVersions);
68+
}
69+
);
70+
});
71+
72+
describe('findPackageForDownload', () => {
73+
it.each([
74+
[
75+
'macos',
76+
'https://corretto.aws/downloads/resources/18.0.0.37.1/amazon-corretto-18.0.0.37.1-macosx-x64.tar.gz'
77+
],
78+
[
79+
'windows',
80+
'https://corretto.aws/downloads/resources/18.0.0.37.1/amazon-corretto-18.0.0.37.1-windows-x64-jdk.zip'
81+
],
82+
[
83+
'linux',
84+
'https://corretto.aws/downloads/resources/18.0.0.37.1/amazon-corretto-18.0.0.37.1-linux-x64.tar.gz'
85+
]
86+
])('for os: %s', async (platform: string, expectedLink: string) => {
87+
const version = '18';
88+
const distribution = new CorrettoDistribution({
89+
version,
90+
architecture: 'x64',
91+
packageType: 'jdk',
92+
checkLatest: false
93+
});
94+
mockPlatform(distribution, platform);
95+
96+
const availableVersion = await distribution['findPackageForDownload'](version);
97+
expect(availableVersion).not.toBeNull();
98+
expect(availableVersion.url).toBe(expectedLink);
99+
});
100+
101+
it('with unstable version expect to throw not supported error', async () => {
102+
const version = '18.0.1-ea';
103+
const distribution = new CorrettoDistribution({
104+
version,
105+
architecture: 'x64',
106+
packageType: 'jdk',
107+
checkLatest: false
108+
});
109+
mockPlatform(distribution, 'linux');
110+
111+
await expect(distribution['findPackageForDownload'](version)).rejects.toThrowError(
112+
'Early access versions are not supported'
113+
);
114+
});
115+
116+
it('with non major version expect to throw not supported error', async () => {
117+
const version = '18.0.1';
118+
const distribution = new CorrettoDistribution({
119+
version,
120+
architecture: 'x64',
121+
packageType: 'jdk',
122+
checkLatest: false
123+
});
124+
mockPlatform(distribution, 'linux');
125+
126+
await expect(distribution['findPackageForDownload'](version)).rejects.toThrowError(
127+
'Only major versions are supported'
128+
);
129+
});
130+
131+
it('with unfound version throw could not find error', async () => {
132+
const version = '4';
133+
const distribution = new CorrettoDistribution({
134+
version,
135+
architecture: 'x64',
136+
packageType: 'jdk',
137+
checkLatest: false
138+
});
139+
mockPlatform(distribution, 'linux');
140+
141+
await expect(distribution['findPackageForDownload'](version)).rejects.toThrowError(
142+
"Could not find satisfied version for SemVer '4'"
143+
);
144+
});
145+
});
146+
147+
const mockPlatform = (distributon: CorrettoDistribution, platform: string) => {
148+
distributon['getPlatformOption'] = () => platform;
149+
const mockedExtension = platform === 'windows' ? 'zip' : 'tar.gz';
150+
spyGetDownloadArchiveExtension.mockReturnValue(mockedExtension);
151+
};
152+
});

0 commit comments

Comments
 (0)