Skip to content

Commit

Permalink
Prepare for deprecation of GraalVM Updater.
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed Sep 6, 2023
1 parent c569e64 commit 265e018
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 21 deletions.
32 changes: 32 additions & 0 deletions src/gu.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import * as c from './constants'
import * as core from '@actions/core'
import {GRAALVM_PLATFORM} from './constants'
import {exec} from './utils'
import {join} from 'path'
import {gte as semverGte, valid as semverValid} from 'semver'

const BASE_FLAGS = ['--non-interactive', 'install', '--no-progress']
const COMPONENT_TO_POST_INSTALL_HOOK = new Map<string, Map<string, string>>([
Expand All @@ -22,6 +25,35 @@ const COMPONENT_TO_POST_INSTALL_HOOK = new Map<string, Map<string, string>>([
])

export async function setUpGUComponents(
javaVersion: string,
graalVMVersion: string,
graalVMHome: string,
components: string[],
gdsToken: string
): Promise<void> {
if (components.length == 0) {
return // nothing to do
}
if (
graalVMVersion === c.VERSION_DEV ||
javaVersion === c.VERSION_DEV ||
(semverValid(javaVersion) && semverGte(javaVersion, '21'))
) {
core.warning(
`Unable to install component(s): '${components.join(
','
)}'. The latest GraalVM dev builds and the upcoming GraalVM for JDK 21 no longer include the GraalVM Updater: https://github.com/oracle/graal/issues/6855`
)
} else if (graalVMVersion.startsWith(c.MANDREL_NAMESPACE)) {
core.warning(
`Mandrel does not support GraalVM component(s): '${components.join(',')}'`
)
} else {
await installGUComponents(gdsToken, graalVMHome, components)
}
}

async function installGUComponents(
gdsToken: string,
graalVMHome: string,
components: string[]
Expand Down
39 changes: 18 additions & 21 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async function run(): Promise<void> {
try {
const javaVersion = core.getInput(c.INPUT_JAVA_VERSION, {required: true})
const distribution = core.getInput(c.INPUT_DISTRIBUTION)
const graalvmVersion = core.getInput(c.INPUT_VERSION)
const graalVMVersion = core.getInput(c.INPUT_VERSION)
const gdsToken = core.getInput(c.INPUT_GDS_TOKEN)
const componentsString: string = core.getInput(c.INPUT_COMPONENTS)
const components: string[] =
Expand All @@ -31,7 +31,7 @@ async function run(): Promise<void> {
const enableNativeImageMusl = core.getInput(c.INPUT_NI_MUSL) === 'true'

if (c.IS_WINDOWS) {
setUpWindowsEnvironment(graalvmVersion)
setUpWindowsEnvironment(graalVMVersion)
}
await setUpDependencies(components)
if (enableNativeImageMusl) {
Expand All @@ -40,7 +40,7 @@ async function run(): Promise<void> {

// Download GraalVM JDK
const isGraalVMforJDK17OrLater =
distribution.length > 0 || graalvmVersion.length == 0
distribution.length > 0 || graalVMVersion.length == 0
let graalVMHome
if (isGraalVMforJDK17OrLater) {
switch (distribution) {
Expand All @@ -51,8 +51,8 @@ async function run(): Promise<void> {
graalVMHome = await graalvm.setUpGraalVMJDKCE(javaVersion)
break
case c.DISTRIBUTION_MANDREL:
if (graalvmVersion.startsWith(c.MANDREL_NAMESPACE)) {
graalVMHome = await setUpMandrel(graalvmVersion, javaVersion)
if (graalVMVersion.startsWith(c.MANDREL_NAMESPACE)) {
graalVMHome = await setUpMandrel(graalVMVersion, javaVersion)
} else {
throw new Error(
`Mandrel requires the 'version' option (see https://github.com/graalvm/setup-graalvm/tree/main#options).`
Expand All @@ -76,7 +76,7 @@ async function run(): Promise<void> {
throw new Error(`Unsupported distribution: ${distribution}`)
}
} else {
switch (graalvmVersion) {
switch (graalVMVersion) {
case c.VERSION_LATEST:
if (
javaVersion.startsWith('17') ||
Expand All @@ -102,15 +102,15 @@ async function run(): Promise<void> {
graalVMHome = await graalvm.setUpGraalVMJDKDevBuild()
break
default:
if (graalvmVersion.startsWith(c.MANDREL_NAMESPACE)) {
graalVMHome = await setUpMandrel(graalvmVersion, javaVersion)
if (graalVMVersion.startsWith(c.MANDREL_NAMESPACE)) {
graalVMHome = await setUpMandrel(graalVMVersion, javaVersion)
} else {
if (enableCheckForUpdates) {
await checkForUpdates(graalvmVersion, javaVersion)
await checkForUpdates(graalVMVersion, javaVersion)
}
graalVMHome = await graalvm.setUpGraalVMRelease(
gdsToken,
graalvmVersion,
graalVMVersion,
javaVersion
)
}
Expand All @@ -126,21 +126,18 @@ async function run(): Promise<void> {
core.exportVariable('JAVA_HOME', graalVMHome)
}

// Set up GraalVM components (if any)
if (components.length > 0) {
if (graalvmVersion.startsWith(c.MANDREL_NAMESPACE)) {
core.warning(
`Mandrel does not support GraalVM components: ${componentsString}`
)
} else {
await setUpGUComponents(gdsToken, graalVMHome, components)
}
}
await setUpGUComponents(
javaVersion,
graalVMVersion,
graalVMHome,
components,
gdsToken
)

if (cache && isCacheAvailable()) {
await restore(cache)
}
setUpNativeImageBuildReports(isGraalVMforJDK17OrLater, graalvmVersion)
setUpNativeImageBuildReports(isGraalVMforJDK17OrLater, graalVMVersion)
} catch (error) {
if (error instanceof Error) core.setFailed(error.message)
}
Expand Down

0 comments on commit 265e018

Please sign in to comment.