Skip to content

Commit

Permalink
Add support for Oracle GraalVM JDK
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed Jun 20, 2023
1 parent 45058d7 commit 8f50776
Show file tree
Hide file tree
Showing 8 changed files with 6,458 additions and 2,651 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/e2e-versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ jobs:
- distribution: oracle
os: ubuntu-latest
version: 20
- distribution: graalvm
os: macos-latest
version: 17
- distribution: graalvm
os: windows-latest
version: 20
- distribution: graalvm
os: ubuntu-latest
version: 20
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down Expand Up @@ -75,6 +84,9 @@ jobs:
- distribution: oracle
os: ubuntu-latest
version: '20.0.1'
- distribution: graalvm
os: ubuntu-latest
version: '20.0.1'
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ Currently, the following distributions are supported:
| `corretto` | Amazon Corretto Build of OpenJDK | [Link](https://aws.amazon.com/corretto/) | [Link](https://aws.amazon.com/corretto/faqs/)
| `semeru` | IBM Semeru Runtime Open Edition | [Link](https://developer.ibm.com/languages/java/semeru-runtimes/downloads/) | [Link](https://openjdk.java.net/legal/gplv2+ce.html) |
| `oracle` | Oracle JDK | [Link](https://www.oracle.com/java/technologies/downloads/) | [Link](https://java.com/freeuselicense)
| `graalvm` | Oracle GraalVM | [Link](https://www.graalvm.org/) | [Link](https://www.oracle.com/downloads/licenses/graal-free-license.html)

**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.

Expand Down
109 changes: 109 additions & 0 deletions __tests__/distributors/graalvm-installer.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import {GraalVMDistribution} from '../../src/distributions/graalvm/installer';
import os from 'os';
import * as core from '@actions/core';
import {getDownloadArchiveExtension} from '../../src/util';
import {HttpClient} from '@actions/http-client';

describe('findPackageForDownload', () => {
let distribution: GraalVMDistribution;
let spyDebug: jest.SpyInstance;
let spyHttpClient: jest.SpyInstance;

beforeEach(() => {
distribution = new GraalVMDistribution({
version: '',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
});

spyDebug = jest.spyOn(core, 'debug');
spyDebug.mockImplementation(() => {});
});

it.each([
[
'20',
'20',
'https://download.oracle.com/graalvm/20/latest/graalvm-jdk-20_{{OS_TYPE}}-x64_bin.{{ARCHIVE_TYPE}}'
],
[
'20.0.1',
'20.0.1',
'https://download.oracle.com/graalvm/20/archive/graalvm-jdk-20.0.1_{{OS_TYPE}}-x64_bin.{{ARCHIVE_TYPE}}'
],
[
'17',
'17',
'https://download.oracle.com/graalvm/17/latest/graalvm-jdk-17_{{OS_TYPE}}-x64_bin.{{ARCHIVE_TYPE}}'
],
[
'17.0.7',
'17.0.7',
'https://download.oracle.com/graalvm/17/archive/graalvm-jdk-17.0.7_{{OS_TYPE}}-x64_bin.{{ARCHIVE_TYPE}}'
]
])('version is %s -> %s', async (input, expectedVersion, expectedUrl) => {
/* Needed only for this particular test because /latest/ urls tend to change */
spyHttpClient = jest.spyOn(HttpClient.prototype, 'head');
spyHttpClient.mockReturnValue(
Promise.resolve({
message: {
statusCode: 200
}
})
);

const result = await distribution['findPackageForDownload'](input);

jest.restoreAllMocks();

expect(result.version).toBe(expectedVersion);
const osType = distribution.getPlatform();
const archiveType = getDownloadArchiveExtension();
const url = expectedUrl
.replace('{{OS_TYPE}}', osType)
.replace('{{ARCHIVE_TYPE}}', archiveType);
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);
jest.spyOn(os, 'platform').mockReturnValue('linux');

const version = '17';
const distro = new GraalVMDistribution({
version,
architecture: '', // to get default value
packageType: 'jdk',
checkLatest: false
});

const osType = distribution.getPlatform();
if (osType === 'windows' && distroArch == 'aarch64') {
return; // skip, aarch64 is not available for Windows
}
const archiveType = getDownloadArchiveExtension();
const result = await distro['findPackageForDownload'](version);
const expectedUrl = `https://download.oracle.com/graalvm/17/latest/graalvm-jdk-17_${osType}-${distroArch}_bin.${archiveType}`;

expect(result.url).toBe(expectedUrl);
}
);

it('should throw an error', async () => {
await expect(distribution['findPackageForDownload']('8')).rejects.toThrow(
/GraalVM JDK is only supported for JDK 17 and later/
);
await expect(distribution['findPackageForDownload']('11')).rejects.toThrow(
/GraalVM JDK is only supported for JDK 17 and later/
);
await expect(distribution['findPackageForDownload']('18')).rejects.toThrow(
/Could not find GraalVM JDK for SemVer */
);
});
});
Loading

0 comments on commit 8f50776

Please sign in to comment.