mirror of
https://github.com/actions/setup-java.git
synced 2025-06-28 20:14:14 +00:00
Code updated to let code accept github token and refactored the code.
This commit is contained in:
parent
f4f1212c88
commit
6992528a74
5 changed files with 159 additions and 170 deletions
86
dist/setup/index.js
vendored
86
dist/setup/index.js
vendored
|
@ -129432,8 +129432,8 @@ const tc = __importStar(__nccwpck_require__(27784));
|
|||
const fs_1 = __importDefault(__nccwpck_require__(57147));
|
||||
const path_1 = __importDefault(__nccwpck_require__(71017));
|
||||
const base_installer_1 = __nccwpck_require__(59741);
|
||||
const util_1 = __nccwpck_require__(92629);
|
||||
const http_client_1 = __nccwpck_require__(96255);
|
||||
const util_1 = __nccwpck_require__(92629);
|
||||
const GRAALVM_DL_BASE = 'https://download.oracle.com/graalvm';
|
||||
const IS_WINDOWS = process.platform === 'win32';
|
||||
const GRAALVM_PLATFORM = IS_WINDOWS ? 'windows' : process.platform;
|
||||
|
@ -129447,12 +129447,11 @@ class GraalVMDistribution extends base_installer_1.JavaBase {
|
|||
let javaArchivePath = yield tc.downloadTool(javaRelease.url);
|
||||
core.info(`Extracting Java archive...`);
|
||||
const extension = (0, util_1.getDownloadArchiveExtension)();
|
||||
if (process.platform === 'win32') {
|
||||
if (IS_WINDOWS) {
|
||||
javaArchivePath = (0, util_1.renameWinArchive)(javaArchivePath);
|
||||
}
|
||||
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 archivePath = path_1.default.join(extractedJavaPath, fs_1.default.readdirSync(extractedJavaPath)[0]);
|
||||
const version = this.getToolcacheVersionName(javaRelease.version);
|
||||
const javaPath = yield tc.cacheDir(archivePath, this.toolcacheFolderName, version, this.architecture);
|
||||
return { version: javaRelease.version, path: javaPath };
|
||||
|
@ -129461,7 +129460,7 @@ class GraalVMDistribution extends base_installer_1.JavaBase {
|
|||
findPackageForDownload(range) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const arch = this.distributionArchitecture();
|
||||
if (arch !== 'x64' && arch !== 'aarch64') {
|
||||
if (!['x64', 'aarch64'].includes(arch)) {
|
||||
throw new Error(`Unsupported architecture: ${this.architecture}`);
|
||||
}
|
||||
if (!this.stable) {
|
||||
|
@ -129472,29 +129471,29 @@ class GraalVMDistribution extends base_installer_1.JavaBase {
|
|||
}
|
||||
const platform = this.getPlatform();
|
||||
const extension = (0, util_1.getDownloadArchiveExtension)();
|
||||
let major;
|
||||
let fileUrl;
|
||||
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}`;
|
||||
}
|
||||
const major = range.includes('.') ? range.split('.')[0] : range;
|
||||
const fileUrl = this.constructFileUrl(range, major, platform, arch, extension);
|
||||
if (parseInt(major) < 17) {
|
||||
throw new Error('GraalVM is only supported for JDK 17 and later');
|
||||
}
|
||||
const response = yield this.http.head(fileUrl);
|
||||
if (response.message.statusCode === http_client_1.HttpCodes.NotFound) {
|
||||
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}`);
|
||||
}
|
||||
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) {
|
||||
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}`);
|
||||
}
|
||||
}
|
||||
findEABuildDownloadUrl(javaEaVersion) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const versions = yield this.fetchEAJson(javaEaVersion);
|
||||
|
@ -129515,38 +129514,29 @@ class GraalVMDistribution extends base_installer_1.JavaBase {
|
|||
}
|
||||
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 url = `https://api.github.com/repos/graalvm/oracle-graalvm-ea-builds/contents/versions/${javaEaVersion}.json?ref=main`;
|
||||
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?`);
|
||||
const fetchedJson = yield this.http
|
||||
.getJson(url, headers)
|
||||
.then(res => res.result);
|
||||
if (!fetchedJson) {
|
||||
throw new Error(`No GraalVM EA build found for version '${javaEaVersion}'. Please check if the version is correct.`);
|
||||
}
|
||||
return fetchedJson;
|
||||
});
|
||||
}
|
||||
getPlatform(platform = process.platform) {
|
||||
switch (platform) {
|
||||
case 'darwin':
|
||||
return 'macos';
|
||||
case 'win32':
|
||||
return 'windows';
|
||||
case 'linux':
|
||||
return 'linux';
|
||||
default:
|
||||
throw new Error(`Platform '${platform}' is not supported. Supported platforms: 'linux', 'macos', 'windows'`);
|
||||
const platformMap = {
|
||||
darwin: 'macos',
|
||||
win32: 'windows',
|
||||
linux: 'linux'
|
||||
};
|
||||
const result = platformMap[platform];
|
||||
if (!result) {
|
||||
throw new Error(`Platform '${platform}' is not supported. Supported platforms: 'linux', 'macos', 'windows'`);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
exports.GraalVMDistribution = GraalVMDistribution;
|
||||
|
@ -131681,9 +131671,9 @@ function convertVersionToSemver(version) {
|
|||
return mainVersion;
|
||||
}
|
||||
exports.convertVersionToSemver = convertVersionToSemver;
|
||||
function getGitHubHttpHeaders() {
|
||||
const token = core.getInput('token');
|
||||
const auth = !token ? undefined : `token ${token}`;
|
||||
function getGitHubHttpHeaders(token) {
|
||||
const resolvedToken = token || core.getInput('token');
|
||||
const auth = !resolvedToken ? undefined : `token ${resolvedToken}`;
|
||||
const headers = {
|
||||
accept: 'application/vnd.github.VERSION.raw'
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue