Skip to content

Commit

Permalink
Add support for Mandrel.
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed Jan 4, 2022
1 parent 7a1abed commit eff06ea
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 9 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ jobs:
java-version: '17'
components: 'native-image'
os: windows-2016
- version: 'mandrel-latest'
java-version: '11'
components: ''
os: ubuntu-latest
- version: 'mandrel-21.3.0.0-Final'
java-version: '17'
components: ''
os: windows-latest
steps:
- uses: actions/checkout@v2
- name: Run setup-graalvm action
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This GitHub action sets up [GraalVM Community Edition][repo] and GraalVM compone

This action:

- supports GraalVM CE [releases], [dev builds][dev-builds], and building from [source][repo] (see [options](#options))
- supports GraalVM CE [releases], [dev builds][dev-builds], building from [source][repo], and [Mandrel][mandrel] (see [options](#options))
- has built-in support for GraalVM components and the [GraalVM updater][gu]
- exports a `$GRAALVM_HOME` environment variable
- adds `$GRAALVM_HOME/bin` to the `$PATH` environment variable<br>(GraalVM tools such as `gu` and GraalVM languages can be invoked directly)
Expand Down Expand Up @@ -89,7 +89,7 @@ jobs:
| Name | Default | Description |
|-----------------|:--------:|-------------|
| `version`<br>*(required)* | n/a | `X.Y.Z` (e.g., `22.0.0`) for a specific [GraalVM release][releases]<br>`latest` for [latest stable release][stable],<br>`dev` for [latest dev build][dev-build],<br>`trunk` for building GraalVM from [source][repo] (slow, can take several minutes). |
| `version`<br>*(required)* | n/a | `X.Y.Z` (e.g., `22.0.0`) for a specific [GraalVM release][releases]<br>`latest` for [latest stable release][stable],<br>`dev` for [latest dev build][dev-build],<br>`trunk` for building GraalVM from [source][repo] (slow, can take several minutes),<br>`mandrel-X.Y.Z` (e.g., `mandrel-21.3.0.0-Final`) for a specific [Mandrel release][mandrel-releases], or<br>`mandrel-latest` for [latest Mandrel stable release][mandrel-stable]. |
| `java-version`<br>*(required)* | n/a | `'11'` or `'17'` for a specific Java version.<br>(`'8'` and `'16'` are supported for GraalVM 21.2 and earlier.) |
| `components` | `''` | Comma-spearated list of GraalVM components (e.g., `native-image` or `ruby,nodejs`) that will be installed by the [GraalVM Updater][gu]. |
| `github-token` | `''` | Token for communication with the GitHub API. Please set to `${{ secrets.GITHUB_TOKEN }}` (see [templates](#templates)) to allow the action to authenticate with the GitHub API, which helps to reduce rate limiting issues. |
Expand All @@ -106,6 +106,9 @@ Only pull requests from committers that can be verified as having signed the OCA
[dev-builds]: https://github.com/graalvm/graalvm-ce-dev-builds
[graalvm-languages]: https://www.graalvm.org/reference-manual/languages/
[gu]: https://www.graalvm.org/reference-manual/graalvm-updater/
[mandrel]: https://github.com/graalvm/mandrel
[mandrel-releases]: https://github.com/graalvm/mandrel/releases
[mandrel-stable]: https://github.com/graalvm/mandrel/releases/latest
[native-image]: https://www.graalvm.org/native-image/
[oca]: https://oca.opensource.oracle.com
[releases]: https://github.com/graalvm/graalvm-ce-builds/releases
Expand Down
95 changes: 93 additions & 2 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ export const GRAALVM_GH_USER = 'graalvm'
export const GRAALVM_PLATFORM = IS_WINDOWS ? 'windows' : process.platform
export const JDK_HOME_SUFFIX = IS_MACOS ? '/Contents/Home' : ''

export const MANDREL_NAMESPACE = 'mandrel-'

export type LatestReleaseResponse =
otypes.Endpoints['GET /repos/{owner}/{repo}/releases/latest']['response']
17 changes: 13 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {mkdirP} from '@actions/io'
import {setUpDependencies} from './dependencies'
import {setUpGUComponents} from './gu'
import {setUpGraalVMTrunk} from './graalvm-trunk'
import {setUpMandrel} from './mandrel'
import {setUpWindowsEnvironment} from './msvc'

async function run(): Promise<void> {
Expand Down Expand Up @@ -37,10 +38,14 @@ async function run(): Promise<void> {
graalVMHome = await setUpGraalVMTrunk(javaVersion, components)
break
default:
graalVMHome = await graalvm.setUpGraalVMRelease(
graalvmVersion,
javaVersion
)
if (graalvmVersion.startsWith(c.MANDREL_NAMESPACE)) {
graalVMHome = await setUpMandrel(graalvmVersion, javaVersion)
} else {
graalVMHome = await graalvm.setUpGraalVMRelease(
graalvmVersion,
javaVersion
)
}
break
}

Expand All @@ -56,6 +61,10 @@ async function run(): Promise<void> {
if (components.length > 0) {
if (graalvmVersion === c.VERSION_TRUNK) {
// components built from source, nothing to do
} else if (graalvmVersion.startsWith(c.MANDREL_NAMESPACE)) {
core.warning(
`Mandrel does not support GraalVM components: ${componentsString}`
)
} else {
await setUpGUComponents(graalVMHome, components)
}
Expand Down
57 changes: 57 additions & 0 deletions src/mandrel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import * as c from './constants'
import {downloadAndExtractJDK, getLatestRelease} from './utils'

const MANDREL_REPO = 'mandrel'
const MANDREL_TAG_PREFIX = c.MANDREL_NAMESPACE
const MANDREL_DL_BASE = 'https://github.com/graalvm/mandrel/releases/download'

export async function setUpMandrel(
graalvmVersion: string,
javaVersion: string
): Promise<string> {
const mandrelVersion = graalvmVersion.substring(
c.MANDREL_NAMESPACE.length,
graalvmVersion.length
)

let mandrelHome
switch (mandrelVersion) {
case 'latest':
mandrelHome = await setUpMandrelLatest(javaVersion)
break
default:
mandrelHome = await setUpMandrelRelease(mandrelVersion, javaVersion)
break
}

return mandrelHome
}

async function setUpMandrelLatest(javaVersion: string): Promise<string> {
const latestRelease = await getLatestRelease(MANDREL_REPO)
const tag_name = latestRelease.tag_name
if (tag_name.startsWith(MANDREL_TAG_PREFIX)) {
const latestVersion = tag_name.substring(
MANDREL_TAG_PREFIX.length,
tag_name.length
)
return setUpMandrelRelease(latestVersion, javaVersion)
}
throw new Error(`Could not find latest Mandrel release: ${tag_name}`)
}

async function setUpMandrelRelease(
version: string,
javaVersion: string
): Promise<string> {
const identifier = determineMandrelIdentifier(version, javaVersion)
const downloadUrl = `${MANDREL_DL_BASE}/${MANDREL_TAG_PREFIX}${version}/${identifier}${c.GRAALVM_FILE_EXTENSION}`
return downloadAndExtractJDK(downloadUrl)
}

function determineMandrelIdentifier(
version: string,
javaVersion: string
): string {
return `mandrel-java${javaVersion}-${c.GRAALVM_PLATFORM}-amd64-${version}`
}

0 comments on commit eff06ea

Please sign in to comment.