Files
setup-graalvm/src/features.ts

81 lines
2.7 KiB
TypeScript
Raw Normal View History

2022-11-02 14:00:51 +01:00
import * as c from './constants'
2022-01-20 17:49:45 +01:00
import * as core from '@actions/core'
import * as tc from '@actions/tool-cache'
2022-11-02 14:00:51 +01:00
import {exec, toSemVer} from './utils'
2022-01-20 17:49:45 +01:00
import {join} from 'path'
2022-11-02 14:00:51 +01:00
import {lt, major, minor, valid} from 'semver'
import {getLatestReleaseVersion} from './graalvm'
2022-03-01 11:45:43 +01:00
const MUSL_NAME = 'x86_64-linux-musl-native'
const MUSL_VERSION = '10.2.1'
2022-01-20 17:49:45 +01:00
2022-11-02 14:00:51 +01:00
export async function checkForUpdates(
graalVMVersion: string,
javaVersion: string
): Promise<void> {
if (graalVMVersion === '22.3.0' && javaVersion === '11') {
core.notice(
'Please consider upgrading your project to Java 17+. The GraalVM 22.3.0 release is the last to support JDK11: https://github.com/oracle/graal/issues/5063'
)
return
}
const latestGraalVMVersion = await getLatestReleaseVersion()
const selectedVersion = toSemVer(graalVMVersion)
const latestVersion = toSemVer(latestGraalVMVersion)
if (
valid(selectedVersion) &&
valid(latestVersion) &&
lt(selectedVersion, latestVersion)
) {
core.notice(
`A new GraalVM release is available! Please consider upgrading to GraalVM ${latestGraalVMVersion}. Release notes: https://www.graalvm.org/release-notes/${major(
latestVersion
)}_${minor(latestVersion)}/`
)
}
}
2022-01-20 17:49:45 +01:00
export async function setUpNativeImageMusl(): Promise<void> {
2022-11-02 14:00:51 +01:00
if (!c.IS_LINUX) {
2022-01-20 17:49:45 +01:00
core.warning('musl is only supported on Linux')
return
}
2022-03-01 11:45:43 +01:00
let toolPath = tc.find(MUSL_NAME, MUSL_VERSION)
if (toolPath) {
core.info(`Found ${MUSL_NAME} ${MUSL_VERSION} in tool-cache @ ${toolPath}`)
} else {
core.startGroup(`Setting up musl for GraalVM Native Image...`)
const muslDownloadPath = await tc.downloadTool(
2022-08-03 17:05:41 +02:00
`https://github.com/graalvm/setup-graalvm/releases/download/x86_64-linux-musl-${MUSL_VERSION}/${MUSL_NAME}.tgz`
2022-03-01 11:45:43 +01:00
)
const muslExtractPath = await tc.extractTar(muslDownloadPath)
const muslPath = join(muslExtractPath, MUSL_NAME)
2022-01-20 17:49:45 +01:00
const zlibCommit = 'ec3df00224d4b396e2ac6586ab5d25f673caa4c2'
2022-03-01 11:45:43 +01:00
const zlibDownloadPath = await tc.downloadTool(
`https://github.com/madler/zlib/archive/${zlibCommit}.tar.gz`
2022-03-01 11:45:43 +01:00
)
const zlibExtractPath = await tc.extractTar(zlibDownloadPath)
const zlibPath = join(zlibExtractPath, `zlib-${zlibCommit}`)
2022-03-01 11:45:43 +01:00
const zlibBuildOptions = {
cwd: zlibPath,
env: {
...process.env,
CC: join(muslPath, 'bin', 'gcc')
}
2022-01-20 17:49:45 +01:00
}
2022-03-01 11:45:43 +01:00
await exec(
'./configure',
[`--prefix=${muslPath}`, '--static'],
zlibBuildOptions
)
await exec('make', [], zlibBuildOptions)
await exec('make', ['install'], {cwd: zlibPath})
core.info(`Adding ${MUSL_NAME} ${MUSL_VERSION} to tool-cache ...`)
toolPath = await tc.cacheDir(muslPath, MUSL_NAME, MUSL_VERSION)
core.endGroup()
2022-01-20 17:49:45 +01:00
}
2022-03-01 11:45:43 +01:00
core.addPath(join(toolPath, 'bin'))
2022-01-20 17:49:45 +01:00
}