2022-01-03 09:01:37 +01:00
# GitHub Action for GraalVM [![build-test](https://github.com/graalvm/setup-graalvm/actions/workflows/test.yml/badge.svg)](https://github.com/graalvm/setup-graalvm/actions/workflows/test.yml)
2023-06-16 12:59:57 +02:00
This GitHub action sets up [Oracle GraalVM][graalvm-medium], GraalVM [Community Edition (CE)][repo], [Enterprise Edition (EE)][graalvm-ee], or [Mandrel][mandrel], as well as [Native Image][native-image] and GraalVM components such as [Truffle languages][truffle-languages].
2022-01-03 09:01:37 +01:00
## Key Features
This action:
2024-02-22 10:41:51 +01:00
- supports Oracle GraalVM [releases][graalvm-dl], [EA builds][ea-builds], GraalVM Community Edition (CE) [releases], [dev builds][dev-builds], GraalVM Enterprise Edition (EE) [releases][graalvm-ee] (set [`gds-token` ](#options )) 22.1.0 and later, and [Mandrel][mandrel] (see [Options ](#options ))
2022-01-03 09:01:37 +01:00
- exports a `$GRAALVM_HOME` environment variable
2023-06-16 09:19:49 +02:00
- adds `$GRAALVM_HOME/bin` to the `$PATH` environment variable< br > (Native Image, Truffle languages, and tools can be invoked directly)
- sets `$JAVA_HOME` to `$GRAALVM_HOME` by default< br > (can be disabled via `set-java-home: 'false'` , see [Options ](#options ))
- supports `x64` and `aarch64` (selected automatically, `aarch64` requires a [self-hosted runner][gha-self-hosted-runners])
2022-08-31 10:34:47 +02:00
- supports dependency caching for Apache Maven, Gradle, and sbt (see [`cache` option ](#options ))
2023-06-16 09:19:49 +02:00
- sets up Windows environments with build tools using [vcvarsall.bat][vcvarsall]
- has built-in support for GraalVM components and the [GraalVM Updater][gu]
2022-01-03 09:01:37 +01:00
## Templates
### Quickstart Template
```yml
2023-06-16 09:19:49 +02:00
name: GraalVM build
2022-01-03 09:01:37 +01:00
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
2023-09-19 14:30:35 +02:00
- uses: actions/checkout@v4
2022-01-03 09:01:37 +01:00
- uses: graalvm/setup-graalvm@v1
with:
2024-02-22 10:41:51 +01:00
java-version: '21' # See 'Options' section below for all supported versions
distribution: 'graalvm' # See 'Options' section below for all available distributions
2022-01-03 09:01:37 +01:00
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Example step
run: |
echo "GRAALVM_HOME: $GRAALVM_HOME"
echo "JAVA_HOME: $JAVA_HOME"
java --version
native-image --version
2023-06-16 09:19:49 +02:00
- name: Example step using Maven plugin # https://graalvm.github.io/native-build-tools/latest/maven-plugin.html
run: mvn -Pnative package
- name: Example step using Gradle plugin # https://graalvm.github.io/native-build-tools/latest/gradle-plugin.html
run: gradlew nativeCompile
2022-01-03 09:01:37 +01:00
```
2022-03-30 14:41:52 +02:00
### Building a HelloWorld with GraalVM Native Image on Different Platforms
2022-01-03 09:01:37 +01:00
```yml
2022-04-20 11:54:31 +02:00
name: GraalVM Native Image builds
2022-01-03 09:01:37 +01:00
on: [push, pull_request]
jobs:
build:
2022-03-30 18:48:08 +02:00
name: HelloWorld on ${{ matrix.os }}
2022-01-03 09:01:37 +01:00
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
steps:
2023-09-19 14:30:35 +02:00
- uses: actions/checkout@v4
2022-01-03 09:01:37 +01:00
- uses: graalvm/setup-graalvm@v1
with:
2023-09-19 14:35:08 +02:00
java-version: '21'
2023-06-16 09:19:49 +02:00
distribution: 'graalvm'
2022-01-03 09:01:37 +01:00
github-token: ${{ secrets.GITHUB_TOKEN }}
2022-11-07 10:21:48 +01:00
native-image-job-reports: 'true'
2022-01-03 09:01:37 +01:00
- name: Build and run HelloWorld.java
run: |
2022-03-29 15:23:04 +02:00
echo 'public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); } }' > HelloWorld.java
2022-01-03 09:01:37 +01:00
javac HelloWorld.java
native-image HelloWorld
./helloworld
- name: Upload binary
uses: actions/upload-artifact@v2
with:
2022-03-30 18:48:08 +02:00
name: helloworld-${{ matrix.os }}
2022-01-03 09:01:37 +01:00
path: helloworld*
```
2024-02-22 10:41:51 +01:00
< details >
< summary > < h4 > Template for Oracle GraalVM Early Access (EA) builds< / h4 > < / summary >
```yml
name: Oracle GraalVM Early Access build
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: graalvm/setup-graalvm@v1
with:
2024-02-22 11:11:07 +01:00
java-version: '22-ea' # or 'latest-ea' for the latest Java version available
2024-02-22 10:41:51 +01:00
distribution: 'graalvm'
github-token: ${{ secrets.GITHUB_TOKEN }}
```
< / details >
2023-06-16 09:19:49 +02:00
< details >
< summary > < h4 > Template for older GraalVM releases< / h4 > < / summary >
```yml
name: GraalVM build
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
2023-09-19 14:30:35 +02:00
- uses: actions/checkout@v4
2023-06-16 09:19:49 +02:00
- uses: graalvm/setup-graalvm@v1
with:
version: '22.3.2' # GraalVM version
java-version: '17'
components: 'native-image'
github-token: ${{ secrets.GITHUB_TOKEN }}
```
< / details >
< details >
< summary > < h4 > Template for GraalVM Enterprise Edition< / h4 > < / summary >
2022-03-11 14:06:12 +01:00
#### Prerequisites
1. Download the version of [GraalVM Enterprise Edition (EE)][graalvm-ee] you want to run on GitHub Actions.
2. Use the [GraalVM Updater][gu] to install the GraalVM components you need on GitHub Actions and accept the corresponding licenses.
3. Run `$GRAALVM_HOME/bin/gu --show-ee-token` to display your token for the GraalVM Download Service.
4. Store this token as a [GitHub Action secret][gha-secrets]. For this template, we use the name `GDS_TOKEN` .
```yml
2022-04-20 11:54:31 +02:00
name: GraalVM Enterprise Edition build
2022-03-11 14:06:12 +01:00
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
2023-09-19 14:30:35 +02:00
- uses: actions/checkout@v4
2022-03-11 14:06:12 +01:00
- uses: graalvm/setup-graalvm@v1
with:
2022-10-26 08:42:01 +02:00
version: '22.3.0'
2022-03-11 14:06:12 +01:00
gds-token: ${{ secrets.GDS_TOKEN }}
2022-11-18 09:59:55 +01:00
java-version: '17'
2022-03-11 14:06:12 +01:00
components: 'native-image'
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Example step
run: |
java --version
native-image --version
```
2023-06-16 09:19:49 +02:00
< / details >
2022-01-03 09:01:37 +01:00
2024-02-08 12:05:32 +01:00
## Migrating from GraalVM 22.3 or Earlier to the New GraalVM for JDK 17 and Later
The [GraalVM for JDK 17 and JDK 20 release ](https://medium.com/graalvm/a-new-graalvm-release-and-new-free-license-4aab483692f5 ) aligns the GraalVM version scheme with OpenJDK.
As a result, this action no longer requires the `version` option to select a specific GraalVM version.
At the same time, it introduces a new `distribution` option to select a specific GraalVM distribution (`graalvm` , `graalvm-community` , or `mandrel` ).
Therefore, to migrate your workflow to use the latest GraalVM release, replace the `version` with the `distribution` option in the workflow `yml` config, for example:
```yml
# ...
- uses: graalvm/setup-graalvm@v1
with:
java-version: '17'
version: '22.3.2' # Old 'version' option for the GraalVM version
# ...
```
can be replaced with:
```yml
# ...
- uses: graalvm/setup-graalvm@v1
with:
java-version: '17.0.7' # for a specific JDK 17; or '17' for the latest JDK 17
distribution: 'graalvm' # New 'distribution' option
# ...
```
2022-01-03 09:01:37 +01:00
## Options
| Name | Default | Description |
|-----------------|:--------:|-------------|
2024-02-22 11:11:07 +01:00
| `java-version` < br > *(required)* | n/a | Java version < ul >< li > major versions: `'21'` , `'17'` , `'11'` , `'8'` </ li >< li > specific versions: `'21.0.2'` , `'17.0.7'` </ li >< li > early access (EA) builds: `'22-ea'` *(requires `distribution: 'graalvm'`)* </ li >< li > latest EA build: `'latest-ea'` *(requires `distribution: 'graalvm'`)* </ li >< li > dev builds: `'dev'` </ li ></ ul > |
| `distribution` | `'graalvm'` | GraalVM distribution < ul >< li > Oracle GraalVM: `'graalvm'` </ li >< li > GraalVM Community Edition: `'graalvm-community'` </ li >< li > Mandrel: `'mandrel'` </ li ></ ul > |
2023-06-16 09:19:49 +02:00
| `github-token` | `'${{ github.token }}'` | Token for communication with the GitHub API. Please set this to `${{ secrets.GITHUB_TOKEN }}` (see [templates ](#templates )) to allow the action to authenticate with the GitHub API, which helps reduce rate-limiting issues. |
2022-11-07 10:21:48 +01:00
| `set-java-home` | `'true'` | If set to `'true'` , instructs the action to set `$JAVA_HOME` to the path of the GraalVM installation. Overrides any previous action or command that sets `$JAVA_HOME` . |
2023-06-16 12:14:42 +02:00
| `cache` | `''` | Name of the build platform to cache dependencies. Turned off by default (`''` ). It can also be `'maven'` , `'gradle'` , or `'sbt'` and works the same way as described in [actions/setup-java][setup-java-caching]. |
2023-06-16 09:19:49 +02:00
| `check-for-updates` | `'true'` | [Annotate jobs][gha-annotations] with update notifications, for example when a new GraalVM release is available. |
2022-11-07 10:21:48 +01:00
| `native-image-musl` | `'false'` | If set to `'true'` , sets up [musl] to build [static binaries][native-image-static] with GraalVM Native Image *(Linux only)* . [Example usage][native-image-musl-build] (be sure to replace `uses: ./` with `uses: graalvm/setup-graalvm@v1` ). |
2022-11-18 09:59:55 +01:00
| `native-image-job-reports` *) | `'false'` | If set to `'true'` , post a job summary containing a Native Image build report. |
| `native-image-pr-reports` *) | `'false'` | If set to `'true'` , post a comment containing a Native Image build report on pull requests. Requires `write` permissions for the [`pull-requests` scope][gha-permissions]. |
2023-06-16 09:19:49 +02:00
| `components` | `''` | Comma-separated list of GraalVM components (e.g., `native-image` or `ruby,nodejs` ) that will be installed by the [GraalVM Updater][gu]. |
2023-11-03 14:21:41 +02:00
| `version` | `''` | `X.Y.Z` (e.g., `22.3.0` ) for a specific [GraalVM release][releases] up to `22.3.2` < br > `mandrel-X.Y.Z.W` or `X.Y.Z.W-Final` (e.g., `mandrel-21.3.0.0-Final` or `21.3.0.0-Final` ) for a specific [Mandrel release][mandrel-releases],< br > `mandrel-latest` or `latest` for the latest Mandrel stable release. |
2023-06-16 09:19:49 +02:00
| `gds-token` | `''` | Download token for the GraalVM Download Service. If a non-empty token is provided, the action will set up GraalVM Enterprise Edition (see [GraalVM EE template ](#template-for-graalvm-enterprise-edition )). |
2022-11-03 17:13:30 +01:00
2022-11-07 10:21:48 +01:00
**) Make sure that Native Image is used only once per build job. Otherwise, the report is only generated for the last Native Image build.*
2022-01-20 17:49:45 +01:00
2022-01-03 09:01:37 +01:00
## Contributing
We welcome code contributions. To get started, you will need to sign the [Oracle Contributor Agreement][oca] (OCA).
Only pull requests from committers that can be verified as having signed the OCA can be accepted.
2022-01-03 13:11:04 +01:00
[dev-build]: https://github.com/graalvm/graalvm-ce-dev-builds/releases/latest
[dev-builds]: https://github.com/graalvm/graalvm-ce-dev-builds
2024-02-22 10:41:51 +01:00
[ea-builds]: https://github.com/graalvm/oracle-graalvm-ea-builds
2022-11-02 14:00:51 +01:00
[gha-annotations]: https://github.com/actions/toolkit/tree/main/packages/core#annotations
2022-11-03 18:46:41 +01:00
[gha-permissions]: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions
2022-03-11 14:06:12 +01:00
[gha-secrets]: https://docs.github.com/en/actions/security-guides/encrypted-secrets#creating -encrypted-secrets-for-a-repository
[gha-self-hosted-runners]: https://docs.github.com/en/actions/hosting-your-own-runners/about-self-hosted-runners
2022-01-03 09:01:37 +01:00
[gu]: https://www.graalvm.org/reference-manual/graalvm-updater/
2023-06-16 09:19:49 +02:00
[graalvm]: https://www.graalvm.org/
[graalvm-dl]: https://www.oracle.com/java/technologies/downloads/
2023-06-16 12:59:57 +02:00
[graalvm-medium]: https://medium.com/graalvm/a-new-graalvm-release-and-new-free-license-4aab483692f5
2022-03-11 14:06:12 +01:00
[graalvm-ee]: https://www.oracle.com/downloads/graalvm-downloads.html
2022-01-03 09:00:36 +01:00
[mandrel]: https://github.com/graalvm/mandrel
[mandrel-releases]: https://github.com/graalvm/mandrel/releases
[mandrel-stable]: https://github.com/graalvm/mandrel/releases/latest
2022-01-20 17:49:45 +01:00
[musl]: https://musl.libc.org/
2022-01-03 09:01:37 +01:00
[native-image]: https://www.graalvm.org/native-image/
2022-01-21 12:49:36 +01:00
[native-image-musl-build]: https://github.com/graalvm/setup-graalvm/blob/778131f1d6837ccd4b2e91382c31830896a2d56e/.github/workflows/test.yml#L74 -L92
2022-01-20 17:49:45 +01:00
[native-image-static]: https://github.com/oracle/graal/blob/fa6f4a974dedacf4688dcc430dd100849d9882f2/docs/reference-manual/native-image/StaticImages.md
2022-01-03 09:01:37 +01:00
[oca]: https://oca.opensource.oracle.com
[releases]: https://github.com/graalvm/graalvm-ce-builds/releases
[repo]: https://github.com/oracle/graal
2022-08-31 10:07:18 +02:00
[setup-java-caching]: https://github.com/actions/setup-java/tree/5b36705a13905facb447b6812d613a06a07e371d#caching -packages-dependencies
2022-01-03 09:01:37 +01:00
[stable]: https://github.com/graalvm/graalvm-ce-builds/releases/latest
2022-01-14 10:10:06 +01:00
[truffle-languages]: https://www.graalvm.org/reference-manual/languages/
2022-01-03 09:01:37 +01:00
[vcvarsall]: https://docs.microsoft.com/en-us/cpp/build/building-on-the-command-line