2025-02-10 09:04:34 +01:00
import * as c from './constants.js'
2023-09-06 09:08:02 +02:00
import * as core from '@actions/core'
2023-09-20 12:59:33 +02:00
import * as semver from 'semver'
2025-02-10 09:16:33 +01:00
import { GRAALVM_PLATFORM } from './constants.js'
import { exec } from './utils.js'
import { join } from 'path'
2022-01-03 08:57:03 +01:00
2022-03-03 17:24:24 +01:00
const BASE_FLAGS = [ '--non-interactive' , 'install' , '--no-progress' ]
2022-01-03 08:57:03 +01:00
const COMPONENT_TO_POST_INSTALL_HOOK = new Map < string , Map < string , string > > ( [
[
'linux' ,
new Map < string , string > ( [
[ 'ruby' , 'languages/ruby/lib/truffle/post_install_hook.sh' ]
// ['R', 'languages/R/bin/configure_fastr'] (GR-36105: cannot be run non-interactively)
] )
] ,
[
'darwin' ,
new Map < string , string > ( [
[ 'ruby' , 'languages/ruby/lib/truffle/post_install_hook.sh' ]
// ['R', 'languages/R/bin/configure_fastr'] (GR-36105: cannot be run non-interactively)
] )
]
// No post install hooks for Windows (yet)
] )
export async function setUpGUComponents (
2023-09-06 09:08:02 +02:00
javaVersion : string ,
graalVMVersion : string ,
graalVMHome : string ,
components : string [ ] ,
gdsToken : string
) : Promise < void > {
if ( components . length == 0 ) {
return // nothing to do
}
2023-09-20 12:59:33 +02:00
const coercedJavaVersion = semver . coerce ( javaVersion )
2023-09-06 09:08:02 +02:00
if (
graalVMVersion === c . VERSION_DEV ||
javaVersion === c . VERSION_DEV ||
2023-09-20 12:59:33 +02:00
( coercedJavaVersion != null && semver . gte ( coercedJavaVersion , '21.0.0' ) )
2023-09-06 09:08:02 +02:00
) {
2023-09-06 10:37:50 +02:00
if ( components . length == 1 && components [ 0 ] === 'native-image' ) {
core . warning (
` Please remove "components: 'native-image'" from your workflow file. It is automatically included since GraalVM for JDK 17: https://github.com/oracle/graal/pull/5995 `
)
} else {
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`
)
}
2023-09-06 09:08:02 +02:00
} else if ( graalVMVersion . startsWith ( c . MANDREL_NAMESPACE ) ) {
2025-02-10 09:16:33 +01:00
core . warning ( ` Mandrel does not support GraalVM component(s): ' ${ components . join ( ',' ) } ' ` )
2023-09-06 09:08:02 +02:00
} else {
await installGUComponents ( gdsToken , graalVMHome , components )
}
}
2025-02-10 09:16:33 +01:00
async function installGUComponents ( gdsToken : string , graalVMHome : string , components : string [ ] ) : Promise < void > {
2022-04-19 21:27:19 +02:00
await exec ( 'gu' , BASE_FLAGS . concat ( components ) , {
env : {
. . . process . env ,
GRAAL_EE_DOWNLOAD_TOKEN : gdsToken
}
} )
2022-01-03 08:57:03 +01:00
const platformHooks = COMPONENT_TO_POST_INSTALL_HOOK . get ( GRAALVM_PLATFORM )
if ( platformHooks ) {
for ( const component of components ) {
const postInstallHook = platformHooks . get ( component )
if ( postInstallHook ) {
await exec ( ` " ${ join ( graalVMHome , postInstallHook ) } " ` )
}
}
}
}