setup-graalvm/README.md

117 lines
5.5 KiB
Markdown
Raw Normal View History

2022-01-03 16:01:37 +08: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)
2022-01-14 17:10:06 +08:00
This GitHub action sets up [GraalVM Community Edition][repo] and GraalVM components such as [Native Image][native-image] and [Truffle languages][truffle-languages].
2022-01-03 16:01:37 +08:00
## Key Features
This action:
2022-01-05 19:51:41 +08:00
- supports GraalVM CE [releases], [dev builds][dev-builds], and [Mandrel][mandrel] (see [options](#options))
2022-01-03 16:01:37 +08:00
- has built-in support for GraalVM components and the [GraalVM updater][gu]
- exports a `$GRAALVM_HOME` environment variable
2022-01-14 17:10:06 +08:00
- adds `$GRAALVM_HOME/bin` to the `$PATH` environment variable<br>(Truffle languages and tools can be invoked directly)
2022-01-03 16:01:37 +08:00
- sets `$JAVA_HOME` to `$GRAALVM_HOME` by default<br>(can be disabled via `set-java-home: 'false'`, see [options](#options))
- supports `amd64` and `aarch64` (requires a [self-hosted runner][gh-self-hosted-runners])
2022-01-03 16:01:37 +08:00
- sets up Windows environments with build tools using [vcvarsall.bat][vcvarsall]
## Templates
### Quickstart Template
```yml
name: GraalVM build
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: graalvm/setup-graalvm@v1
with:
version: 'latest'
java-version: '11'
components: 'native-image'
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Example step
run: |
echo "GRAALVM_HOME: $GRAALVM_HOME"
echo "JAVA_HOME: $JAVA_HOME"
java --version
gu --version
native-image --version
```
2022-03-30 20:41:52 +08:00
### Building a HelloWorld with GraalVM Native Image on Different Platforms
2022-01-03 16:01:37 +08:00
```yml
name: GraalVM Native Image build
on: [push, pull_request]
jobs:
build:
name: HelloWorld on ${{ matrix.os }}
2022-01-03 16:01:37 +08:00
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
steps:
- uses: actions/checkout@v2
- uses: graalvm/setup-graalvm@v1
with:
version: '22.0.0.2'
2022-01-03 16:01:37 +08:00
java-version: '11'
components: 'native-image'
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Build and run HelloWorld.java
run: |
echo 'public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); } }' > HelloWorld.java
2022-01-03 16:01:37 +08:00
javac HelloWorld.java
native-image HelloWorld
./helloworld
- name: Upload binary
uses: actions/upload-artifact@v2
with:
name: helloworld-${{ matrix.os }}
2022-01-03 16:01:37 +08:00
path: helloworld*
```
## Options
| Name | Default | Description |
|-----------------|:--------:|-------------|
2022-01-25 23:24:36 +08:00
| `version`<br>*(required)* | n/a | `X.Y.Z` (e.g., `21.3.0`) for a specific [GraalVM release][releases]<br>`latest` for [latest stable release][stable],<br>`dev` for [latest dev build][dev-build],<br>`mandrel-X.Y.Z` (e.g., `mandrel-21.3.0.0-Final`) for a specific [Mandrel release][mandrel-releases],<br>`mandrel-latest` for [latest Mandrel stable release][mandrel-stable]. |
2022-01-03 16:01:37 +08:00
| `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. |
| `set-java-home` | `'true'` | If set to `'true'`, instructs the action to set `$JAVA_HOME` to the path of the GraalVM installation. |
2022-01-21 00:49:45 +08:00
| `native-image-musl` | `'false'` | If set to `'true'`, sets up [musl] for building [static images][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-01-03 16:01:37 +08: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 20:11:04 +08:00
[dev-build]: https://github.com/graalvm/graalvm-ce-dev-builds/releases/latest
[dev-builds]: https://github.com/graalvm/graalvm-ce-dev-builds
[gh-self-hosted-runners]: https://docs.github.com/en/actions/hosting-your-own-runners/about-self-hosted-runners
2022-01-03 16:01:37 +08:00
[gu]: https://www.graalvm.org/reference-manual/graalvm-updater/
2022-01-03 16:00:36 +08: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-21 00:49:45 +08:00
[musl]: https://musl.libc.org/
2022-01-03 16:01:37 +08:00
[native-image]: https://www.graalvm.org/native-image/
[native-image-musl-build]: https://github.com/graalvm/setup-graalvm/blob/778131f1d6837ccd4b2e91382c31830896a2d56e/.github/workflows/test.yml#L74-L92
2022-01-21 00:49:45 +08:00
[native-image-static]: https://github.com/oracle/graal/blob/fa6f4a974dedacf4688dcc430dd100849d9882f2/docs/reference-manual/native-image/StaticImages.md
2022-01-03 16:01:37 +08:00
[oca]: https://oca.opensource.oracle.com
[releases]: https://github.com/graalvm/graalvm-ce-builds/releases
[repo]: https://github.com/oracle/graal
[stable]: https://github.com/graalvm/graalvm-ce-builds/releases/latest
2022-01-14 17:10:06 +08:00
[truffle-languages]: https://www.graalvm.org/reference-manual/languages/
2022-01-03 16:01:37 +08:00
[vcvarsall]: https://docs.microsoft.com/en-us/cpp/build/building-on-the-command-line