Skip to content

Commit fc45baf

Browse files
committed
Support new GraalVM for JDK17/JDK20 release
This commit adds support for the new GraalVM for JDK17/JDK20 release, including the new Oracle GraalVM distribution. For this, users only need to specify the 'java-version' option and the new 'distribution' option. The 'version' option is now marked as optional and kept for compatibility with older GraalVM releases and Mandrel.
1 parent 17d64df commit fc45baf

File tree

14 files changed

+745
-205
lines changed

14 files changed

+745
-205
lines changed

.github/workflows/test.yml

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,49 @@ jobs:
2020
npm install
2121
- run: |
2222
npm run all
23+
test:
24+
name: GraalVM
25+
runs-on: ${{ matrix.os }}
26+
strategy:
27+
matrix:
28+
java-version: ['17', '20', 'dev']
29+
distribution: ['graalvm', 'graalvm-community']
30+
os: [macos-latest, windows-latest, ubuntu-latest]
31+
steps:
32+
- uses: actions/checkout@v3
33+
- name: Run setup-graalvm action
34+
uses: ./
35+
with:
36+
java-version: ${{ matrix.java-version }}
37+
distribution: ${{ matrix.distribution }}
38+
github-token: ${{ secrets.GITHUB_TOKEN }}
39+
- name: Check environment
40+
run: |
41+
echo "GRAALVM_HOME: $GRAALVM_HOME"
42+
if [[ "${{ matrix.java-version }}" == "dev" ]]; then
43+
[[ "$GRAALVM_HOME" == *"$RUNNER_TEMP"* ]] || exit 12
44+
else
45+
[[ "$GRAALVM_HOME" == *"$RUNNER_TOOL_CACHE"* ]] || exit 23
46+
fi
47+
echo "JAVA_HOME: $JAVA_HOME"
48+
java --version
49+
java --version | grep "GraalVM" || exit 34
50+
native-image --version
51+
if: runner.os != 'Windows'
52+
- name: Check Windows environment
53+
run: |
54+
echo "GRAALVM_HOME: $env:GRAALVM_HOME"
55+
echo "JAVA_HOME: $env:JAVA_HOME"
56+
java --version
57+
native-image --version
2358
test-ce: # make sure the action works on a clean machine without building
59+
needs: test
2460
name: CE ${{ matrix.version }} + JDK${{ matrix.java-version }} on ${{ matrix.os }}
2561
runs-on: ${{ matrix.os }}
2662
strategy:
2763
matrix:
2864
version: ['latest', 'dev']
29-
java-version: ['19', '20']
65+
java-version: ['17', '20']
3066
components: ['native-image']
3167
os: [macos-latest, windows-latest, ubuntu-latest]
3268
exclude:
@@ -70,7 +106,7 @@ jobs:
70106
fi
71107
echo "JAVA_HOME: $JAVA_HOME"
72108
java --version
73-
java --version | grep "GraalVM CE" || exit 34
109+
java --version | grep "GraalVM" || exit 34
74110
native-image --version
75111
gu list
76112
if: runner.os != 'Windows'
@@ -83,6 +119,7 @@ jobs:
83119
gu.cmd remove native-image
84120
if: runner.os == 'Windows'
85121
test-ee:
122+
needs: test
86123
name: EE ${{ matrix.version }} + JDK${{ matrix.java-version }} on ${{ matrix.os }}
87124
if: github.event_name != 'pull_request'
88125
runs-on: ${{ matrix.os }}
@@ -130,6 +167,7 @@ jobs:
130167
gu.cmd remove native-image
131168
if: runner.os == 'Windows'
132169
test-mandrel:
170+
needs: test
133171
name: ${{ matrix.version }} + JDK${{ matrix.java-version }} on ${{ matrix.os }}
134172
runs-on: ${{ matrix.os }}
135173
strategy:
@@ -175,9 +213,8 @@ jobs:
175213
- name: Run setup-graalvm action
176214
uses: ./
177215
with:
178-
version: 'dev'
179216
java-version: 'dev'
180-
components: 'native-image'
217+
distribution: 'graalvm-community'
181218
native-image-job-reports: 'true'
182219
native-image-pr-reports: 'true'
183220
github-token: ${{ secrets.GITHUB_TOKEN }}
@@ -188,8 +225,8 @@ jobs:
188225
native-image HelloWorld
189226
./helloworld
190227
test-native-image-windows-msvc:
191-
name: native-image on windows-2019
192-
runs-on: windows-2019
228+
name: native-image on windows-2022
229+
runs-on: windows-2022
193230
permissions:
194231
contents: read
195232
pull-requests: write # for `native-image-pr-reports` option
@@ -198,9 +235,8 @@ jobs:
198235
- name: Run setup-graalvm action
199236
uses: ./
200237
with:
201-
version: '22.3.1'
202238
java-version: '17'
203-
components: 'native-image'
239+
distribution: 'graalvm'
204240
native-image-job-reports: 'true'
205241
native-image-pr-reports: 'true'
206242
github-token: ${{ secrets.GITHUB_TOKEN }}
@@ -221,9 +257,8 @@ jobs:
221257
- name: Run setup-graalvm action
222258
uses: ./
223259
with:
224-
version: 'dev'
225260
java-version: 'dev'
226-
components: 'native-image'
261+
distribution: 'graalvm-community'
227262
native-image-musl: 'true'
228263
native-image-job-reports: 'true'
229264
native-image-pr-reports: 'true'
@@ -245,9 +280,9 @@ jobs:
245280
- name: Run setup-graalvm action
246281
uses: ./
247282
with:
248-
version: 'latest'
249283
java-version: '17'
250-
components: 'espresso,llvm-toolchain,native-image,nodejs,python,R,ruby,wasm'
284+
distribution: 'graalvm'
285+
components: 'espresso,llvm-toolchain,native-image,nodejs,python,ruby,wasm'
251286
set-java-home: 'false'
252287
native-image-job-reports: 'true'
253288
native-image-pr-reports: 'true'
@@ -268,8 +303,6 @@ jobs:
268303
[[ $(which node) == *"graalvm"* ]] || exit 45
269304
node --version
270305
graalpy --version
271-
[[ $(which R) == *"graalvm"* ]] || exit 56
272-
R --version
273306
truffleruby --version
274307
wasm --version
275308
- name: Build HelloWorld.java with GraalVM Native Image
@@ -290,4 +323,4 @@ jobs:
290323
bundle exec rake test
291324
popd > /dev/null
292325
- name: Remove components
293-
run: gu remove espresso llvm-toolchain nodejs python R ruby wasm
326+
run: gu remove espresso llvm-toolchain nodejs python ruby wasm

