2022-01-03 08:52:11 +01:00
|
|
|
import * as c from './constants'
|
2022-03-01 10:50:00 +01:00
|
|
|
import {
|
|
|
|
downloadAndExtractJDK,
|
|
|
|
downloadExtractAndCacheJDK,
|
|
|
|
getLatestRelease
|
|
|
|
} from './utils'
|
2022-03-03 17:24:24 +01:00
|
|
|
import {downloadGraalVMEE} from './gds'
|
|
|
|
import {downloadTool} from '@actions/tool-cache'
|
2022-01-03 08:52:11 +01:00
|
|
|
|
|
|
|
const GRAALVM_CE_DL_BASE =
|
|
|
|
'https://github.com/graalvm/graalvm-ce-builds/releases/download'
|
2022-01-03 13:11:04 +01:00
|
|
|
const GRAALVM_REPO_DEV_BUILDS = 'graalvm-ce-dev-builds'
|
2022-01-03 08:52:11 +01:00
|
|
|
const GRAALVM_REPO_RELEASES = 'graalvm-ce-builds'
|
|
|
|
const GRAALVM_TAG_PREFIX = 'vm-'
|
|
|
|
|
2022-03-03 17:24:24 +01:00
|
|
|
export async function setUpGraalVMLatest(
|
|
|
|
gdsToken: string,
|
|
|
|
javaVersion: string
|
|
|
|
): Promise<string> {
|
|
|
|
if (gdsToken.length > 0) {
|
|
|
|
return setUpGraalVMRelease(gdsToken, c.VERSION_LATEST, javaVersion)
|
|
|
|
}
|
2022-01-03 08:52:11 +01:00
|
|
|
const latestRelease = await getLatestRelease(GRAALVM_REPO_RELEASES)
|
|
|
|
const tag_name = latestRelease.tag_name
|
|
|
|
if (tag_name.startsWith(GRAALVM_TAG_PREFIX)) {
|
|
|
|
const latestVersion = tag_name.substring(
|
|
|
|
GRAALVM_TAG_PREFIX.length,
|
|
|
|
tag_name.length
|
|
|
|
)
|
2022-03-03 17:24:24 +01:00
|
|
|
return setUpGraalVMRelease(gdsToken, latestVersion, javaVersion)
|
2022-01-03 08:52:11 +01:00
|
|
|
}
|
|
|
|
throw new Error(`Could not find latest GraalVM release: ${tag_name}`)
|
|
|
|
}
|
|
|
|
|
2022-01-03 13:11:04 +01:00
|
|
|
export async function setUpGraalVMDevBuild(
|
2022-03-03 17:24:24 +01:00
|
|
|
gdsToken: string,
|
2022-01-03 08:52:11 +01:00
|
|
|
javaVersion: string
|
|
|
|
): Promise<string> {
|
2022-03-03 17:24:24 +01:00
|
|
|
if (gdsToken.length > 0) {
|
|
|
|
throw new Error('Downloading GraalVM EE dev builds is not supported')
|
|
|
|
}
|
2022-01-03 13:11:04 +01:00
|
|
|
const latestDevBuild = await getLatestRelease(GRAALVM_REPO_DEV_BUILDS)
|
2022-03-03 17:24:24 +01:00
|
|
|
const graalVMIdentifier = determineGraalVMIdentifier(
|
|
|
|
false,
|
|
|
|
'dev',
|
|
|
|
javaVersion
|
|
|
|
)
|
2022-01-03 08:52:11 +01:00
|
|
|
const expectedFileName = `${graalVMIdentifier}${c.GRAALVM_FILE_EXTENSION}`
|
2022-01-03 13:11:04 +01:00
|
|
|
for (const asset of latestDevBuild.assets) {
|
2022-01-03 08:52:11 +01:00
|
|
|
if (asset.name === expectedFileName) {
|
|
|
|
return downloadAndExtractJDK(asset.browser_download_url)
|
|
|
|
}
|
|
|
|
}
|
2022-01-03 13:11:04 +01:00
|
|
|
throw new Error('Could not find GraalVM dev build')
|
2022-01-03 08:52:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function setUpGraalVMRelease(
|
2022-03-03 17:24:24 +01:00
|
|
|
gdsToken: string,
|
2022-01-03 08:52:11 +01:00
|
|
|
version: string,
|
|
|
|
javaVersion: string
|
|
|
|
): Promise<string> {
|
2022-03-03 17:24:24 +01:00
|
|
|
const isEE = gdsToken.length > 0
|
|
|
|
const graalVMIdentifier = determineGraalVMIdentifier(
|
|
|
|
isEE,
|
|
|
|
version,
|
|
|
|
javaVersion
|
|
|
|
)
|
|
|
|
const toolName = determineToolName(isEE, javaVersion)
|
|
|
|
let downloader: () => Promise<string>
|
|
|
|
if (isEE) {
|
|
|
|
downloader = async () => downloadGraalVMEE(gdsToken, version, javaVersion)
|
|
|
|
} else {
|
|
|
|
const downloadUrl = `${GRAALVM_CE_DL_BASE}/${GRAALVM_TAG_PREFIX}${version}/${graalVMIdentifier}${c.GRAALVM_FILE_EXTENSION}`
|
|
|
|
downloader = async () => downloadTool(downloadUrl)
|
|
|
|
}
|
|
|
|
return downloadExtractAndCacheJDK(downloader, toolName, version)
|
2022-01-03 08:52:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function determineGraalVMIdentifier(
|
2022-03-03 17:24:24 +01:00
|
|
|
isEE: boolean,
|
2022-01-03 08:52:11 +01:00
|
|
|
version: string,
|
|
|
|
javaVersion: string
|
|
|
|
): string {
|
2022-03-03 17:24:24 +01:00
|
|
|
return `graalvm-${isEE ? 'ee' : 'ce'}-java${javaVersion}-${
|
|
|
|
c.GRAALVM_PLATFORM
|
|
|
|
}-${c.GRAALVM_ARCH}-${version}`
|
2022-01-03 08:52:11 +01:00
|
|
|
}
|
2022-03-01 10:50:00 +01:00
|
|
|
|
2022-03-03 17:24:24 +01:00
|
|
|
function determineToolName(isEE: boolean, javaVersion: string): string {
|
|
|
|
return `graalvm-${isEE ? 'ee' : 'ce'}-java${javaVersion}-${
|
|
|
|
c.GRAALVM_PLATFORM
|
|
|
|
}`
|
2022-03-01 10:50:00 +01:00
|
|
|
}
|