This commit is contained in:
mahabaleshwars 2025-06-24 17:24:40 +00:00 committed by GitHub
commit 20a5494b86
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 159 additions and 170 deletions

View file

@ -2,9 +2,9 @@ import {GraalVMDistribution} from '../../src/distributions/graalvm/installer';
import os from 'os'; import os from 'os';
import * as core from '@actions/core'; import * as core from '@actions/core';
import {getDownloadArchiveExtension} from '../../src/util'; import {getDownloadArchiveExtension} from '../../src/util';
import {HttpClient} from '@actions/http-client'; import {HttpClient, HttpClientResponse} from '@actions/http-client';
describe('findPackageForDownload', () => { describe('GraalVMDistribution', () => {
let distribution: GraalVMDistribution; let distribution: GraalVMDistribution;
let spyDebug: jest.SpyInstance; let spyDebug: jest.SpyInstance;
let spyHttpClient: jest.SpyInstance; let spyHttpClient: jest.SpyInstance;
@ -17,11 +17,21 @@ describe('findPackageForDownload', () => {
checkLatest: false checkLatest: false
}); });
spyDebug = jest.spyOn(core, 'debug'); spyDebug = jest.spyOn(core, 'debug').mockImplementation(() => {});
spyDebug.mockImplementation(() => {});
}); });
it.each([ afterEach(() => {
jest.restoreAllMocks();
});
const setupHttpClientSpy = () => {
spyHttpClient = jest.spyOn(HttpClient.prototype, 'head').mockResolvedValue({
message: {statusCode: 200} as any, // Minimal mock for IncomingMessage
readBody: jest.fn().mockResolvedValue('')
} as HttpClientResponse);
};
const testCases = [
[ [
'21', '21',
'21', '21',
@ -42,49 +52,38 @@ describe('findPackageForDownload', () => {
'17.0.12', '17.0.12',
'https://download.oracle.com/graalvm/17/archive/graalvm-jdk-17.0.12_{{OS_TYPE}}-x64_bin.{{ARCHIVE_TYPE}}' 'https://download.oracle.com/graalvm/17/archive/graalvm-jdk-17.0.12_{{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'); it.each(testCases)(
spyHttpClient.mockReturnValue( 'should find package for version %s',
Promise.resolve({ async (input, expectedVersion, expectedUrl) => {
message: { setupHttpClientSpy();
statusCode: 200
}
})
);
const result = await distribution['findPackageForDownload'](input); const result = await distribution['findPackageForDownload'](input);
jest.restoreAllMocks();
expect(result.version).toBe(expectedVersion);
const osType = distribution.getPlatform(); const osType = distribution.getPlatform();
const archiveType = getDownloadArchiveExtension(); const archiveType = getDownloadArchiveExtension();
const url = expectedUrl const expectedFormattedUrl = expectedUrl
.replace('{{OS_TYPE}}', osType) .replace('{{OS_TYPE}}', osType)
.replace('{{ARCHIVE_TYPE}}', archiveType); .replace('{{ARCHIVE_TYPE}}', archiveType);
expect(result.url).toBe(url);
}); expect(result.version).toBe(expectedVersion);
expect(result.url).toBe(expectedFormattedUrl);
}
);
it.each([ it.each([
[ [
'24-ea', '24-ea',
/^https:\/\/github\.com\/graalvm\/oracle-graalvm-ea-builds\/releases\/download\/jdk-24\.0\.0-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 */ 'should find EA package for version %s',
spyHttpClient = jest.spyOn(HttpClient.prototype, 'head'); async (version, expectedUrlPrefix) => {
spyHttpClient.mockReturnValue( setupHttpClientSpy();
Promise.resolve({
message: {
statusCode: 200
}
})
);
const eaDistro = new GraalVMDistribution({ const eaDistro = new GraalVMDistribution({
version, version,
architecture: '', // to get default value architecture: '',
packageType: 'jdk', packageType: 'jdk',
checkLatest: false checkLatest: false
}); });
@ -92,16 +91,15 @@ describe('findPackageForDownload', () => {
const versionWithoutEA = version.split('-')[0]; const versionWithoutEA = version.split('-')[0];
const result = await eaDistro['findPackageForDownload'](versionWithoutEA); const result = await eaDistro['findPackageForDownload'](versionWithoutEA);
jest.restoreAllMocks();
expect(result.url).toEqual(expect.stringMatching(expectedUrlPrefix)); expect(result.url).toEqual(expect.stringMatching(expectedUrlPrefix));
}); }
);
it.each([ it.each([
['amd64', 'x64'], ['amd64', 'x64'],
['arm64', 'aarch64'] ['arm64', 'aarch64']
])( ])(
'defaults to os.arch(): %s mapped to distro arch: %s', 'should map OS architecture %s to distribution architecture %s',
async (osArch: string, distroArch: string) => { async (osArch: string, distroArch: string) => {
jest.spyOn(os, 'arch').mockReturnValue(osArch); jest.spyOn(os, 'arch').mockReturnValue(osArch);
jest.spyOn(os, 'platform').mockReturnValue('linux'); jest.spyOn(os, 'platform').mockReturnValue('linux');
@ -109,15 +107,16 @@ describe('findPackageForDownload', () => {
const version = '21'; const version = '21';
const distro = new GraalVMDistribution({ const distro = new GraalVMDistribution({
version, version,
architecture: '', // to get default value architecture: '',
packageType: 'jdk', packageType: 'jdk',
checkLatest: false checkLatest: false
}); });
const osType = distribution.getPlatform(); const osType = distribution.getPlatform();
if (osType === 'windows' && distroArch == 'aarch64') { if (osType === 'windows' && distroArch === 'aarch64') {
return; // skip, aarch64 is not available for Windows return; // skip, aarch64 is not available for Windows
} }
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/21/latest/graalvm-jdk-21_${osType}-${distroArch}_bin.${archiveType}`; const expectedUrl = `https://download.oracle.com/graalvm/21/latest/graalvm-jdk-21_${osType}-${distroArch}_bin.${archiveType}`;
@ -126,27 +125,26 @@ describe('findPackageForDownload', () => {
} }
); );
it('should throw an error', async () => { it('should throw an error for unsupported versions', async () => {
await expect(distribution['findPackageForDownload']('8')).rejects.toThrow( setupHttpClientSpy();
/GraalVM is only supported for JDK 17 and later/
); const unsupportedVersions = ['8', '11'];
await expect(distribution['findPackageForDownload']('11')).rejects.toThrow( for (const version of unsupportedVersions) {
/GraalVM is only supported for JDK 17 and later/ await expect(
); distribution['findPackageForDownload'](version)
await expect(distribution['findPackageForDownload']('18')).rejects.toThrow( ).rejects.toThrow(/GraalVM is only supported for JDK 17 and later/);
/Could not find GraalVM for SemVer */ }
);
const unavailableEADistro = new GraalVMDistribution({ const unavailableEADistro = new GraalVMDistribution({
version: '17-ea', version: '17-ea',
architecture: '', // to get default value architecture: '',
packageType: 'jdk', packageType: 'jdk',
checkLatest: false checkLatest: false
}); });
await expect( await expect(
unavailableEADistro['findPackageForDownload']('17') unavailableEADistro['findPackageForDownload']('17')
).rejects.toThrow( ).rejects.toThrow(
/No GraalVM EA build found\. Are you sure java-version: '17-ea' is correct\?/ `No GraalVM EA build found for version '17-ea'. Please check if the version is correct.`
); );
}); });
}); });

View file

@ -93676,9 +93676,9 @@ function convertVersionToSemver(version) {
return mainVersion; return mainVersion;
} }
exports.convertVersionToSemver = convertVersionToSemver; exports.convertVersionToSemver = convertVersionToSemver;
function getGitHubHttpHeaders() { function getGitHubHttpHeaders(token) {
const token = core.getInput('token'); const resolvedToken = token || core.getInput('token');
const auth = !token ? undefined : `token ${token}`; const auth = !resolvedToken ? undefined : `token ${resolvedToken}`;
const headers = { const headers = {
accept: 'application/vnd.github.VERSION.raw' accept: 'application/vnd.github.VERSION.raw'
}; };

76
dist/setup/index.js vendored
View file

@ -129455,8 +129455,8 @@ const tc = __importStar(__nccwpck_require__(27784));
const fs_1 = __importDefault(__nccwpck_require__(57147)); const fs_1 = __importDefault(__nccwpck_require__(57147));
const path_1 = __importDefault(__nccwpck_require__(71017)); const path_1 = __importDefault(__nccwpck_require__(71017));
const base_installer_1 = __nccwpck_require__(59741); const base_installer_1 = __nccwpck_require__(59741);
const util_1 = __nccwpck_require__(92629);
const http_client_1 = __nccwpck_require__(96255); const http_client_1 = __nccwpck_require__(96255);
const util_1 = __nccwpck_require__(92629);
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 IS_WINDOWS = process.platform === 'win32';
const GRAALVM_PLATFORM = IS_WINDOWS ? 'windows' : process.platform; const GRAALVM_PLATFORM = IS_WINDOWS ? 'windows' : process.platform;
@ -129470,12 +129470,11 @@ class GraalVMDistribution extends base_installer_1.JavaBase {
let javaArchivePath = yield tc.downloadTool(javaRelease.url); let javaArchivePath = yield tc.downloadTool(javaRelease.url);
core.info(`Extracting Java archive...`); core.info(`Extracting Java archive...`);
const extension = (0, util_1.getDownloadArchiveExtension)(); const extension = (0, util_1.getDownloadArchiveExtension)();
if (process.platform === 'win32') { if (IS_WINDOWS) {
javaArchivePath = (0, util_1.renameWinArchive)(javaArchivePath); javaArchivePath = (0, util_1.renameWinArchive)(javaArchivePath);
} }
const extractedJavaPath = yield (0, util_1.extractJdkFile)(javaArchivePath, extension); const extractedJavaPath = yield (0, util_1.extractJdkFile)(javaArchivePath, extension);
const archiveName = fs_1.default.readdirSync(extractedJavaPath)[0]; const archivePath = path_1.default.join(extractedJavaPath, fs_1.default.readdirSync(extractedJavaPath)[0]);
const archivePath = path_1.default.join(extractedJavaPath, archiveName);
const version = this.getToolcacheVersionName(javaRelease.version); const version = this.getToolcacheVersionName(javaRelease.version);
const javaPath = yield tc.cacheDir(archivePath, this.toolcacheFolderName, version, this.architecture); const javaPath = yield tc.cacheDir(archivePath, this.toolcacheFolderName, version, this.architecture);
return { version: javaRelease.version, path: javaPath }; return { version: javaRelease.version, path: javaPath };
@ -129484,7 +129483,7 @@ class GraalVMDistribution extends base_installer_1.JavaBase {
findPackageForDownload(range) { findPackageForDownload(range) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const arch = this.distributionArchitecture(); const arch = this.distributionArchitecture();
if (arch !== 'x64' && arch !== 'aarch64') { if (!['x64', 'aarch64'].includes(arch)) {
throw new Error(`Unsupported architecture: ${this.architecture}`); throw new Error(`Unsupported architecture: ${this.architecture}`);
} }
if (!this.stable) { if (!this.stable) {
@ -129495,28 +129494,28 @@ class GraalVMDistribution extends base_installer_1.JavaBase {
} }
const platform = this.getPlatform(); const platform = this.getPlatform();
const extension = (0, util_1.getDownloadArchiveExtension)(); const extension = (0, util_1.getDownloadArchiveExtension)();
let major; const major = range.includes('.') ? range.split('.')[0] : range;
let fileUrl; const fileUrl = this.constructFileUrl(range, major, platform, arch, extension);
if (range.includes('.')) {
major = range.split('.')[0];
fileUrl = `${GRAALVM_DL_BASE}/${major}/archive/graalvm-jdk-${range}_${platform}-${arch}_bin.${extension}`;
}
else {
major = range;
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 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);
this.handleHttpResponse(response, range);
return { url: fileUrl, version: range };
});
}
constructFileUrl(range, major, platform, arch, extension) {
return range.includes('.')
? `${GRAALVM_DL_BASE}/${major}/archive/graalvm-jdk-${range}_${platform}-${arch}_bin.${extension}`
: `${GRAALVM_DL_BASE}/${range}/latest/graalvm-jdk-${range}_${platform}-${arch}_bin.${extension}`;
}
handleHttpResponse(response, range) {
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 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 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 };
});
} }
findEABuildDownloadUrl(javaEaVersion) { findEABuildDownloadUrl(javaEaVersion) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
@ -129538,38 +129537,29 @@ class GraalVMDistribution extends base_installer_1.JavaBase {
} }
fetchEAJson(javaEaVersion) { fetchEAJson(javaEaVersion) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const owner = 'graalvm'; const url = `https://api.github.com/repos/graalvm/oracle-graalvm-ea-builds/contents/versions/${javaEaVersion}.json?ref=main`;
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)(); const headers = (0, util_1.getGitHubHttpHeaders)();
core.debug(`Trying to fetch available version info for GraalVM EA builds from '${url}'`); core.debug(`Trying to fetch available version info for GraalVM EA builds from '${url}'`);
let fetchedJson; const fetchedJson = yield this.http
try { .getJson(url, headers)
fetchedJson = (yield this.http.getJson(url, headers)) .then(res => res.result);
.result; if (!fetchedJson) {
} throw new Error(`No GraalVM EA build found for version '${javaEaVersion}'. Please check if the version is correct.`);
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; return fetchedJson;
}); });
} }
getPlatform(platform = process.platform) { getPlatform(platform = process.platform) {
switch (platform) { const platformMap = {
case 'darwin': darwin: 'macos',
return 'macos'; win32: 'windows',
case 'win32': linux: 'linux'
return 'windows'; };
case 'linux': const result = platformMap[platform];
return 'linux'; if (!result) {
default:
throw new Error(`Platform '${platform}' is not supported. Supported platforms: 'linux', 'macos', 'windows'`); throw new Error(`Platform '${platform}' is not supported. Supported platforms: 'linux', 'macos', 'windows'`);
} }
return result;
} }
} }
exports.GraalVMDistribution = GraalVMDistribution; exports.GraalVMDistribution = GraalVMDistribution;
@ -131704,9 +131694,9 @@ function convertVersionToSemver(version) {
return mainVersion; return mainVersion;
} }
exports.convertVersionToSemver = convertVersionToSemver; exports.convertVersionToSemver = convertVersionToSemver;
function getGitHubHttpHeaders() { function getGitHubHttpHeaders(token) {
const token = core.getInput('token'); const resolvedToken = token || core.getInput('token');
const auth = !token ? undefined : `token ${token}`; const auth = !resolvedToken ? undefined : `token ${resolvedToken}`;
const headers = { const headers = {
accept: 'application/vnd.github.VERSION.raw' accept: 'application/vnd.github.VERSION.raw'
}; };

View file

@ -1,10 +1,10 @@
import * as core from '@actions/core'; import * as core from '@actions/core';
import * as tc from '@actions/tool-cache'; import * as tc from '@actions/tool-cache';
import fs from 'fs'; import fs from 'fs';
import path from 'path'; import path from 'path';
import {JavaBase} from '../base-installer'; import {JavaBase} from '../base-installer';
import {HttpCodes} from '@actions/http-client';
import {GraalVMEAVersion} from './models';
import { import {
JavaDownloadRelease, JavaDownloadRelease,
JavaInstallerOptions, JavaInstallerOptions,
@ -16,8 +16,6 @@ import {
getGitHubHttpHeaders, getGitHubHttpHeaders,
renameWinArchive renameWinArchive
} from '../../util'; } from '../../util';
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 IS_WINDOWS = process.platform === 'win32';
@ -38,13 +36,14 @@ export class GraalVMDistribution extends JavaBase {
core.info(`Extracting Java archive...`); core.info(`Extracting Java archive...`);
const extension = getDownloadArchiveExtension(); const extension = getDownloadArchiveExtension();
if (process.platform === 'win32') { if (IS_WINDOWS) {
javaArchivePath = renameWinArchive(javaArchivePath); javaArchivePath = renameWinArchive(javaArchivePath);
} }
const extractedJavaPath = await extractJdkFile(javaArchivePath, extension); const extractedJavaPath = await extractJdkFile(javaArchivePath, extension);
const archivePath = path.join(
const archiveName = fs.readdirSync(extractedJavaPath)[0]; extractedJavaPath,
const archivePath = path.join(extractedJavaPath, archiveName); fs.readdirSync(extractedJavaPath)[0]
);
const version = this.getToolcacheVersionName(javaRelease.version); const version = this.getToolcacheVersionName(javaRelease.version);
const javaPath = await tc.cacheDir( const javaPath = await tc.cacheDir(
@ -53,7 +52,6 @@ export class GraalVMDistribution extends JavaBase {
version, version,
this.architecture this.architecture
); );
return {version: javaRelease.version, path: javaPath}; return {version: javaRelease.version, path: javaPath};
} }
@ -61,7 +59,7 @@ export class GraalVMDistribution extends JavaBase {
range: string range: string
): Promise<JavaDownloadRelease> { ): Promise<JavaDownloadRelease> {
const arch = this.distributionArchitecture(); const arch = this.distributionArchitecture();
if (arch !== 'x64' && arch !== 'aarch64') { if (!['x64', 'aarch64'].includes(arch)) {
throw new Error(`Unsupported architecture: ${this.architecture}`); throw new Error(`Unsupported architecture: ${this.architecture}`);
} }
@ -75,33 +73,46 @@ export class GraalVMDistribution extends JavaBase {
const platform = this.getPlatform(); const platform = this.getPlatform();
const extension = getDownloadArchiveExtension(); const extension = getDownloadArchiveExtension();
let major; const major = range.includes('.') ? range.split('.')[0] : range;
let fileUrl; const fileUrl = this.constructFileUrl(
if (range.includes('.')) { range,
major = range.split('.')[0]; major,
fileUrl = `${GRAALVM_DL_BASE}/${major}/archive/graalvm-jdk-${range}_${platform}-${arch}_bin.${extension}`; platform,
} else { arch,
major = range; 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 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);
this.handleHttpResponse(response, range);
return {url: fileUrl, version: range};
}
private constructFileUrl(
range: string,
major: string,
platform: string,
arch: string,
extension: string
): string {
return range.includes('.')
? `${GRAALVM_DL_BASE}/${major}/archive/graalvm-jdk-${range}_${platform}-${arch}_bin.${extension}`
: `${GRAALVM_DL_BASE}/${range}/latest/graalvm-jdk-${range}_${platform}-${arch}_bin.${extension}`;
}
private handleHttpResponse(response: any, range: string): void {
if (response.message.statusCode === HttpCodes.NotFound) { if (response.message.statusCode === HttpCodes.NotFound) {
throw new Error(`Could not find GraalVM 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 failed with status code: ${response.message.statusCode}` `Http request for GraalVM failed with status code: ${response.message.statusCode}`
); );
} }
return {url: fileUrl, version: range};
} }
private async findEABuildDownloadUrl( private async findEABuildDownloadUrl(
@ -112,6 +123,7 @@ export class GraalVMDistribution extends JavaBase {
if (!latestVersion) { if (!latestVersion) {
throw new Error(`Unable to find latest version for '${javaEaVersion}'`); throw new Error(`Unable to find latest version for '${javaEaVersion}'`);
} }
const arch = this.distributionArchitecture(); const arch = this.distributionArchitecture();
const file = latestVersion.files.find( const file = latestVersion.files.find(
f => f.arch === arch && f.platform === GRAALVM_PLATFORM f => f.arch === arch && f.platform === GRAALVM_PLATFORM
@ -119,6 +131,7 @@ export class GraalVMDistribution extends JavaBase {
if (!file || !file.filename.startsWith('graalvm-jdk-')) { if (!file || !file.filename.startsWith('graalvm-jdk-')) {
throw new Error(`Unable to find file metadata for '${javaEaVersion}'`); throw new Error(`Unable to find file metadata for '${javaEaVersion}'`);
} }
return { return {
url: `${latestVersion.download_base_url}${file.filename}`, url: `${latestVersion.download_base_url}${file.filename}`,
version: latestVersion.version version: latestVersion.version
@ -128,49 +141,37 @@ export class GraalVMDistribution extends JavaBase {
private async fetchEAJson( private async fetchEAJson(
javaEaVersion: string javaEaVersion: string
): Promise<GraalVMEAVersion[]> { ): Promise<GraalVMEAVersion[]> {
const owner = 'graalvm'; const url = `https://api.github.com/repos/graalvm/oracle-graalvm-ea-builds/contents/versions/${javaEaVersion}.json?ref=main`;
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(); const headers = getGitHubHttpHeaders();
core.debug( core.debug(
`Trying to fetch available version info for GraalVM EA builds from '${url}'` `Trying to fetch available version info for GraalVM EA builds from '${url}'`
); );
let fetchedJson; const fetchedJson = await this.http
try { .getJson<GraalVMEAVersion[]>(url, headers)
fetchedJson = (await this.http.getJson<GraalVMEAVersion[]>(url, headers)) .then(res => res.result);
.result;
} catch (err) { if (!fetchedJson) {
throw Error( throw new Error(
`Fetching version info for GraalVM EA builds from '${url}' failed with the error: ${ `No GraalVM EA build found for version '${javaEaVersion}'. Please check if the version is correct.`
(err as Error).message
}`
);
}
if (fetchedJson === null) {
throw Error(
`No GraalVM EA build found. Are you sure java-version: '${javaEaVersion}' is correct?`
); );
} }
return fetchedJson; return fetchedJson;
} }
public getPlatform(platform: NodeJS.Platform = process.platform): OsVersions { public getPlatform(platform: NodeJS.Platform = process.platform): OsVersions {
switch (platform) { const platformMap: Record<string, OsVersions> = {
case 'darwin': darwin: 'macos',
return 'macos'; win32: 'windows',
case 'win32': linux: 'linux'
return 'windows'; };
case 'linux':
return 'linux'; const result = platformMap[platform];
default: if (!result) {
throw new Error( throw new Error(
`Platform '${platform}' is not supported. Supported platforms: 'linux', 'macos', 'windows'` `Platform '${platform}' is not supported. Supported platforms: 'linux', 'macos', 'windows'`
); );
} }
return result;
} }
} }

View file

@ -183,9 +183,9 @@ export function convertVersionToSemver(version: number[] | string) {
return mainVersion; return mainVersion;
} }
export function getGitHubHttpHeaders(): OutgoingHttpHeaders { export function getGitHubHttpHeaders(token?: string): OutgoingHttpHeaders {
const token = core.getInput('token'); const resolvedToken = token || core.getInput('token');
const auth = !token ? undefined : `token ${token}`; const auth = !resolvedToken ? undefined : `token ${resolvedToken}`;
const headers: OutgoingHttpHeaders = { const headers: OutgoingHttpHeaders = {
accept: 'application/vnd.github.VERSION.raw' accept: 'application/vnd.github.VERSION.raw'