2022-01-03 08:52:11 +01:00
import * as c from './constants'
2022-01-03 08:43:40 +01:00
import * as core from '@actions/core'
2022-01-03 08:52:11 +01:00
import * as graalvm from './graalvm'
import { join } from 'path'
import { mkdirP } from '@actions/io'
2022-01-03 08:54:37 +01:00
import { setUpDependencies } from './dependencies'
2022-01-03 08:57:03 +01:00
import { setUpGUComponents } from './gu'
2022-01-03 08:52:11 +01:00
import { setUpGraalVMTrunk } from './graalvm-trunk'
2022-01-03 09:00:36 +01:00
import { setUpMandrel } from './mandrel'
2022-01-03 08:53:37 +01:00
import { setUpWindowsEnvironment } from './msvc'
2022-01-03 08:43:40 +01:00
async function run ( ) : Promise < void > {
try {
2022-01-03 08:52:11 +01:00
const graalvmVersion : string = core . getInput ( 'version' , { required : true } )
const javaVersion : string = core . getInput ( 'java-version' , { required : true } )
const componentsString : string = core . getInput ( 'components' )
const components : string [ ] =
componentsString . length > 0 ? componentsString . split ( ',' ) : [ ]
const setJavaHome = core . getInput ( 'set-java-home' ) === 'true'
2022-01-03 08:53:37 +01:00
if ( c . IS_WINDOWS ) {
setUpWindowsEnvironment ( )
}
2022-01-03 08:54:37 +01:00
setUpDependencies ( components )
2022-01-03 08:53:37 +01:00
2022-01-03 08:52:11 +01:00
await mkdirP ( c . GRAALVM_BASE )
// Download or build GraalVM
2022-01-03 08:43:40 +01:00
let graalVMHome
2022-01-03 08:52:11 +01:00
switch ( graalvmVersion ) {
case c . VERSION_LATEST :
graalVMHome = await graalvm . setUpGraalVMLatest ( javaVersion )
break
2022-01-03 13:11:04 +01:00
case c . VERSION_DEV :
graalVMHome = await graalvm . setUpGraalVMDevBuild ( javaVersion )
2022-01-03 08:52:11 +01:00
break
case c . VERSION_TRUNK :
2022-01-05 12:51:41 +01:00
core . warning (
"Building GraalVM from source is deprecated and will be removed on Jan 10, 2022. Please use the latest dev build instead (version: 'dev'). For more details see https://github.com/graalvm/setup-graalvm/issues/3"
)
2022-01-03 08:52:11 +01:00
graalVMHome = await setUpGraalVMTrunk ( javaVersion , components )
break
default :
2022-01-03 09:00:36 +01:00
if ( graalvmVersion . startsWith ( c . MANDREL_NAMESPACE ) ) {
graalVMHome = await setUpMandrel ( graalvmVersion , javaVersion )
} else {
graalVMHome = await graalvm . setUpGraalVMRelease (
graalvmVersion ,
javaVersion
)
}
2022-01-03 08:52:11 +01:00
break
}
// Activate GraalVM
core . debug ( ` Activating GraalVM located at ' ${ graalVMHome } '... ` )
2022-01-03 08:43:40 +01:00
core . exportVariable ( 'GRAALVM_HOME' , graalVMHome )
2022-01-03 08:52:11 +01:00
core . addPath ( join ( graalVMHome , 'bin' ) )
if ( setJavaHome ) {
core . exportVariable ( 'JAVA_HOME' , graalVMHome )
}
2022-01-03 08:57:03 +01:00
// Set up GraalVM components (if any)
if ( components . length > 0 ) {
if ( graalvmVersion === c . VERSION_TRUNK ) {
// components built from source, nothing to do
2022-01-03 09:00:36 +01:00
} else if ( graalvmVersion . startsWith ( c . MANDREL_NAMESPACE ) ) {
core . warning (
` Mandrel does not support GraalVM components: ${ componentsString } `
)
2022-01-03 08:57:03 +01:00
} else {
await setUpGUComponents ( graalVMHome , components )
}
}
2022-01-03 08:43:40 +01:00
} catch ( error ) {
if ( error instanceof Error ) core . setFailed ( error . message )
}
}
run ( )