Skip to content

Commit

Permalink
Add initial support for early access (EA) builds.
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed Feb 13, 2024
1 parent a638430 commit 2408275
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ jobs:
]
components: ['']
include:
- java-version: '22-ea'
distribution: 'graalvm'
os: ubuntu-latest
- java-version: '21'
distribution: ''
os: ubuntu-latest
Expand Down
19 changes: 18 additions & 1 deletion dist/cleanup/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 36 additions & 1 deletion dist/main/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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': {
Expand Down
25 changes: 25 additions & 0 deletions src/graalvm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as semver from 'semver'
import {
downloadAndExtractJDK,
downloadExtractAndCacheJDK,
getLatestPrerelease,
getLatestRelease,
getMatchingTags,
getTaggedRelease
Expand All @@ -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-'
Expand Down Expand Up @@ -45,13 +47,36 @@ 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}`
}
const downloader = async () => downloadGraalVMJDK(downloadUrl, javaVersion)
return downloadExtractAndCacheJDK(downloader, toolName, javaVersion)
}

async function findLatestEABuildDownloadUrl(
javaEaVersion: string
): Promise<string> {
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<string> {
Expand Down
19 changes: 19 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,25 @@ export async function exec(
}
}

export async function getLatestPrerelease(
repo: string
): Promise<c.ReleasesResponse['data'][number]> {
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<c.LatestReleaseResponse['data']> {
Expand Down

0 comments on commit 2408275

Please sign in to comment.