From 2408275e34ad9141fa3ff453eed0e1aaa0290c1a Mon Sep 17 00:00:00 2001 From: Fabio Niephaus Date: Tue, 13 Feb 2024 13:37:00 +0100 Subject: [PATCH] Add initial support for early access (EA) builds. --- .github/workflows/test.yml | 3 +++ dist/cleanup/index.js | 19 ++++++++++++++++++- dist/main/index.js | 37 ++++++++++++++++++++++++++++++++++++- src/constants.ts | 3 +++ src/graalvm.ts | 25 +++++++++++++++++++++++++ src/utils.ts | 19 +++++++++++++++++++ 6 files changed, 104 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 76b6b22..d491f39 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -35,6 +35,9 @@ jobs: ] components: [''] include: + - java-version: '22-ea' + distribution: 'graalvm' + os: ubuntu-latest - java-version: '21' distribution: '' os: ubuntu-latest diff --git a/dist/cleanup/index.js b/dist/cleanup/index.js index ea401f3..9cbc4f3 100644 --- a/dist/cleanup/index.js +++ b/dist/cleanup/index.js @@ -92864,7 +92864,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.createPRComment = exports.isPREvent = exports.toSemVer = exports.calculateSHA256 = exports.downloadExtractAndCacheJDK = exports.downloadAndExtractJDK = exports.getMatchingTags = exports.getTaggedRelease = exports.getLatestRelease = exports.exec = void 0; +exports.createPRComment = exports.isPREvent = exports.toSemVer = exports.calculateSHA256 = exports.downloadExtractAndCacheJDK = exports.downloadAndExtractJDK = exports.getMatchingTags = exports.getTaggedRelease = exports.getLatestRelease = exports.getLatestPrerelease = exports.exec = void 0; const c = __importStar(__nccwpck_require__(9042)); const core = __importStar(__nccwpck_require__(2186)); const github = __importStar(__nccwpck_require__(5438)); @@ -92894,6 +92894,23 @@ function exec(commandLine, args, options) { }); } exports.exec = exec; +function getLatestPrerelease(repo) { + return __awaiter(this, void 0, void 0, function* () { + const githubToken = getGitHubToken(); + const options = githubToken.length > 0 ? { auth: githubToken } : {}; + const octokit = new GitHubDotCom(options); + const releases = (yield octokit.request('GET /repos/{owner}/{repo}/releases', { + owner: c.GRAALVM_GH_USER, + repo + })).data; + const firstPrerelease = releases.find(r => r.prerelease); + if (!firstPrerelease) { + throw new Error(`Unable to find latest prerelease in ${repo}`); + } + return firstPrerelease; + }); +} +exports.getLatestPrerelease = getLatestPrerelease; function getLatestRelease(repo) { return __awaiter(this, void 0, void 0, function* () { const githubToken = getGitHubToken(); diff --git a/dist/main/index.js b/dist/main/index.js index 65ff422..d756017 100644 --- a/dist/main/index.js +++ b/dist/main/index.js @@ -93850,6 +93850,7 @@ const tool_cache_1 = __nccwpck_require__(7784); const path_1 = __nccwpck_require__(1017); const GRAALVM_DL_BASE = 'https://download.oracle.com/graalvm'; const GRAALVM_CE_DL_BASE = `https://github.com/graalvm/${c.GRAALVM_RELEASES_REPO}/releases/download`; +const ORACLE_GRAALVM_REPO_EA_BUILDS = 'oracle-graalvm-dev-builds'; const GRAALVM_REPO_DEV_BUILDS = 'graalvm-ce-dev-builds'; const GRAALVM_JDK_TAG_PREFIX = 'jdk-'; const GRAALVM_TAG_PREFIX = 'vm-'; @@ -93879,6 +93880,9 @@ function setUpGraalVMJDK(javaVersionOrDev) { throw new Error(`java-version set to '${javaVersion}'. Please make sure the java-version is set correctly. ${c.ERROR_HINT}`); } } + else if (javaVersion === '22-ea') { + downloadUrl = yield findLatestEABuildDownloadUrl(javaVersion); + } else { downloadUrl = `${GRAALVM_DL_BASE}/${javaVersion}/latest/${toolName}${c.GRAALVM_FILE_EXTENSION}`; } @@ -93887,6 +93891,20 @@ function setUpGraalVMJDK(javaVersionOrDev) { }); } exports.setUpGraalVMJDK = setUpGraalVMJDK; +function findLatestEABuildDownloadUrl(javaEaVersion) { + return __awaiter(this, void 0, void 0, function* () { + const latestPrerelease = yield (0, utils_1.getLatestPrerelease)(ORACLE_GRAALVM_REPO_EA_BUILDS); + const expectedFileNamePrefix = 'graalvm-jdk-'; + const expectedFileNameSuffix = `_${c.JDK_PLATFORM}-${c.JDK_ARCH}_bin${c.GRAALVM_FILE_EXTENSION}`; + for (const asset of latestPrerelease.assets) { + if (asset.name.startsWith(expectedFileNamePrefix) && + asset.name.endsWith(expectedFileNameSuffix)) { + return asset.browser_download_url; + } + } + throw new Error(`Could not find Oracle GraalVM build for ${javaEaVersion}. ${c.ERROR_HINT}`); + }); +} function setUpGraalVMJDKCE(javaVersionOrDev) { return __awaiter(this, void 0, void 0, function* () { if (javaVersionOrDev === c.VERSION_DEV) { @@ -94621,7 +94639,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.createPRComment = exports.isPREvent = exports.toSemVer = exports.calculateSHA256 = exports.downloadExtractAndCacheJDK = exports.downloadAndExtractJDK = exports.getMatchingTags = exports.getTaggedRelease = exports.getLatestRelease = exports.exec = void 0; +exports.createPRComment = exports.isPREvent = exports.toSemVer = exports.calculateSHA256 = exports.downloadExtractAndCacheJDK = exports.downloadAndExtractJDK = exports.getMatchingTags = exports.getTaggedRelease = exports.getLatestRelease = exports.getLatestPrerelease = exports.exec = void 0; const c = __importStar(__nccwpck_require__(9042)); const core = __importStar(__nccwpck_require__(2186)); const github = __importStar(__nccwpck_require__(5438)); @@ -94651,6 +94669,23 @@ function exec(commandLine, args, options) { }); } exports.exec = exec; +function getLatestPrerelease(repo) { + return __awaiter(this, void 0, void 0, function* () { + const githubToken = getGitHubToken(); + const options = githubToken.length > 0 ? { auth: githubToken } : {}; + const octokit = new GitHubDotCom(options); + const releases = (yield octokit.request('GET /repos/{owner}/{repo}/releases', { + owner: c.GRAALVM_GH_USER, + repo + })).data; + const firstPrerelease = releases.find(r => r.prerelease); + if (!firstPrerelease) { + throw new Error(`Unable to find latest prerelease in ${repo}`); + } + return firstPrerelease; + }); +} +exports.getLatestPrerelease = getLatestPrerelease; function getLatestRelease(repo) { return __awaiter(this, void 0, void 0, function* () { const githubToken = getGitHubToken(); diff --git a/src/constants.ts b/src/constants.ts index a021f0e..4088517 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -49,6 +49,9 @@ export type LatestReleaseResponse = export type MatchingRefsResponse = otypes.Endpoints['GET /repos/{owner}/{repo}/git/matching-refs/{ref}']['response'] +export type ReleasesResponse = + otypes.Endpoints['GET /repos/{owner}/{repo}/releases']['response'] + function determineJDKArchitecture(): string { switch (process.arch) { case 'x64': { diff --git a/src/graalvm.ts b/src/graalvm.ts index f2be101..1d8d437 100644 --- a/src/graalvm.ts +++ b/src/graalvm.ts @@ -3,6 +3,7 @@ import * as semver from 'semver' import { downloadAndExtractJDK, downloadExtractAndCacheJDK, + getLatestPrerelease, getLatestRelease, getMatchingTags, getTaggedRelease @@ -13,6 +14,7 @@ import {basename} from 'path' const GRAALVM_DL_BASE = 'https://download.oracle.com/graalvm' const GRAALVM_CE_DL_BASE = `https://github.com/graalvm/${c.GRAALVM_RELEASES_REPO}/releases/download` +const ORACLE_GRAALVM_REPO_EA_BUILDS = 'oracle-graalvm-dev-builds' const GRAALVM_REPO_DEV_BUILDS = 'graalvm-ce-dev-builds' const GRAALVM_JDK_TAG_PREFIX = 'jdk-' const GRAALVM_TAG_PREFIX = 'vm-' @@ -45,6 +47,8 @@ export async function setUpGraalVMJDK( `java-version set to '${javaVersion}'. Please make sure the java-version is set correctly. ${c.ERROR_HINT}` ) } + } else if (javaVersion === '22-ea') { + downloadUrl = await findLatestEABuildDownloadUrl(javaVersion) } else { downloadUrl = `${GRAALVM_DL_BASE}/${javaVersion}/latest/${toolName}${c.GRAALVM_FILE_EXTENSION}` } @@ -52,6 +56,27 @@ export async function setUpGraalVMJDK( return downloadExtractAndCacheJDK(downloader, toolName, javaVersion) } +async function findLatestEABuildDownloadUrl( + javaEaVersion: string +): Promise { + const latestPrerelease = await getLatestPrerelease( + ORACLE_GRAALVM_REPO_EA_BUILDS + ) + const expectedFileNamePrefix = 'graalvm-jdk-' + const expectedFileNameSuffix = `_${c.JDK_PLATFORM}-${c.JDK_ARCH}_bin${c.GRAALVM_FILE_EXTENSION}` + for (const asset of latestPrerelease.assets) { + if ( + asset.name.startsWith(expectedFileNamePrefix) && + asset.name.endsWith(expectedFileNameSuffix) + ) { + return asset.browser_download_url + } + } + throw new Error( + `Could not find Oracle GraalVM build for ${javaEaVersion}. ${c.ERROR_HINT}` + ) +} + export async function setUpGraalVMJDKCE( javaVersionOrDev: string ): Promise { diff --git a/src/utils.ts b/src/utils.ts index 0288dad..1934e56 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -33,6 +33,25 @@ export async function exec( } } +export async function getLatestPrerelease( + repo: string +): Promise { + const githubToken = getGitHubToken() + const options = githubToken.length > 0 ? {auth: githubToken} : {} + const octokit = new GitHubDotCom(options) + const releases: c.ReleasesResponse['data'] = ( + await octokit.request('GET /repos/{owner}/{repo}/releases', { + owner: c.GRAALVM_GH_USER, + repo + }) + ).data + const firstPrerelease = releases.find(r => r.prerelease) + if (!firstPrerelease) { + throw new Error(`Unable to find latest prerelease in ${repo}`) + } + return firstPrerelease +} + export async function getLatestRelease( repo: string ): Promise {