mirror of
https://github.com/actions/setup-java.git
synced 2024-11-13 21:48:05 +00:00
Add support for EA builds of Oracle GraalVM
This commit is contained in:
parent
bbbb45e1c5
commit
f0a7c591b0
3
.github/workflows/e2e-versions.yml
vendored
3
.github/workflows/e2e-versions.yml
vendored
@ -58,6 +58,9 @@ jobs:
|
|||||||
- distribution: graalvm
|
- distribution: graalvm
|
||||||
os: ubuntu-latest
|
os: ubuntu-latest
|
||||||
version: 21
|
version: 21
|
||||||
|
- distribution: graalvm
|
||||||
|
os: ubuntu-latest
|
||||||
|
version: '24-ea'
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
@ -66,6 +66,37 @@ describe('findPackageForDownload', () => {
|
|||||||
expect(result.url).toBe(url);
|
expect(result.url).toBe(url);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it.each([
|
||||||
|
[
|
||||||
|
'24-ea',
|
||||||
|
/^https:\/\/github\.com\/graalvm\/oracle-graalvm-ea-builds\/releases\/download\/jdk-24\.0\.0-ea\./
|
||||||
|
]
|
||||||
|
])('version is %s -> %s', async (version, expectedUrlPrefix) => {
|
||||||
|
/* 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 eaDistro = new GraalVMDistribution({
|
||||||
|
version,
|
||||||
|
architecture: '', // to get default value
|
||||||
|
packageType: 'jdk',
|
||||||
|
checkLatest: false
|
||||||
|
});
|
||||||
|
|
||||||
|
const versionWithoutEA = version.split('-')[0];
|
||||||
|
const result = await eaDistro['findPackageForDownload'](versionWithoutEA);
|
||||||
|
|
||||||
|
jest.restoreAllMocks();
|
||||||
|
|
||||||
|
expect(result.url).toEqual(expect.stringMatching(expectedUrlPrefix));
|
||||||
|
});
|
||||||
|
|
||||||
it.each([
|
it.each([
|
||||||
['amd64', 'x64'],
|
['amd64', 'x64'],
|
||||||
['arm64', 'aarch64']
|
['arm64', 'aarch64']
|
||||||
@ -75,7 +106,7 @@ describe('findPackageForDownload', () => {
|
|||||||
jest.spyOn(os, 'arch').mockReturnValue(osArch);
|
jest.spyOn(os, 'arch').mockReturnValue(osArch);
|
||||||
jest.spyOn(os, 'platform').mockReturnValue('linux');
|
jest.spyOn(os, 'platform').mockReturnValue('linux');
|
||||||
|
|
||||||
const version = '17';
|
const version = '21';
|
||||||
const distro = new GraalVMDistribution({
|
const distro = new GraalVMDistribution({
|
||||||
version,
|
version,
|
||||||
architecture: '', // to get default value
|
architecture: '', // to get default value
|
||||||
@ -89,7 +120,7 @@ describe('findPackageForDownload', () => {
|
|||||||
}
|
}
|
||||||
const archiveType = getDownloadArchiveExtension();
|
const archiveType = getDownloadArchiveExtension();
|
||||||
const result = await distro['findPackageForDownload'](version);
|
const result = await distro['findPackageForDownload'](version);
|
||||||
const expectedUrl = `https://download.oracle.com/graalvm/17/latest/graalvm-jdk-17_${osType}-${distroArch}_bin.${archiveType}`;
|
const expectedUrl = `https://download.oracle.com/graalvm/21/latest/graalvm-jdk-21_${osType}-${distroArch}_bin.${archiveType}`;
|
||||||
|
|
||||||
expect(result.url).toBe(expectedUrl);
|
expect(result.url).toBe(expectedUrl);
|
||||||
}
|
}
|
||||||
@ -97,13 +128,25 @@ describe('findPackageForDownload', () => {
|
|||||||
|
|
||||||
it('should throw an error', async () => {
|
it('should throw an error', async () => {
|
||||||
await expect(distribution['findPackageForDownload']('8')).rejects.toThrow(
|
await expect(distribution['findPackageForDownload']('8')).rejects.toThrow(
|
||||||
/GraalVM JDK is only supported for JDK 17 and later/
|
/GraalVM is only supported for JDK 17 and later/
|
||||||
);
|
);
|
||||||
await expect(distribution['findPackageForDownload']('11')).rejects.toThrow(
|
await expect(distribution['findPackageForDownload']('11')).rejects.toThrow(
|
||||||
/GraalVM JDK is only supported for JDK 17 and later/
|
/GraalVM is only supported for JDK 17 and later/
|
||||||
);
|
);
|
||||||
await expect(distribution['findPackageForDownload']('18')).rejects.toThrow(
|
await expect(distribution['findPackageForDownload']('18')).rejects.toThrow(
|
||||||
/Could not find GraalVM JDK for SemVer */
|
/Could not find GraalVM for SemVer */
|
||||||
|
);
|
||||||
|
|
||||||
|
const unavailableEADistro = new GraalVMDistribution({
|
||||||
|
version: '17-ea',
|
||||||
|
architecture: '', // to get default value
|
||||||
|
packageType: 'jdk',
|
||||||
|
checkLatest: false
|
||||||
|
});
|
||||||
|
await expect(
|
||||||
|
unavailableEADistro['findPackageForDownload']('17')
|
||||||
|
).rejects.toThrow(
|
||||||
|
/No GraalVM EA build found\. Are you sure java-version: '17-ea' is correct\?/
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
53
dist/setup/index.js
vendored
53
dist/setup/index.js
vendored
@ -124366,6 +124366,8 @@ const base_installer_1 = __nccwpck_require__(59741);
|
|||||||
const util_1 = __nccwpck_require__(92629);
|
const util_1 = __nccwpck_require__(92629);
|
||||||
const http_client_1 = __nccwpck_require__(96255);
|
const http_client_1 = __nccwpck_require__(96255);
|
||||||
const GRAALVM_DL_BASE = 'https://download.oracle.com/graalvm';
|
const GRAALVM_DL_BASE = 'https://download.oracle.com/graalvm';
|
||||||
|
const IS_WINDOWS = process.platform === 'win32';
|
||||||
|
const GRAALVM_PLATFORM = IS_WINDOWS ? 'windows' : process.platform;
|
||||||
class GraalVMDistribution extends base_installer_1.JavaBase {
|
class GraalVMDistribution extends base_installer_1.JavaBase {
|
||||||
constructor(installerOptions) {
|
constructor(installerOptions) {
|
||||||
super('GraalVM', installerOptions);
|
super('GraalVM', installerOptions);
|
||||||
@ -124391,10 +124393,10 @@ class GraalVMDistribution extends base_installer_1.JavaBase {
|
|||||||
throw new Error(`Unsupported architecture: ${this.architecture}`);
|
throw new Error(`Unsupported architecture: ${this.architecture}`);
|
||||||
}
|
}
|
||||||
if (!this.stable) {
|
if (!this.stable) {
|
||||||
throw new Error('Early access versions are not supported');
|
return this.findEABuildDownloadUrl(`${range}-ea`);
|
||||||
}
|
}
|
||||||
if (this.packageType !== 'jdk') {
|
if (this.packageType !== 'jdk') {
|
||||||
throw new Error('GraalVM JDK provides only the `jdk` package type');
|
throw new Error('GraalVM provides only the `jdk` package type');
|
||||||
}
|
}
|
||||||
const platform = this.getPlatform();
|
const platform = this.getPlatform();
|
||||||
const extension = (0, util_1.getDownloadArchiveExtension)();
|
const extension = (0, util_1.getDownloadArchiveExtension)();
|
||||||
@ -124409,18 +124411,59 @@ class GraalVMDistribution extends base_installer_1.JavaBase {
|
|||||||
fileUrl = `${GRAALVM_DL_BASE}/${range}/latest/graalvm-jdk-${range}_${platform}-${arch}_bin.${extension}`;
|
fileUrl = `${GRAALVM_DL_BASE}/${range}/latest/graalvm-jdk-${range}_${platform}-${arch}_bin.${extension}`;
|
||||||
}
|
}
|
||||||
if (parseInt(major) < 17) {
|
if (parseInt(major) < 17) {
|
||||||
throw new Error('GraalVM JDK is only supported for JDK 17 and later');
|
throw new Error('GraalVM is only supported for JDK 17 and later');
|
||||||
}
|
}
|
||||||
const response = yield this.http.head(fileUrl);
|
const response = yield this.http.head(fileUrl);
|
||||||
if (response.message.statusCode === http_client_1.HttpCodes.NotFound) {
|
if (response.message.statusCode === http_client_1.HttpCodes.NotFound) {
|
||||||
throw new Error(`Could not find GraalVM JDK for SemVer ${range}`);
|
throw new Error(`Could not find GraalVM for SemVer ${range}`);
|
||||||
}
|
}
|
||||||
if (response.message.statusCode !== http_client_1.HttpCodes.OK) {
|
if (response.message.statusCode !== http_client_1.HttpCodes.OK) {
|
||||||
throw new Error(`Http request for GraalVM JDK failed with status code: ${response.message.statusCode}`);
|
throw new Error(`Http request for GraalVM failed with status code: ${response.message.statusCode}`);
|
||||||
}
|
}
|
||||||
return { url: fileUrl, version: range };
|
return { url: fileUrl, version: range };
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
findEABuildDownloadUrl(javaEaVersion) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
const versions = yield this.fetchEAJson(javaEaVersion);
|
||||||
|
const latestVersion = versions.find(v => v.latest);
|
||||||
|
if (!latestVersion) {
|
||||||
|
throw new Error(`Unable to find latest version for '${javaEaVersion}'`);
|
||||||
|
}
|
||||||
|
const arch = this.distributionArchitecture();
|
||||||
|
const file = latestVersion.files.find(f => f.arch === arch && f.platform === GRAALVM_PLATFORM);
|
||||||
|
if (!file || !file.filename.startsWith('graalvm-jdk-')) {
|
||||||
|
throw new Error(`Unable to find file metadata for '${javaEaVersion}'`);
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
url: `${latestVersion.download_base_url}${file.filename}`,
|
||||||
|
version: latestVersion.version
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
fetchEAJson(javaEaVersion) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
const owner = 'graalvm';
|
||||||
|
const repository = 'oracle-graalvm-ea-builds';
|
||||||
|
const branch = 'main';
|
||||||
|
const filePath = `versions/${javaEaVersion}.json`;
|
||||||
|
const url = `https://api.github.com/repos/${owner}/${repository}/contents/${filePath}?ref=${branch}`;
|
||||||
|
const headers = (0, util_1.getGitHubHttpHeaders)();
|
||||||
|
core.debug(`Trying to fetch available version info for GraalVM EA builds from '${url}'`);
|
||||||
|
let fetchedJson;
|
||||||
|
try {
|
||||||
|
fetchedJson = (yield this.http.getJson(url, headers))
|
||||||
|
.result;
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
throw Error(`Fetching version info for GraalVM EA builds from '${url}' failed with the error: ${err.message}`);
|
||||||
|
}
|
||||||
|
if (fetchedJson === null) {
|
||||||
|
throw Error(`No GraalVM EA build found. Are you sure java-version: '${javaEaVersion}' is correct?`);
|
||||||
|
}
|
||||||
|
return fetchedJson;
|
||||||
|
});
|
||||||
|
}
|
||||||
getPlatform(platform = process.platform) {
|
getPlatform(platform = process.platform) {
|
||||||
switch (platform) {
|
switch (platform) {
|
||||||
case 'darwin':
|
case 'darwin':
|
||||||
|
@ -10,10 +10,17 @@ import {
|
|||||||
JavaInstallerOptions,
|
JavaInstallerOptions,
|
||||||
JavaInstallerResults
|
JavaInstallerResults
|
||||||
} from '../base-models';
|
} from '../base-models';
|
||||||
import {extractJdkFile, getDownloadArchiveExtension} from '../../util';
|
import {
|
||||||
|
extractJdkFile,
|
||||||
|
getDownloadArchiveExtension,
|
||||||
|
getGitHubHttpHeaders
|
||||||
|
} from '../../util';
|
||||||
import {HttpCodes} from '@actions/http-client';
|
import {HttpCodes} from '@actions/http-client';
|
||||||
|
import {GraalVMEAVersion} from './models';
|
||||||
|
|
||||||
const GRAALVM_DL_BASE = 'https://download.oracle.com/graalvm';
|
const GRAALVM_DL_BASE = 'https://download.oracle.com/graalvm';
|
||||||
|
const IS_WINDOWS = process.platform === 'win32';
|
||||||
|
const GRAALVM_PLATFORM = IS_WINDOWS ? 'windows' : process.platform;
|
||||||
|
|
||||||
export class GraalVMDistribution extends JavaBase {
|
export class GraalVMDistribution extends JavaBase {
|
||||||
constructor(installerOptions: JavaInstallerOptions) {
|
constructor(installerOptions: JavaInstallerOptions) {
|
||||||
@ -56,11 +63,11 @@ export class GraalVMDistribution extends JavaBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!this.stable) {
|
if (!this.stable) {
|
||||||
throw new Error('Early access versions are not supported');
|
return this.findEABuildDownloadUrl(`${range}-ea`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.packageType !== 'jdk') {
|
if (this.packageType !== 'jdk') {
|
||||||
throw new Error('GraalVM JDK provides only the `jdk` package type');
|
throw new Error('GraalVM provides only the `jdk` package type');
|
||||||
}
|
}
|
||||||
|
|
||||||
const platform = this.getPlatform();
|
const platform = this.getPlatform();
|
||||||
@ -76,24 +83,79 @@ export class GraalVMDistribution extends JavaBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (parseInt(major) < 17) {
|
if (parseInt(major) < 17) {
|
||||||
throw new Error('GraalVM JDK is only supported for JDK 17 and later');
|
throw new Error('GraalVM is only supported for JDK 17 and later');
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await this.http.head(fileUrl);
|
const response = await this.http.head(fileUrl);
|
||||||
|
|
||||||
if (response.message.statusCode === HttpCodes.NotFound) {
|
if (response.message.statusCode === HttpCodes.NotFound) {
|
||||||
throw new Error(`Could not find GraalVM JDK for SemVer ${range}`);
|
throw new Error(`Could not find GraalVM for SemVer ${range}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.message.statusCode !== HttpCodes.OK) {
|
if (response.message.statusCode !== HttpCodes.OK) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Http request for GraalVM JDK failed with status code: ${response.message.statusCode}`
|
`Http request for GraalVM failed with status code: ${response.message.statusCode}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {url: fileUrl, version: range};
|
return {url: fileUrl, version: range};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async findEABuildDownloadUrl(
|
||||||
|
javaEaVersion: string
|
||||||
|
): Promise<JavaDownloadRelease> {
|
||||||
|
const versions = await this.fetchEAJson(javaEaVersion);
|
||||||
|
const latestVersion = versions.find(v => v.latest);
|
||||||
|
if (!latestVersion) {
|
||||||
|
throw new Error(`Unable to find latest version for '${javaEaVersion}'`);
|
||||||
|
}
|
||||||
|
const arch = this.distributionArchitecture();
|
||||||
|
const file = latestVersion.files.find(
|
||||||
|
f => f.arch === arch && f.platform === GRAALVM_PLATFORM
|
||||||
|
);
|
||||||
|
if (!file || !file.filename.startsWith('graalvm-jdk-')) {
|
||||||
|
throw new Error(`Unable to find file metadata for '${javaEaVersion}'`);
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
url: `${latestVersion.download_base_url}${file.filename}`,
|
||||||
|
version: latestVersion.version
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private async fetchEAJson(
|
||||||
|
javaEaVersion: string
|
||||||
|
): Promise<GraalVMEAVersion[]> {
|
||||||
|
const owner = 'graalvm';
|
||||||
|
const repository = 'oracle-graalvm-ea-builds';
|
||||||
|
const branch = 'main';
|
||||||
|
const filePath = `versions/${javaEaVersion}.json`;
|
||||||
|
|
||||||
|
const url = `https://api.github.com/repos/${owner}/${repository}/contents/${filePath}?ref=${branch}`;
|
||||||
|
|
||||||
|
const headers = getGitHubHttpHeaders();
|
||||||
|
|
||||||
|
core.debug(
|
||||||
|
`Trying to fetch available version info for GraalVM EA builds from '${url}'`
|
||||||
|
);
|
||||||
|
let fetchedJson;
|
||||||
|
try {
|
||||||
|
fetchedJson = (await this.http.getJson<GraalVMEAVersion[]>(url, headers))
|
||||||
|
.result;
|
||||||
|
} catch (err) {
|
||||||
|
throw Error(
|
||||||
|
`Fetching version info for GraalVM EA builds from '${url}' failed with the error: ${
|
||||||
|
(err as Error).message
|
||||||
|
}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (fetchedJson === null) {
|
||||||
|
throw Error(
|
||||||
|
`No GraalVM EA build found. Are you sure java-version: '${javaEaVersion}' is correct?`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return fetchedJson;
|
||||||
|
}
|
||||||
|
|
||||||
public getPlatform(platform: NodeJS.Platform = process.platform): OsVersions {
|
public getPlatform(platform: NodeJS.Platform = process.platform): OsVersions {
|
||||||
switch (platform) {
|
switch (platform) {
|
||||||
case 'darwin':
|
case 'darwin':
|
||||||
|
@ -1 +1,14 @@
|
|||||||
export type OsVersions = 'linux' | 'macos' | 'windows';
|
export type OsVersions = 'linux' | 'macos' | 'windows';
|
||||||
|
|
||||||
|
export interface GraalVMEAFile {
|
||||||
|
filename: string;
|
||||||
|
arch: 'aarch64' | 'x64';
|
||||||
|
platform: 'darwin' | 'linux' | 'windows';
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GraalVMEAVersion {
|
||||||
|
version: string;
|
||||||
|
latest?: boolean;
|
||||||
|
download_base_url: string;
|
||||||
|
files: GraalVMEAFile[];
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user