README.md

Lines changed: 77 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,54 @@
11
# 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)
2-
This GitHub action sets up GraalVM [Community Edition (CE)][repo] or [Enterprise Edition (EE)][graalvm-ee] as well as GraalVM components such as [Native Image][native-image] and [Truffle languages][truffle-languages].
2+
This GitHub action sets up [Oracle GraalVM][graalvm], 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].
33

44
## Key Features
55

66
This action:
77

8-
- supports 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))
9-
- has built-in support for GraalVM components and the [GraalVM Updater][gu]
8+
- supports Oracle GraalVM [releases][graalvm-dl], 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))
109
- exports a `$GRAALVM_HOME` environment variable
11-
- adds `$GRAALVM_HOME/bin` to the `$PATH` environment variable<br>(Truffle languages and tools can be invoked directly)
12-
- sets `$JAVA_HOME` to `$GRAALVM_HOME` by default<br>(can be disabled via `set-java-home: 'false'`, see [options](#options))
13-
- supports `amd64` and `aarch64` (selected automatically, `aarch64` requires a [self-hosted runner][gha-self-hosted-runners])
14-
- sets up Windows environments with build tools using [vcvarsall.bat][vcvarsall]
10+
- adds `$GRAALVM_HOME/bin` to the `$PATH` environment variable<br>(Native Image, Truffle languages, and tools can be invoked directly)
11+
- sets `$JAVA_HOME` to `$GRAALVM_HOME` by default<br>(can be disabled via `set-java-home: 'false'`, see [Options](#options))
12+
- supports `x64` and `aarch64` (selected automatically, `aarch64` requires a [self-hosted runner][gha-self-hosted-runners])
1513
- supports dependency caching for Apache Maven, Gradle, and sbt (see [`cache` option](#options))
14+
- sets up Windows environments with build tools using [vcvarsall.bat][vcvarsall]
15+
- has built-in support for GraalVM components and the [GraalVM Updater][gu]
16+
17+
18+
## Migrating from GraalVM 22.3 or earlier to the new GraalVM for JDK 17 and later
19+
20+
The new [GraalVM release](https://medium.com/graalvm/a-new-graalvm-release-and-new-free-license-4aab483692f5) aligns the version scheme with OpenJDK.
21+
As a result, this action no longer requires the `version` option that was used to select a specific GraalVM version.
22+
At the same time, it introduces a new `distribution` option that can be used to select a specific GraalVM distribution (`graalvm`, `graalvm-community`, and `mandrel`).
23+
Therefore, to migrate workflows to use the latest GraalVM release, replace the `version` with the `distribution` option in your workflow `yml` config, for example:
24+
25+
```yml
26+
# ...
27+
- uses: graalvm/setup-graalvm@v1
28+
with:
29+
java-version: '17'
30+
version: '22.3.2' # Old 'version' option for the GraalVM version
31+
# ...
32+
```
33+
34+
can be turned into:
35+
36+
```yml
37+
# ...
38+
- uses: graalvm/setup-graalvm@v1
39+
with:
40+
java-version: '17.0.7' # for a specific JDK 17; or '17' for the latest JDK 17
41+
distribution: 'graalvm' # New 'distribution' option
42+
# ...
43+
```
1644

1745

1846
## Templates
1947

2048
### Quickstart Template
2149

2250
```yml
23-
name: GraalVM Community Edition build
51+
name: GraalVM build
2452
on: [push, pull_request]
2553
jobs:
2654
build:
@@ -29,17 +57,19 @@ jobs:
2957
- uses: actions/checkout@v3
3058
- uses: graalvm/setup-graalvm@v1
3159
with:
32-
version: 'latest'
33-
java-version: '17'
34-
components: 'native-image'
60+
java-version: '17.0.7'
61+
distribution: 'graalvm' # See 'Options' for all available distributions
3562
github-token: ${{ secrets.GITHUB_TOKEN }}
3663
- name: Example step
3764
run: |
3865
echo "GRAALVM_HOME: $GRAALVM_HOME"
3966
echo "JAVA_HOME: $JAVA_HOME"
4067
java --version
41-
gu --version
4268
native-image --version
69+
- name: Example step using Maven plugin # https://graalvm.github.io/native-build-tools/latest/maven-plugin.html
70+
run: mvn -Pnative package
71+
- name: Example step using Gradle plugin # https://graalvm.github.io/native-build-tools/latest/gradle-plugin.html
72+
run: gradlew nativeCompile
4373
```
4474
4575
### Building a HelloWorld with GraalVM Native Image on Different Platforms
@@ -59,9 +89,8 @@ jobs:
5989

6090
- uses: graalvm/setup-graalvm@v1
6191
with:
62-
version: '22.3.0'
63-
java-version: '17'
64-
components: 'native-image'
92+
java-version: '17.0.7'
93+
distribution: 'graalvm'
6594
github-token: ${{ secrets.GITHUB_TOKEN }}
6695
native-image-job-reports: 'true'
6796

@@ -79,7 +108,29 @@ jobs:
79108
path: helloworld*
80109
```
81110
82-
### Basic GraalVM Enterprise Edition Template
111+
<details>
112+
<summary><h4>Template for older GraalVM releases</h4></summary>
113+
114+
```yml
115+
name: GraalVM build
116+
on: [push, pull_request]
117+
jobs:
118+
build:
119+
runs-on: ubuntu-latest
120+
steps:
121+
- uses: actions/checkout@v3
122+
- uses: graalvm/setup-graalvm@v1
123+
with:
124+
version: '22.3.2' # GraalVM version
125+
java-version: '17'
126+
components: 'native-image'
127+
github-token: ${{ secrets.GITHUB_TOKEN }}
128+
```
129+
130+
</details>
131+
132+
<details>
133+
<summary><h4>Template for GraalVM Enterprise Edition</h4></summary>
83134
84135
#### Prerequisites
85136
@@ -109,22 +160,24 @@ jobs:
109160
native-image --version
110161
```
111162

163+
</details>
112164

113165
## Options
114166

115167
| Name | Default | Description |
116168
|-----------------|:--------:|-------------|
117-
| `version`<br>*(required)* | n/a | `X.Y.Z` (e.g., `22.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]. |
118-
| `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](#basic-graalvm-enterprise-edition-template)). |
119-
| `java-version`<br>*(required)* | n/a | `'17'` or `'19'` for a specific Java version, `'dev'` for the highest Java version available (requires `version: 'dev'`).<br>(`'8'`, `'11'`, `'16'` are supported for older GraalVM releases.) |
120-
| `components` | `''` | Comma-spearated list of GraalVM components (e.g., `native-image` or `ruby,nodejs`) that will be installed by the [GraalVM Updater][gu]. |
121-
| `github-token` | `'${{ 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. |
169+
| `java-version`<br>*(required)* | n/a | `'17.0.7'` or `'20.0.1'` for a specific Java version, `'dev'` for a dev build with the highest Java version available.<br>(`'8'`, `'11'`, `'16'`, `'19'` are supported for older GraalVM releases.) |
170+
| `distribution` | `''` | GraalVM distribution (`graalvm` for Oracle GraalVM, `graalvm-community` for GraalVM Community Edition, `mandrel` for Mandrel). |
171+
| `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. |
122172
| `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`. |
123173
| `cache` | `''` | Name of the build platform to cache dependencies. It can be `'maven'`, `'gradle'`, or `'sbt'` and works the same way as described in [actions/setup-java][setup-java-caching]. |
124-
| `check-for-updates` | `'true'` | [Annotate jobs][gha-annotations] with update notifications, for example, when a new GraalVM release is available. |
174+
| `check-for-updates` | `'true'` | [Annotate jobs][gha-annotations] with update notifications, for example when a new GraalVM release is available. |
125175
| `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`). |
126176
| `native-image-job-reports` *) | `'false'` | If set to `'true'`, post a job summary containing a Native Image build report. |
127177
| `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]. |
178+
| `components` | `''` | Comma-separated list of GraalVM components (e.g., `native-image` or `ruby,nodejs`) that will be installed by the [GraalVM Updater][gu]. |
179+
| `version` | n/a | `X.Y.Z` (e.g., `22.3.0`) for a specific [GraalVM release][releases] up to `22.3.2`<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]. |
180+
| `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)). |
128181

129182
**) Make sure that Native Image is used only once per build job. Otherwise, the report is only generated for the last Native Image build.*
130183

@@ -143,6 +196,8 @@ Only pull requests from committers that can be verified as having signed the OCA
143196
[gha-secrets]: https://docs.github.com/en/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository
144197
[gha-self-hosted-runners]: https://docs.github.com/en/actions/hosting-your-own-runners/about-self-hosted-runners
145198
[gu]: https://www.graalvm.org/reference-manual/graalvm-updater/
199+
[graalvm]: https://www.graalvm.org/
200+
[graalvm-dl]: https://www.oracle.com/java/technologies/downloads/
146201
[graalvm-ee]: https://www.oracle.com/downloads/graalvm-downloads.html
147202
[mandrel]: https://github.com/graalvm/mandrel
148203
[mandrel-releases]: https://github.com/graalvm/mandrel/releases

__tests__/gds.test.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as path from 'path'
2-
import {downloadGraalVMEE, fetchArtifact} from '../src/gds'
2+
import {downloadGraalVMEELegacy, fetchArtifact} from '../src/gds'
33
import {expect, test} from '@jest/globals'
44

55
const TEST_USER_AGENT = 'GraalVMGitHubActionTest/1.0.4'
@@ -32,13 +32,15 @@ test('fetch artifacts', async () => {
3232
})
3333

3434
test('errors when downloading artifacts', async () => {
35-
await expect(downloadGraalVMEE('invalid', '22.1.0', '11')).rejects.toThrow(
35+
await expect(
36+
downloadGraalVMEELegacy('invalid', '22.1.0', '11')
37+
).rejects.toThrow(
3638
'The provided "gds-token" was rejected (reason: "Invalid download token", opc-request-id: /'
3739
)
38-
await expect(downloadGraalVMEE('invalid', '1.0.0', '11')).rejects.toThrow(
39-
'Unable to find JDK11-based GraalVM EE 1.0.0'
40-
)
41-
await expect(downloadGraalVMEE('invalid', '22.1.0', '1')).rejects.toThrow(
42-
'Unable to find JDK1-based GraalVM EE 22.1.0'
43-
)
40+
await expect(
41+
downloadGraalVMEELegacy('invalid', '1.0.0', '11')
42+
).rejects.toThrow('Unable to find JDK11-based GraalVM EE 1.0.0')
43+
await expect(
44+
downloadGraalVMEELegacy('invalid', '22.1.0', '1')
45+
).rejects.toThrow('Unable to find JDK1-based GraalVM EE 22.1.0')
4446
})

__tests__/graalvm.test.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ test('request invalid version/javaVersion', async () => {
1919
await graalvm.setUpGraalVMRelease('', combination[0], combination[1])
2020
} catch (err) {
2121
if (!(err instanceof Error)) {
22-
fail(`Unexpected non-Erro: ${err}`)
22+
fail(`Unexpected non-Error: ${err}`)
2323
}
2424
error = err
2525
}
@@ -31,6 +31,23 @@ test('request invalid version/javaVersion', async () => {
3131
})
3232

3333
test('find version/javaVersion', async () => {
34+
// Make sure the action can find the latest Java version for known major versions
35+
for (var majorJavaVersion of ['17', '20']) {
36+
await graalvm.findLatestGraalVMJDKCEJavaVersion(majorJavaVersion)
37+
}
38+
39+
let error = new Error('unexpected')
40+
try {
41+
await graalvm.findLatestGraalVMJDKCEJavaVersion('11')
42+
fail('Should not find Java version for 11')
43+
} catch (err) {
44+
if (!(err instanceof Error)) {
45+
fail(`Unexpected non-Error: ${err}`)
46+
}
47+
error = err
48+
}
49+
expect(error.message).toContain('Unable to find the latest Java version for')
50+
3451
const latestRelease = await getTaggedRelease(
3552
GRAALVM_RELEASES_REPO,
3653
'vm-22.3.1'
@@ -40,7 +57,7 @@ test('find version/javaVersion', async () => {
4057
const latestJavaVersion = findHighestJavaVersion(latestRelease, latestVersion)
4158
expect(latestJavaVersion).not.toBe('')
4259

43-
let error = new Error('unexpected')
60+
error = new Error('unexpected')
4461
try {
4562
const invalidRelease = {...latestRelease, tag_name: 'invalid'}
4663
findGraalVMVersion(invalidRelease)
@@ -56,7 +73,7 @@ test('find version/javaVersion', async () => {
5673
findHighestJavaVersion(latestRelease, 'invalid')
5774
} catch (err) {
5875
if (!(err instanceof Error)) {
59-
fail(`Unexpected non-Erro: ${err}`)
76+
fail(`Unexpected non-Error: ${err}`)
6077
}
6178
error = err
6279
}

0 commit comments

Comments
 (0)