mirror of
https://github.com/actions/setup-java.git
synced 2025-11-26 17:09:09 +08:00
Compare commits
3 Commits
6ba5449b7d
...
dependabot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a2c8d38afa | ||
|
|
46c56d6f92 | ||
|
|
66b945764b |
File diff suppressed because it is too large
Load Diff
4
dist/cleanup/index.js
vendored
4
dist/cleanup/index.js
vendored
@@ -94747,8 +94747,8 @@ function convertVersionToSemver(version) {
|
|||||||
}
|
}
|
||||||
exports.convertVersionToSemver = convertVersionToSemver;
|
exports.convertVersionToSemver = convertVersionToSemver;
|
||||||
function getGitHubHttpHeaders() {
|
function getGitHubHttpHeaders() {
|
||||||
const token = core.getInput('token');
|
const resolvedToken = core.getInput('token') || process.env.GITHUB_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'
|
||||||
};
|
};
|
||||||
|
|||||||
166
dist/setup/index.js
vendored
166
dist/setup/index.js
vendored
@@ -130592,37 +130592,56 @@ 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;
|
||||||
|
const GRAALVM_MIN_VERSION = 17;
|
||||||
|
const SUPPORTED_ARCHITECTURES = ['x64', 'aarch64'];
|
||||||
class GraalVMDistribution extends base_installer_1.JavaBase {
|
class GraalVMDistribution extends base_installer_1.JavaBase {
|
||||||
constructor(installerOptions) {
|
constructor(installerOptions) {
|
||||||
super('GraalVM', installerOptions);
|
super('GraalVM', installerOptions);
|
||||||
}
|
}
|
||||||
downloadTool(javaRelease) {
|
downloadTool(javaRelease) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
core.info(`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`);
|
try {
|
||||||
let javaArchivePath = yield tc.downloadTool(javaRelease.url);
|
core.info(`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`);
|
||||||
core.info(`Extracting Java archive...`);
|
let javaArchivePath = yield tc.downloadTool(javaRelease.url);
|
||||||
const extension = (0, util_1.getDownloadArchiveExtension)();
|
core.info(`Extracting Java archive...`);
|
||||||
if (process.platform === 'win32') {
|
const extension = (0, util_1.getDownloadArchiveExtension)();
|
||||||
javaArchivePath = (0, util_1.renameWinArchive)(javaArchivePath);
|
if (IS_WINDOWS) {
|
||||||
|
javaArchivePath = (0, util_1.renameWinArchive)(javaArchivePath);
|
||||||
|
}
|
||||||
|
const extractedJavaPath = yield (0, util_1.extractJdkFile)(javaArchivePath, extension);
|
||||||
|
// Add validation for extracted path
|
||||||
|
if (!fs_1.default.existsSync(extractedJavaPath)) {
|
||||||
|
throw new Error(`Extraction failed: path ${extractedJavaPath} does not exist`);
|
||||||
|
}
|
||||||
|
const dirContents = fs_1.default.readdirSync(extractedJavaPath);
|
||||||
|
if (dirContents.length === 0) {
|
||||||
|
throw new Error('Extraction failed: no files found in extracted directory');
|
||||||
|
}
|
||||||
|
const archivePath = path_1.default.join(extractedJavaPath, dirContents[0]);
|
||||||
|
const version = this.getToolcacheVersionName(javaRelease.version);
|
||||||
|
const javaPath = yield tc.cacheDir(archivePath, this.toolcacheFolderName, version, this.architecture);
|
||||||
|
return { version: javaRelease.version, path: javaPath };
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
core.error(`Failed to download and extract GraalVM: ${error}`);
|
||||||
|
throw error;
|
||||||
}
|
}
|
||||||
const extractedJavaPath = yield (0, util_1.extractJdkFile)(javaArchivePath, extension);
|
|
||||||
const archiveName = fs_1.default.readdirSync(extractedJavaPath)[0];
|
|
||||||
const archivePath = path_1.default.join(extractedJavaPath, archiveName);
|
|
||||||
const version = this.getToolcacheVersionName(javaRelease.version);
|
|
||||||
const javaPath = yield tc.cacheDir(archivePath, this.toolcacheFolderName, version, this.architecture);
|
|
||||||
return { version: javaRelease.version, path: javaPath };
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
findPackageForDownload(range) {
|
findPackageForDownload(range) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
// Add input validation
|
||||||
|
if (!range || typeof range !== 'string') {
|
||||||
|
throw new Error('Version range is required and must be a string');
|
||||||
|
}
|
||||||
const arch = this.distributionArchitecture();
|
const arch = this.distributionArchitecture();
|
||||||
if (arch !== 'x64' && arch !== 'aarch64') {
|
if (!SUPPORTED_ARCHITECTURES.includes(arch)) {
|
||||||
throw new Error(`Unsupported architecture: ${this.architecture}`);
|
throw new Error(`Unsupported architecture: ${this.architecture}. Supported architectures are: ${SUPPORTED_ARCHITECTURES.join(', ')}`);
|
||||||
}
|
}
|
||||||
if (!this.stable) {
|
if (!this.stable) {
|
||||||
return this.findEABuildDownloadUrl(`${range}-ea`);
|
return this.findEABuildDownloadUrl(`${range}-ea`);
|
||||||
@@ -130632,81 +130651,104 @@ 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 majorVersion = parseInt(major);
|
||||||
if (range.includes('.')) {
|
if (isNaN(majorVersion)) {
|
||||||
major = range.split('.')[0];
|
throw new Error(`Invalid version format: ${range}`);
|
||||||
fileUrl = `${GRAALVM_DL_BASE}/${major}/archive/graalvm-jdk-${range}_${platform}-${arch}_bin.${extension}`;
|
|
||||||
}
|
}
|
||||||
else {
|
if (majorVersion < GRAALVM_MIN_VERSION) {
|
||||||
major = range;
|
throw new Error(`GraalVM is only supported for JDK ${GRAALVM_MIN_VERSION} and later. Requested version: ${major}`);
|
||||||
fileUrl = `${GRAALVM_DL_BASE}/${range}/latest/graalvm-jdk-${range}_${platform}-${arch}_bin.${extension}`;
|
|
||||||
}
|
|
||||||
if (parseInt(major) < 17) {
|
|
||||||
throw new Error('GraalVM is only supported for JDK 17 and later');
|
|
||||||
}
|
}
|
||||||
|
const fileUrl = this.constructFileUrl(range, major, platform, arch, extension);
|
||||||
const response = yield this.http.head(fileUrl);
|
const response = yield this.http.head(fileUrl);
|
||||||
if (response.message.statusCode === http_client_1.HttpCodes.NotFound) {
|
this.handleHttpResponse(response, range);
|
||||||
throw new Error(`Could not find GraalVM for SemVer ${range}`);
|
|
||||||
}
|
|
||||||
if (response.message.statusCode !== http_client_1.HttpCodes.OK) {
|
|
||||||
throw new Error(`Http request for GraalVM failed with status code: ${response.message.statusCode}`);
|
|
||||||
}
|
|
||||||
return { url: fileUrl, version: 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) {
|
||||||
|
const statusCode = response.message.statusCode;
|
||||||
|
if (statusCode === http_client_1.HttpCodes.NotFound) {
|
||||||
|
throw new Error(`Could not find GraalVM for SemVer ${range}. Please check if this version is available at ${GRAALVM_DL_BASE}`);
|
||||||
|
}
|
||||||
|
if (statusCode === http_client_1.HttpCodes.Unauthorized ||
|
||||||
|
statusCode === http_client_1.HttpCodes.Forbidden) {
|
||||||
|
throw new Error(`Access denied when downloading GraalVM. Status code: ${statusCode}. Please check your credentials or permissions.`);
|
||||||
|
}
|
||||||
|
if (statusCode !== http_client_1.HttpCodes.OK) {
|
||||||
|
throw new Error(`HTTP request for GraalVM failed with status code: ${statusCode} (${response.message.statusMessage || 'Unknown error'})`);
|
||||||
|
}
|
||||||
|
}
|
||||||
findEABuildDownloadUrl(javaEaVersion) {
|
findEABuildDownloadUrl(javaEaVersion) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
core.debug(`Searching for EA build: ${javaEaVersion}`);
|
||||||
const versions = yield this.fetchEAJson(javaEaVersion);
|
const versions = yield this.fetchEAJson(javaEaVersion);
|
||||||
|
core.debug(`Found ${versions.length} EA versions`);
|
||||||
const latestVersion = versions.find(v => v.latest);
|
const latestVersion = versions.find(v => v.latest);
|
||||||
if (!latestVersion) {
|
if (!latestVersion) {
|
||||||
|
core.error(`Available versions: ${versions.map(v => v.version).join(', ')}`);
|
||||||
throw new Error(`Unable to find latest version for '${javaEaVersion}'`);
|
throw new Error(`Unable to find latest version for '${javaEaVersion}'`);
|
||||||
}
|
}
|
||||||
|
core.debug(`Latest version found: ${latestVersion.version}`);
|
||||||
const arch = this.distributionArchitecture();
|
const arch = this.distributionArchitecture();
|
||||||
const file = latestVersion.files.find(f => f.arch === arch && f.platform === GRAALVM_PLATFORM);
|
const file = latestVersion.files.find(f => f.arch === arch && f.platform === GRAALVM_PLATFORM);
|
||||||
if (!file || !file.filename.startsWith('graalvm-jdk-')) {
|
if (!file) {
|
||||||
throw new Error(`Unable to find file metadata for '${javaEaVersion}'`);
|
core.error(`Available files for architecture ${arch}: ${JSON.stringify(latestVersion.files)}`);
|
||||||
|
throw new Error(`Unable to find file for architecture '${arch}' and platform '${GRAALVM_PLATFORM}'`);
|
||||||
}
|
}
|
||||||
|
if (!file.filename.startsWith('graalvm-jdk-')) {
|
||||||
|
throw new Error(`Invalid filename format: ${file.filename}. Expected to start with 'graalvm-jdk-'`);
|
||||||
|
}
|
||||||
|
const downloadUrl = `${latestVersion.download_base_url}${file.filename}`;
|
||||||
|
core.debug(`Download URL: ${downloadUrl}`);
|
||||||
return {
|
return {
|
||||||
url: `${latestVersion.download_base_url}${file.filename}`,
|
url: downloadUrl,
|
||||||
version: latestVersion.version
|
version: latestVersion.version
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
fetchEAJson(javaEaVersion) {
|
fetchEAJson(javaEaVersion) {
|
||||||
|
var _a;
|
||||||
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;
|
|
||||||
try {
|
try {
|
||||||
fetchedJson = (yield this.http.getJson(url, headers))
|
const response = yield this.http.getJson(url, headers);
|
||||||
.result;
|
if (!response.result) {
|
||||||
|
throw new Error(`No GraalVM EA build found for version '${javaEaVersion}'. Please check if the version is correct.`);
|
||||||
|
}
|
||||||
|
return response.result;
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (error) {
|
||||||
throw Error(`Fetching version info for GraalVM EA builds from '${url}' failed with the error: ${err.message}`);
|
if (error instanceof Error) {
|
||||||
|
// Check if it's a 404 error (file not found)
|
||||||
|
if ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('404')) {
|
||||||
|
throw new Error(`GraalVM EA version '${javaEaVersion}' not found. Please verify the version exists in the EA builds repository.`);
|
||||||
|
}
|
||||||
|
// Re-throw with more context
|
||||||
|
throw new Error(`Failed to fetch GraalVM EA version information for '${javaEaVersion}': ${error.message}`);
|
||||||
|
}
|
||||||
|
// If it's not an Error instance, throw a generic error
|
||||||
|
throw new Error(`Failed to fetch GraalVM EA version information for '${javaEaVersion}'`);
|
||||||
}
|
}
|
||||||
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) {
|
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;
|
||||||
@@ -131587,9 +131629,9 @@ class SapMachineDistribution extends base_installer_1.JavaBase {
|
|||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const platform = this.getPlatformOption();
|
const platform = this.getPlatformOption();
|
||||||
const arch = this.distributionArchitecture();
|
const arch = this.distributionArchitecture();
|
||||||
let fetchedReleasesJson = yield this.fetchReleasesFromUrl('https://sap.github.io/SapMachine/assets/data/sapmachine-releases-all.json');
|
let fetchedReleasesJson = yield this.fetchReleasesFromUrl('https://sapmachine.io/assets/data/sapmachine-releases-all.json');
|
||||||
if (!fetchedReleasesJson) {
|
if (!fetchedReleasesJson) {
|
||||||
fetchedReleasesJson = yield this.fetchReleasesFromUrl('https://api.github.com/repos/SAP/SapMachine/contents/assets/data/sapmachine-releases-all.json?ref=gh-pages', (0, util_1.getGitHubHttpHeaders)());
|
fetchedReleasesJson = yield this.fetchReleasesFromUrl('https://sap.github.io/SapMachine/assets/data/sapmachine-releases-all.json');
|
||||||
}
|
}
|
||||||
if (!fetchedReleasesJson) {
|
if (!fetchedReleasesJson) {
|
||||||
throw new Error(`Couldn't fetch SapMachine versions information from both primary and backup urls`);
|
throw new Error(`Couldn't fetch SapMachine versions information from both primary and backup urls`);
|
||||||
@@ -132849,8 +132891,8 @@ function convertVersionToSemver(version) {
|
|||||||
}
|
}
|
||||||
exports.convertVersionToSemver = convertVersionToSemver;
|
exports.convertVersionToSemver = convertVersionToSemver;
|
||||||
function getGitHubHttpHeaders() {
|
function getGitHubHttpHeaders() {
|
||||||
const token = core.getInput('token');
|
const resolvedToken = core.getInput('token') || process.env.GITHUB_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'
|
||||||
};
|
};
|
||||||
|
|||||||
587
package-lock.json
generated
587
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -46,7 +46,7 @@
|
|||||||
"@typescript-eslint/eslint-plugin": "^8.35.1",
|
"@typescript-eslint/eslint-plugin": "^8.35.1",
|
||||||
"@typescript-eslint/parser": "^8.35.1",
|
"@typescript-eslint/parser": "^8.35.1",
|
||||||
"@vercel/ncc": "^0.38.1",
|
"@vercel/ncc": "^0.38.1",
|
||||||
"eslint": "^8.57.0",
|
"eslint": "^9.39.1",
|
||||||
"eslint-config-prettier": "^8.6.0",
|
"eslint-config-prettier": "^8.6.0",
|
||||||
"eslint-plugin-jest": "^29.0.1",
|
"eslint-plugin-jest": "^29.0.1",
|
||||||
"eslint-plugin-node": "^11.1.0",
|
"eslint-plugin-node": "^11.1.0",
|
||||||
|
|||||||
@@ -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,12 +16,14 @@ 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';
|
||||||
const GRAALVM_PLATFORM = IS_WINDOWS ? 'windows' : process.platform;
|
const GRAALVM_PLATFORM = IS_WINDOWS ? 'windows' : process.platform;
|
||||||
|
const GRAALVM_MIN_VERSION = 17;
|
||||||
|
const SUPPORTED_ARCHITECTURES = ['x64', 'aarch64'] as const;
|
||||||
|
type SupportedArchitecture = (typeof SUPPORTED_ARCHITECTURES)[number];
|
||||||
|
type OsVersions = 'linux' | 'macos' | 'windows';
|
||||||
|
|
||||||
export class GraalVMDistribution extends JavaBase {
|
export class GraalVMDistribution extends JavaBase {
|
||||||
constructor(installerOptions: JavaInstallerOptions) {
|
constructor(installerOptions: JavaInstallerOptions) {
|
||||||
@@ -31,38 +33,67 @@ export class GraalVMDistribution extends JavaBase {
|
|||||||
protected async downloadTool(
|
protected async downloadTool(
|
||||||
javaRelease: JavaDownloadRelease
|
javaRelease: JavaDownloadRelease
|
||||||
): Promise<JavaInstallerResults> {
|
): Promise<JavaInstallerResults> {
|
||||||
core.info(
|
try {
|
||||||
`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`
|
core.info(
|
||||||
);
|
`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`
|
||||||
let javaArchivePath = await tc.downloadTool(javaRelease.url);
|
);
|
||||||
|
let javaArchivePath = await tc.downloadTool(javaRelease.url);
|
||||||
|
|
||||||
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
|
||||||
|
);
|
||||||
|
|
||||||
|
// Add validation for extracted path
|
||||||
|
if (!fs.existsSync(extractedJavaPath)) {
|
||||||
|
throw new Error(
|
||||||
|
`Extraction failed: path ${extractedJavaPath} does not exist`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const dirContents = fs.readdirSync(extractedJavaPath);
|
||||||
|
if (dirContents.length === 0) {
|
||||||
|
throw new Error(
|
||||||
|
'Extraction failed: no files found in extracted directory'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const archivePath = path.join(extractedJavaPath, dirContents[0]);
|
||||||
|
const version = this.getToolcacheVersionName(javaRelease.version);
|
||||||
|
|
||||||
|
const javaPath = await tc.cacheDir(
|
||||||
|
archivePath,
|
||||||
|
this.toolcacheFolderName,
|
||||||
|
version,
|
||||||
|
this.architecture
|
||||||
|
);
|
||||||
|
|
||||||
|
return {version: javaRelease.version, path: javaPath};
|
||||||
|
} catch (error) {
|
||||||
|
core.error(`Failed to download and extract GraalVM: ${error}`);
|
||||||
|
throw error;
|
||||||
}
|
}
|
||||||
const extractedJavaPath = await extractJdkFile(javaArchivePath, extension);
|
|
||||||
|
|
||||||
const archiveName = fs.readdirSync(extractedJavaPath)[0];
|
|
||||||
const archivePath = path.join(extractedJavaPath, archiveName);
|
|
||||||
const version = this.getToolcacheVersionName(javaRelease.version);
|
|
||||||
|
|
||||||
const javaPath = await tc.cacheDir(
|
|
||||||
archivePath,
|
|
||||||
this.toolcacheFolderName,
|
|
||||||
version,
|
|
||||||
this.architecture
|
|
||||||
);
|
|
||||||
|
|
||||||
return {version: javaRelease.version, path: javaPath};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async findPackageForDownload(
|
protected async findPackageForDownload(
|
||||||
range: string
|
range: string
|
||||||
): Promise<JavaDownloadRelease> {
|
): Promise<JavaDownloadRelease> {
|
||||||
|
// Add input validation
|
||||||
|
if (!range || typeof range !== 'string') {
|
||||||
|
throw new Error('Version range is required and must be a string');
|
||||||
|
}
|
||||||
|
|
||||||
const arch = this.distributionArchitecture();
|
const arch = this.distributionArchitecture();
|
||||||
if (arch !== 'x64' && arch !== 'aarch64') {
|
if (!SUPPORTED_ARCHITECTURES.includes(arch as SupportedArchitecture)) {
|
||||||
throw new Error(`Unsupported architecture: ${this.architecture}`);
|
throw new Error(
|
||||||
|
`Unsupported architecture: ${this.architecture}. Supported architectures are: ${SUPPORTED_ARCHITECTURES.join(', ')}`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.stable) {
|
if (!this.stable) {
|
||||||
@@ -75,52 +106,113 @@ 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 majorVersion = parseInt(major);
|
||||||
if (range.includes('.')) {
|
|
||||||
major = range.split('.')[0];
|
if (isNaN(majorVersion)) {
|
||||||
fileUrl = `${GRAALVM_DL_BASE}/${major}/archive/graalvm-jdk-${range}_${platform}-${arch}_bin.${extension}`;
|
throw new Error(`Invalid version format: ${range}`);
|
||||||
} else {
|
|
||||||
major = range;
|
|
||||||
fileUrl = `${GRAALVM_DL_BASE}/${range}/latest/graalvm-jdk-${range}_${platform}-${arch}_bin.${extension}`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parseInt(major) < 17) {
|
if (majorVersion < GRAALVM_MIN_VERSION) {
|
||||||
throw new Error('GraalVM is only supported for JDK 17 and later');
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await this.http.head(fileUrl);
|
|
||||||
|
|
||||||
if (response.message.statusCode === HttpCodes.NotFound) {
|
|
||||||
throw new Error(`Could not find GraalVM for SemVer ${range}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (response.message.statusCode !== HttpCodes.OK) {
|
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Http request for GraalVM failed with status code: ${response.message.statusCode}`
|
`GraalVM is only supported for JDK ${GRAALVM_MIN_VERSION} and later. Requested version: ${major}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const fileUrl = this.constructFileUrl(
|
||||||
|
range,
|
||||||
|
major,
|
||||||
|
platform,
|
||||||
|
arch,
|
||||||
|
extension
|
||||||
|
);
|
||||||
|
|
||||||
|
const response = await this.http.head(fileUrl);
|
||||||
|
this.handleHttpResponse(response, range);
|
||||||
|
|
||||||
return {url: fileUrl, version: 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 {
|
||||||
|
const statusCode = response.message.statusCode;
|
||||||
|
|
||||||
|
if (statusCode === HttpCodes.NotFound) {
|
||||||
|
throw new Error(
|
||||||
|
`Could not find GraalVM for SemVer ${range}. Please check if this version is available at ${GRAALVM_DL_BASE}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
statusCode === HttpCodes.Unauthorized ||
|
||||||
|
statusCode === HttpCodes.Forbidden
|
||||||
|
) {
|
||||||
|
throw new Error(
|
||||||
|
`Access denied when downloading GraalVM. Status code: ${statusCode}. Please check your credentials or permissions.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (statusCode !== HttpCodes.OK) {
|
||||||
|
throw new Error(
|
||||||
|
`HTTP request for GraalVM failed with status code: ${statusCode} (${response.message.statusMessage || 'Unknown error'})`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private async findEABuildDownloadUrl(
|
private async findEABuildDownloadUrl(
|
||||||
javaEaVersion: string
|
javaEaVersion: string
|
||||||
): Promise<JavaDownloadRelease> {
|
): Promise<JavaDownloadRelease> {
|
||||||
|
core.debug(`Searching for EA build: ${javaEaVersion}`);
|
||||||
|
|
||||||
const versions = await this.fetchEAJson(javaEaVersion);
|
const versions = await this.fetchEAJson(javaEaVersion);
|
||||||
|
core.debug(`Found ${versions.length} EA versions`);
|
||||||
|
|
||||||
const latestVersion = versions.find(v => v.latest);
|
const latestVersion = versions.find(v => v.latest);
|
||||||
if (!latestVersion) {
|
if (!latestVersion) {
|
||||||
|
core.error(
|
||||||
|
`Available versions: ${versions.map(v => v.version).join(', ')}`
|
||||||
|
);
|
||||||
throw new Error(`Unable to find latest version for '${javaEaVersion}'`);
|
throw new Error(`Unable to find latest version for '${javaEaVersion}'`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core.debug(`Latest version found: ${latestVersion.version}`);
|
||||||
|
|
||||||
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
|
||||||
);
|
);
|
||||||
if (!file || !file.filename.startsWith('graalvm-jdk-')) {
|
|
||||||
throw new Error(`Unable to find file metadata for '${javaEaVersion}'`);
|
if (!file) {
|
||||||
|
core.error(
|
||||||
|
`Available files for architecture ${arch}: ${JSON.stringify(latestVersion.files)}`
|
||||||
|
);
|
||||||
|
throw new Error(
|
||||||
|
`Unable to find file for architecture '${arch}' and platform '${GRAALVM_PLATFORM}'`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!file.filename.startsWith('graalvm-jdk-')) {
|
||||||
|
throw new Error(
|
||||||
|
`Invalid filename format: ${file.filename}. Expected to start with 'graalvm-jdk-'`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const downloadUrl = `${latestVersion.download_base_url}${file.filename}`;
|
||||||
|
core.debug(`Download URL: ${downloadUrl}`);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
url: `${latestVersion.download_base_url}${file.filename}`,
|
url: downloadUrl,
|
||||||
version: latestVersion.version
|
version: latestVersion.version
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -128,49 +220,59 @@ 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;
|
|
||||||
try {
|
try {
|
||||||
fetchedJson = (await this.http.getJson<GraalVMEAVersion[]>(url, headers))
|
const response = await this.http.getJson<GraalVMEAVersion[]>(
|
||||||
.result;
|
url,
|
||||||
} catch (err) {
|
headers
|
||||||
throw Error(
|
);
|
||||||
`Fetching version info for GraalVM EA builds from '${url}' failed with the error: ${
|
|
||||||
(err as Error).message
|
if (!response.result) {
|
||||||
}`
|
throw new Error(
|
||||||
|
`No GraalVM EA build found for version '${javaEaVersion}'. Please check if the version is correct.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.result;
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
// Check if it's a 404 error (file not found)
|
||||||
|
if (error.message?.includes('404')) {
|
||||||
|
throw new Error(
|
||||||
|
`GraalVM EA version '${javaEaVersion}' not found. Please verify the version exists in the EA builds repository.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// Re-throw with more context
|
||||||
|
throw new Error(
|
||||||
|
`Failed to fetch GraalVM EA version information for '${javaEaVersion}': ${error.message}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// If it's not an Error instance, throw a generic error
|
||||||
|
throw new Error(
|
||||||
|
`Failed to fetch GraalVM EA version information for '${javaEaVersion}'`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
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) {
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import {
|
|||||||
convertVersionToSemver,
|
convertVersionToSemver,
|
||||||
extractJdkFile,
|
extractJdkFile,
|
||||||
getDownloadArchiveExtension,
|
getDownloadArchiveExtension,
|
||||||
getGitHubHttpHeaders,
|
|
||||||
isVersionSatisfies,
|
isVersionSatisfies,
|
||||||
renameWinArchive
|
renameWinArchive
|
||||||
} from '../../util';
|
} from '../../util';
|
||||||
@@ -64,13 +63,12 @@ export class SapMachineDistribution extends JavaBase {
|
|||||||
const arch = this.distributionArchitecture();
|
const arch = this.distributionArchitecture();
|
||||||
|
|
||||||
let fetchedReleasesJson = await this.fetchReleasesFromUrl(
|
let fetchedReleasesJson = await this.fetchReleasesFromUrl(
|
||||||
'https://sap.github.io/SapMachine/assets/data/sapmachine-releases-all.json'
|
'https://sapmachine.io/assets/data/sapmachine-releases-all.json'
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!fetchedReleasesJson) {
|
if (!fetchedReleasesJson) {
|
||||||
fetchedReleasesJson = await this.fetchReleasesFromUrl(
|
fetchedReleasesJson = await this.fetchReleasesFromUrl(
|
||||||
'https://api.github.com/repos/SAP/SapMachine/contents/assets/data/sapmachine-releases-all.json?ref=gh-pages',
|
'https://sap.github.io/SapMachine/assets/data/sapmachine-releases-all.json'
|
||||||
getGitHubHttpHeaders()
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -184,8 +184,8 @@ export function convertVersionToSemver(version: number[] | string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getGitHubHttpHeaders(): OutgoingHttpHeaders {
|
export function getGitHubHttpHeaders(): OutgoingHttpHeaders {
|
||||||
const token = core.getInput('token');
|
const resolvedToken = core.getInput('token') || process.env.GITHUB_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'
|
||||||
|
|||||||
Reference in New Issue
Block a user