Compare commits

...

34 Commits

Author SHA1 Message Date
Fabio Niephaus
3d7ab58c1d Bump version to 1.1.9. 2024-03-12 20:41:34 +01:00
Fabio Niephaus
d3f9e14fc3 Fix and test check for MSVC setup. 2024-03-12 17:01:21 +01:00
Fabio Niephaus
b03aef7455 Fix GraalVM for JDK 17+ detection in MSVC feature.
Fixes #88
2024-03-12 17:01:21 +01:00
Fabio Niephaus
5393c3d809 Use -version on JDK 8. Fixes #86 2024-02-23 08:45:57 +01:00
Fabio Niephaus
e878075a91 Bump version to 1.1.8. 2024-02-22 13:17:14 +01:00
Fabio Niephaus
9a425fb910 Report java --version when done.
Fixes #81
2024-02-22 13:17:14 +01:00
Fabio Niephaus
7652cc43b3 Disable MSVC feature for javaVersion gte 18.
Fixes #32.
2024-02-22 13:17:14 +01:00
Fabio Niephaus
a2b35c9a1c Turn descriptions for versions & distros into list.
[ci skip]
2024-02-22 13:17:14 +01:00
Fabio Niephaus
791f27b2b8 Document support for Oracle GraalVM EA builds.
[ci skip]
2024-02-22 13:17:14 +01:00
Fabio Niephaus
f6947ecb49 Derive javaVersion from downloadUrl.
This ensures that `latest-ea` and `22-ea` can be cached based on the actual version number (e.g., `22.0.0`).
2024-02-22 13:17:14 +01:00
Fabio Niephaus
cb063c121c Use new Oracle GraalVM EA builds repo. 2024-02-22 13:17:14 +01:00
dependabot[bot]
076347913e Bump undici from 5.28.2 to 5.28.3
Bumps [undici](https://github.com/nodejs/undici) from 5.28.2 to 5.28.3.
- [Release notes](https://github.com/nodejs/undici/releases)
- [Commits](https://github.com/nodejs/undici/compare/v5.28.2...v5.28.3)

---
updated-dependencies:
- dependency-name: undici
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-02-19 09:32:54 +01:00
Fabio Niephaus
d72e3dbf5f Bump version to 1.1.7. 2024-02-13 17:28:29 +01:00
Fabio Niephaus
22551b2bec Minor edit. 2024-02-13 17:16:15 +01:00
Fabio Niephaus
bf3e45bce6 Use toSemVer() for tool name. 2024-02-13 15:44:22 +01:00
Fabio Niephaus
1588b03f82 Use semver in toSemVer(). 2024-02-13 15:44:08 +01:00
Fabio Niephaus
6df9f698c6 Avoid deprecated methods in tests. 2024-02-13 15:43:34 +01:00
Fabio Niephaus
2408275e34 Add initial support for early access (EA) builds. 2024-02-13 13:37:00 +01:00
Fabio Niephaus
a638430bc0 Move migration notice further down. 2024-02-08 12:05:32 +01:00
Fabio Niephaus
3bd233e767 Test on macos-14 (macOS on Apple Silicon).
For context: https://github.blog/changelog/2024-01-30-github-actions-introducing-the-new-m1-macos-runner-available-to-open-source/
2024-01-31 14:27:15 +01:00
Fabio Niephaus
c99915cc1a Upgrade actions/setup-node to v4. 2024-01-31 14:27:03 +01:00
Jongwoo Han
a0f131ece5 Upgrade node-version to v20. 2024-01-31 14:35:58 +09:00
Fabio Niephaus
a1b47fdf04 Bump version to 1.1.6. 2024-01-30 15:36:39 +01:00
Fabio Niephaus
129a551a10 Upgrade Node to v20. 2024-01-30 15:26:44 +01:00
Foivos Zakkak
b8dc5fccfb Get latest mandrel release if version not specified
Update doc.
2023-11-03 13:30:38 +01:00
Foivos Zakkak
1c219f5b27 Remove user-agent from HttpClient 2023-11-03 13:30:38 +01:00
Fabio Niephaus
2a93b69fdf Bump version to 1.1.5. 2023-11-03 13:12:28 +01:00
Fabio Niephaus
0b782b6b90 Support fixed GA versions of Oracle GraalVM. 2023-11-03 13:01:11 +01:00
Fabio Niephaus
d5b07dd118 Lock java-version to 17.0.8.
This is the last release with access to all tested GU components.
2023-11-03 12:36:12 +01:00
Foivos Zakkak
40dc6ae006 Restore windows latest test & add test for non-prefixed mandrel ver 2023-11-03 12:07:47 +01:00
Foivos Zakkak
cde0daed27 Relax requirement of mandrel versions starting with mandrel-
Since we can now define the distribution there is no longer the need to
include the mandrel- prefix in Mandrel versions.
2023-11-03 12:07:47 +01:00
Foivos Zakkak
22b65d7de0 Use Foojay.io DISCO API to get latest Mandrel release 2023-11-03 12:07:47 +01:00
Foivos Zakkak
c2fd2d6d8e Improve error log for wrong mandrel version and javaVersion comb.
Add test to test similar to the GraalVM one for the expected error
output.
2023-11-03 12:07:47 +01:00
dependabot[bot]
2b3d0bde8f Bump @babel/traverse from 7.21.4 to 7.23.2
Bumps [@babel/traverse](https://github.com/babel/babel/tree/HEAD/packages/babel-traverse) from 7.21.4 to 7.23.2.
- [Release notes](https://github.com/babel/babel/releases)
- [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md)
- [Commits](https://github.com/babel/babel/commits/v7.23.2/packages/babel-traverse)

---
updated-dependencies:
- dependency-name: "@babel/traverse"
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-10-19 08:40:23 +02:00
22 changed files with 60070 additions and 16112 deletions

View File

@@ -26,10 +26,10 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set Node.js 16.x
uses: actions/setup-node@v3
- name: Set Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: 16.x
node-version: 20.x
cache: npm
- name: Install dependencies

View File

@@ -27,9 +27,20 @@ jobs:
matrix:
java-version: ['21', '17', '20', 'dev']
distribution: ['graalvm', 'graalvm-community']
os: [macos-latest, windows-latest, ubuntu-latest]
os: [
ubuntu-latest,
macos-14, # macOS on Apple silicon
macos-12, # macOS on Intel
windows-latest
]
components: ['']
include:
- java-version: 'latest-ea'
distribution: 'graalvm'
os: ubuntu-latest
- java-version: '22-ea'
distribution: 'graalvm'
os: ubuntu-latest
- java-version: '21'
distribution: ''
os: ubuntu-latest
@@ -40,6 +51,9 @@ jobs:
distribution: 'graalvm-community'
os: ubuntu-latest
components: 'native-image' # should print a warning but not fail
- java-version: '21.0.0' # test for GA version (see #63)
distribution: 'graalvm'
os: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run setup-graalvm action
@@ -88,8 +102,12 @@ jobs:
java-version: '17'
components: 'native-image'
os: ubuntu-20.04
- version: '21.2.0'
java-version: '8' # for JDK 8 notification
components: 'native-image'
os: ubuntu-latest
- version: '22.3.1'
java-version: '11' # for JDK11 notification
java-version: '11' # for JDK 11 notification
components: 'native-image'
os: macos-11
- version: '22.3.1'
@@ -118,8 +136,8 @@ jobs:
[[ "$GRAALVM_HOME" == *"$RUNNER_TOOL_CACHE"* ]] || exit 23
fi
echo "JAVA_HOME: $JAVA_HOME"
java --version
java --version | grep "GraalVM" || exit 34
java -version
java -version 2>&1 | grep "GraalVM" || exit 34
native-image --version
if [[ "${{ matrix.java-version }}" != "dev" ]]; then
gu list
@@ -129,7 +147,7 @@ jobs:
run: |
echo "GRAALVM_HOME: $env:GRAALVM_HOME"
echo "JAVA_HOME: $env:JAVA_HOME"
java --version
java -version
native-image --version
gu.cmd remove native-image
if: runner.os == 'Windows'
@@ -187,7 +205,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
version: ['mandrel-22.2.0.0-Final', 'mandrel-latest']
version: ['mandrel-22.2.0.0-Final', '23.0.1.2-Final', 'mandrel-latest']
java-version: ['17']
distribution: ['mandrel']
os: [windows-latest, ubuntu-latest]
@@ -196,10 +214,10 @@ jobs:
java-version: '17'
distribution: '' # test empty distribution for backward compatibility
os: ubuntu-latest
exclude: # temporarily disable Mandrel latest builds on Windows due to unavailability
- version: 'mandrel-latest'
java-version: '17'
os: windows-latest
- version: '' # test with no version
java-version: '21'
distribution: 'mandrel'
os: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run setup-graalvm action
@@ -303,7 +321,7 @@ jobs:
- name: Run setup-graalvm action
uses: ./
with:
java-version: '17'
java-version: '17.0.8'
distribution: 'graalvm'
components: 'espresso,llvm-toolchain,native-image,nodejs,python,ruby,wasm'
set-java-home: 'false'

View File

@@ -5,7 +5,7 @@ This GitHub action sets up [Oracle GraalVM][graalvm-medium], GraalVM [Community
This action:
- 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))
- 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))
- exports a `$GRAALVM_HOME` environment variable
- 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))
@@ -15,34 +15,6 @@ This action:
- has built-in support for GraalVM components and the [GraalVM Updater][gu]
## 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
# ...
```
## Templates
### Quickstart Template
@@ -57,8 +29,8 @@ jobs:
- uses: actions/checkout@v4
- uses: graalvm/setup-graalvm@v1
with:
java-version: '21'
distribution: 'graalvm' # See 'Options' for all available distributions
java-version: '21' # See 'Options' section below for all supported versions
distribution: 'graalvm' # See 'Options' section below for all available distributions
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Example step
run: |
@@ -108,6 +80,26 @@ jobs:
path: helloworld*
```
<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:
java-version: '22-ea' # or 'latest-ea' for the latest Java version available
distribution: 'graalvm'
github-token: ${{ secrets.GITHUB_TOKEN }}
```
</details>
<details>
<summary><h4>Template for older GraalVM releases</h4></summary>
@@ -162,12 +154,41 @@ jobs:
</details>
## 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
# ...
```
## Options
| Name | Default | Description |
|-----------------|:--------:|-------------|
| `java-version`<br>*(required)* | n/a | `'21'` or `'17.0.7'` for a specific Java version, `'dev'` for a dev build with the latest Java version available.<br>(`'8'`, `'11'`, `'16'`, `'19'` are supported for older GraalVM releases.) |
| `distribution` | `''` | GraalVM distribution (`graalvm` for Oracle GraalVM, `graalvm-community` for GraalVM Community Edition, `mandrel` for Mandrel). |
| `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> |
| `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. |
| `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`. |
| `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]. |
@@ -176,7 +197,7 @@ jobs:
| `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]. |
| `components` | `''` | Comma-separated list of GraalVM components (e.g., `native-image` or `ruby,nodejs`) that will be installed by the [GraalVM Updater][gu]. |
| `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` (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]. |
| `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. |
| `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)). |
**) Make sure that Native Image is used only once per build job. Otherwise, the report is only generated for the last Native Image build.*
@@ -191,6 +212,7 @@ Only pull requests from committers that can be verified as having signed the OCA
[dev-build]: https://github.com/graalvm/graalvm-ce-dev-builds/releases/latest
[dev-builds]: https://github.com/graalvm/graalvm-ce-dev-builds
[ea-builds]: https://github.com/graalvm/oracle-graalvm-ea-builds
[gha-annotations]: https://github.com/actions/toolkit/tree/main/packages/core#annotations
[gha-permissions]: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions
[gha-secrets]: https://docs.github.com/en/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository

View File

@@ -101,14 +101,14 @@ describe('dependency cache', () => {
})
it('throws error if unsupported package manager specified', () => {
return expect(restore('ant')).rejects.toThrowError(
return expect(restore('ant')).rejects.toThrow(
'unknown package manager specified: ant'
)
})
describe('for maven', () => {
it('throws error if no pom.xml found', async () => {
await expect(restore('maven')).rejects.toThrowError(
await expect(restore('maven')).rejects.toThrow(
`No file in ${projectRoot(
workspace
)} matched to [**/pom.xml], make sure you have checked out the target repository`
@@ -118,14 +118,14 @@ describe('dependency cache', () => {
createFile(join(workspace, 'pom.xml'))
await restore('maven')
expect(spyCacheRestore).toBeCalled()
expect(spyWarning).not.toBeCalled()
expect(spyInfo).toBeCalledWith('maven cache is not found')
expect(spyCacheRestore).toHaveBeenCalled()
expect(spyWarning).not.toHaveBeenCalled()
expect(spyInfo).toHaveBeenCalledWith('maven cache is not found')
})
})
describe('for gradle', () => {
it('throws error if no build.gradle found', async () => {
await expect(restore('gradle')).rejects.toThrowError(
await expect(restore('gradle')).rejects.toThrow(
`No file in ${projectRoot(
workspace
)} matched to [**/*.gradle*,**/gradle-wrapper.properties,buildSrc/**/Versions.kt,buildSrc/**/Dependencies.kt], make sure you have checked out the target repository`
@@ -135,17 +135,17 @@ describe('dependency cache', () => {
createFile(join(workspace, 'build.gradle'))
await restore('gradle')
expect(spyCacheRestore).toBeCalled()
expect(spyWarning).not.toBeCalled()
expect(spyInfo).toBeCalledWith('gradle cache is not found')
expect(spyCacheRestore).toHaveBeenCalled()
expect(spyWarning).not.toHaveBeenCalled()
expect(spyInfo).toHaveBeenCalledWith('gradle cache is not found')
})
it('downloads cache based on build.gradle.kts', async () => {
createFile(join(workspace, 'build.gradle.kts'))
await restore('gradle')
expect(spyCacheRestore).toBeCalled()
expect(spyWarning).not.toBeCalled()
expect(spyInfo).toBeCalledWith('gradle cache is not found')
expect(spyCacheRestore).toHaveBeenCalled()
expect(spyWarning).not.toHaveBeenCalled()
expect(spyInfo).toHaveBeenCalledWith('gradle cache is not found')
})
})
it('downloads cache based on buildSrc/Versions.kt', async () => {
@@ -153,13 +153,13 @@ describe('dependency cache', () => {
createFile(join(workspace, 'buildSrc', 'Versions.kt'))
await restore('gradle')
expect(spyCacheRestore).toBeCalled()
expect(spyWarning).not.toBeCalled()
expect(spyInfo).toBeCalledWith('gradle cache is not found')
expect(spyCacheRestore).toHaveBeenCalled()
expect(spyWarning).not.toHaveBeenCalled()
expect(spyInfo).toHaveBeenCalledWith('gradle cache is not found')
})
describe('for sbt', () => {
it('throws error if no build.sbt found', async () => {
await expect(restore('sbt')).rejects.toThrowError(
await expect(restore('sbt')).rejects.toThrow(
`No file in ${projectRoot(
workspace
)} matched to [**/*.sbt,**/project/build.properties,**/project/**.{scala,sbt}], make sure you have checked out the target repository`
@@ -169,9 +169,9 @@ describe('dependency cache', () => {
createFile(join(workspace, 'build.sbt'))
await restore('sbt')
expect(spyCacheRestore).toBeCalled()
expect(spyWarning).not.toBeCalled()
expect(spyInfo).toBeCalledWith('sbt cache is not found')
expect(spyCacheRestore).toHaveBeenCalled()
expect(spyWarning).not.toHaveBeenCalled()
expect(spyInfo).toHaveBeenCalledWith('sbt cache is not found')
})
})
})
@@ -191,7 +191,7 @@ describe('dependency cache', () => {
})
it('throws error if unsupported package manager specified', () => {
return expect(save('ant')).rejects.toThrowError(
return expect(save('ant')).rejects.toThrow(
'unknown package manager specified: ant'
)
})
@@ -201,10 +201,10 @@ describe('dependency cache', () => {
createStateForMissingBuildFile()
await save('maven')
expect(spyCacheSave).toBeCalled()
expect(spyWarning).not.toBeCalled()
expect(spyInfo).toBeCalled()
expect(spyInfo).toBeCalledWith(
expect(spyCacheSave).toHaveBeenCalled()
expect(spyWarning).not.toHaveBeenCalled()
expect(spyInfo).toHaveBeenCalled()
expect(spyInfo).toHaveBeenCalledWith(
expect.stringMatching(/^Cache saved with the key:.*/)
)
})
@@ -225,24 +225,26 @@ describe('dependency cache', () => {
it('uploads cache even if no pom.xml found', async () => {
createStateForMissingBuildFile()
await save('maven')
expect(spyCacheSave).toBeCalled()
expect(spyWarning).not.toBeCalled()
expect(spyCacheSave).toHaveBeenCalled()
expect(spyWarning).not.toHaveBeenCalled()
})
it('does not upload cache if no restore run before', async () => {
createFile(join(workspace, 'pom.xml'))
await save('maven')
expect(spyCacheSave).not.toBeCalled()
expect(spyWarning).toBeCalledWith('Error retrieving key from state.')
expect(spyCacheSave).not.toHaveBeenCalled()
expect(spyWarning).toHaveBeenCalledWith(
'Error retrieving key from state.'
)
})
it('uploads cache', async () => {
createFile(join(workspace, 'pom.xml'))
createStateForSuccessfulRestore()
await save('maven')
expect(spyCacheSave).toBeCalled()
expect(spyWarning).not.toBeCalled()
expect(spyInfo).toBeCalledWith(
expect(spyCacheSave).toHaveBeenCalled()
expect(spyWarning).not.toHaveBeenCalled()
expect(spyInfo).toHaveBeenCalledWith(
expect.stringMatching(/^Cache saved with the key:.*/)
)
})
@@ -252,24 +254,26 @@ describe('dependency cache', () => {
createStateForMissingBuildFile()
await save('gradle')
expect(spyCacheSave).toBeCalled()
expect(spyWarning).not.toBeCalled()
expect(spyCacheSave).toHaveBeenCalled()
expect(spyWarning).not.toHaveBeenCalled()
})
it('does not upload cache if no restore run before', async () => {
createFile(join(workspace, 'build.gradle'))
await save('gradle')
expect(spyCacheSave).not.toBeCalled()
expect(spyWarning).toBeCalledWith('Error retrieving key from state.')
expect(spyCacheSave).not.toHaveBeenCalled()
expect(spyWarning).toHaveBeenCalledWith(
'Error retrieving key from state.'
)
})
it('uploads cache based on build.gradle', async () => {
createFile(join(workspace, 'build.gradle'))
createStateForSuccessfulRestore()
await save('gradle')
expect(spyCacheSave).toBeCalled()
expect(spyWarning).not.toBeCalled()
expect(spyInfo).toBeCalledWith(
expect(spyCacheSave).toHaveBeenCalled()
expect(spyWarning).not.toHaveBeenCalled()
expect(spyInfo).toHaveBeenCalledWith(
expect.stringMatching(/^Cache saved with the key:.*/)
)
})
@@ -278,9 +282,9 @@ describe('dependency cache', () => {
createStateForSuccessfulRestore()
await save('gradle')
expect(spyCacheSave).toBeCalled()
expect(spyWarning).not.toBeCalled()
expect(spyInfo).toBeCalledWith(
expect(spyCacheSave).toHaveBeenCalled()
expect(spyWarning).not.toHaveBeenCalled()
expect(spyInfo).toHaveBeenCalledWith(
expect.stringMatching(/^Cache saved with the key:.*/)
)
})
@@ -290,9 +294,9 @@ describe('dependency cache', () => {
createStateForSuccessfulRestore()
await save('gradle')
expect(spyCacheSave).toBeCalled()
expect(spyWarning).not.toBeCalled()
expect(spyInfo).toBeCalledWith(
expect(spyCacheSave).toHaveBeenCalled()
expect(spyWarning).not.toHaveBeenCalled()
expect(spyInfo).toHaveBeenCalledWith(
expect.stringMatching(/^Cache saved with the key:.*/)
)
})
@@ -301,24 +305,26 @@ describe('dependency cache', () => {
it('uploads cache even if no build.sbt found', async () => {
createStateForMissingBuildFile()
await save('sbt')
expect(spyCacheSave).toBeCalled()
expect(spyWarning).not.toBeCalled()
expect(spyCacheSave).toHaveBeenCalled()
expect(spyWarning).not.toHaveBeenCalled()
})
it('does not upload cache if no restore run before', async () => {
createFile(join(workspace, 'build.sbt'))
await save('sbt')
expect(spyCacheSave).not.toBeCalled()
expect(spyWarning).toBeCalledWith('Error retrieving key from state.')
expect(spyCacheSave).not.toHaveBeenCalled()
expect(spyWarning).toHaveBeenCalledWith(
'Error retrieving key from state.'
)
})
it('uploads cache', async () => {
createFile(join(workspace, 'build.sbt'))
createStateForSuccessfulRestore()
await save('sbt')
expect(spyCacheSave).toBeCalled()
expect(spyWarning).not.toBeCalled()
expect(spyInfo).toBeCalledWith(
expect(spyCacheSave).toHaveBeenCalled()
expect(spyWarning).not.toHaveBeenCalled()
expect(spyInfo).toHaveBeenCalledWith(
expect.stringMatching(/^Cache saved with the key:.*/)
)
})

View File

@@ -27,7 +27,6 @@
import {run as cleanup} from '../src/cleanup'
import * as core from '@actions/core'
import * as cache from '@actions/cache'
import * as util from '../src/utils'
describe('cleanup', () => {
let spyWarning: jest.SpyInstance<void, Parameters<typeof core.warning>>
@@ -62,8 +61,8 @@ describe('cleanup', () => {
return name === 'cache' ? 'gradle' : ''
})
await cleanup()
expect(spyCacheSave).toBeCalled()
expect(spyWarning).not.toBeCalled()
expect(spyCacheSave).toHaveBeenCalled()
expect(spyWarning).not.toHaveBeenCalled()
})
it('does not fail even though the save process throws error', async () => {
@@ -74,7 +73,7 @@ describe('cleanup', () => {
return name === 'cache' ? 'gradle' : ''
})
await cleanup()
expect(spyCacheSave).toBeCalled()
expect(spyCacheSave).toHaveBeenCalled()
})
})

View File

@@ -2,7 +2,11 @@ import * as path from 'path'
import * as graalvm from '../src/graalvm'
import {expect, test} from '@jest/globals'
import {getTaggedRelease} from '../src/utils'
import {findGraalVMVersion, findHighestJavaVersion} from '../src/graalvm'
import {
findGraalVMVersion,
findHighestJavaVersion,
findLatestEABuildDownloadUrl
} from '../src/graalvm'
import {GRAALVM_RELEASES_REPO} from '../src/constants'
process.env['RUNNER_TOOL_CACHE'] = path.join(__dirname, 'TOOL_CACHE')
@@ -79,3 +83,21 @@ test('find version/javaVersion', async () => {
}
expect(error.message).toContain('Could not find highest Java version.')
})
test('find version/javaVersion', async () => {
let url22EA = await findLatestEABuildDownloadUrl('22-ea')
expect(url22EA).not.toBe('')
let urlLatestEA = await findLatestEABuildDownloadUrl('latest-ea')
expect(urlLatestEA).not.toBe('')
let error = new Error('unexpected')
try {
await findLatestEABuildDownloadUrl('8-ea')
} catch (err) {
if (!(err instanceof Error)) {
fail(`Unexpected non-Error: ${err}`)
}
error = err
}
expect(error.message).toContain('Unable to resolve download URL for')
})

75
__tests__/mandrel.test.ts Normal file
View File

@@ -0,0 +1,75 @@
import * as path from 'path'
import * as mandrel from '../src/mandrel'
import {expect, test} from '@jest/globals'
import {getLatestRelease} from '../src/utils'
process.env['RUNNER_TOOL_CACHE'] = path.join(__dirname, 'TOOL_CACHE')
process.env['RUNNER_TEMP'] = path.join(__dirname, 'TEMP')
test('request invalid version/javaVersion combination', async () => {
for (var combination of [
['mandrel-23.1.1.0-Final', '17'],
['mandrel-23.0.2.1-Final', '21']
]) {
let error = new Error('unexpected')
try {
await mandrel.setUpMandrel(combination[0], combination[1])
} catch (err) {
if (!(err instanceof Error)) {
fail(`Unexpected non-Error: ${err}`)
}
error = err
}
expect(error).not.toBeUndefined()
expect(error.message).toContain('Failed to download')
expect(error.message).toContain('Are you sure version')
}
})
test('request invalid version', async () => {
for (var combination of [
['mandrel-23.1.1.0', '21'],
['mandrel-23.0.2.1', '17']
]) {
let error = new Error('unexpected')
try {
await mandrel.setUpMandrel(combination[0], combination[1])
} catch (err) {
if (!(err instanceof Error)) {
fail(`Unexpected non-Error: ${err}`)
}
error = err
}
expect(error).not.toBeUndefined()
expect(error.message).toContain('Failed to download')
expect(error.message).toContain('Are you sure version')
}
})
test('find latest', async () => {
// Make sure the action can find the latest Mandrel release
const latestRelease = await getLatestRelease(mandrel.MANDREL_REPO)
const tag_name = latestRelease.tag_name
expect(tag_name).toContain(mandrel.MANDREL_TAG_PREFIX)
})
test('get known latest Mandrel for specific JDK', async () => {
// Test deprecated versions that won't get updates anymore
for (var combination of [
['11', '22.2.0.0-Final'],
['20', '23.0.1.2-Final']
]) {
const latest = await mandrel.getLatestMandrelReleaseUrl(combination[0])
expect(latest).toContain(`mandrel-java${combination[0]}`)
expect(latest).toContain(combination[1])
}
})
test('get latest Mandrel for specific JDK', async () => {
// Test supported versions
for (var javaVersion of ['17', '21']) {
const latest = await mandrel.getLatestMandrelReleaseUrl(javaVersion)
expect(latest).toContain(`mandrel-java${javaVersion}`)
}
})

36
__tests__/msvc.test.ts Normal file
View File

@@ -0,0 +1,36 @@
import * as path from 'path'
import {expect, test} from '@jest/globals'
import {needsWindowsEnvironmentSetup} from '../src/msvc'
import {VERSION_DEV, VERSION_LATEST} from '../src/constants'
process.env['RUNNER_TOOL_CACHE'] = path.join(__dirname, 'TOOL_CACHE')
process.env['RUNNER_TEMP'] = path.join(__dirname, 'TEMP')
test('decide whether Window env must be set up for GraalVM for JDK', async () => {
for (var javaVersion of [
'17',
'17.0.8',
'17.0',
'21',
'22',
'22-ea',
'23-ea',
VERSION_DEV
]) {
expect(needsWindowsEnvironmentSetup(javaVersion, '', true)).toBe(false)
}
})
test('decide whether Window env must be set up for legacy GraalVM', async () => {
for (var combination of [
['7', '22.3.0'],
['17', '22.3'],
['7', '22.3'],
['7', VERSION_DEV],
['17', VERSION_LATEST]
]) {
expect(
needsWindowsEnvironmentSetup(combination[0], combination[1], false)
).toBe(combination[1] !== VERSION_DEV)
}
})

34
__tests__/utils.test.ts Normal file
View File

@@ -0,0 +1,34 @@
import * as path from 'path'
import {expect, test} from '@jest/globals'
import {toSemVer} from '../src/utils'
test('convert version', async () => {
for (var inputAndExpectedOutput of [
['22', '22.0.0'],
['22.0', '22.0.0'],
['22.0.0', '22.0.0'],
['22.0.0.2', '22.0.0-2'],
['22-ea', '22.0.0-ea'],
['22.0-ea', '22.0.0-ea'],
['22.0.0-ea', '22.0.0-ea']
]) {
expect(toSemVer(inputAndExpectedOutput[0])).toBe(inputAndExpectedOutput[1])
}
})
test('convert invalid version', async () => {
for (var input of ['dev', 'abc', 'a.b.c']) {
let error = new Error('unexpected')
try {
toSemVer(input)
} catch (err) {
if (!(err instanceof Error)) {
fail(`Unexpected non-Error: ${err}`)
}
error = err
}
expect(error).not.toBeUndefined()
expect(error.message).toContain('Unable to convert')
}
})

View File

@@ -54,7 +54,7 @@ outputs:
cache-hit:
description: 'A boolean value to indicate an exact match was found for the primary key'
runs:
using: 'node16'
using: 'node20'
main: 'dist/main/index.js'
post: 'dist/cleanup/index.js'
post-if: 'success()'

33096
dist/cleanup/index.js generated vendored

File diff suppressed because one or more lines are too long

32780
dist/main/index.js generated vendored

File diff suppressed because one or more lines are too long

9449
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{
"name": "setup-graalvm",
"version": "1.1.4",
"version": "1.1.9",
"private": true,
"description": "GitHub Action for GraalVM",
"main": "lib/main.js",
@@ -27,33 +27,37 @@
"author": "GraalVM Community",
"license": "UPL",
"dependencies": {
"@actions/cache": "^3.0.4",
"@actions/core": "^1.10.0",
"@actions/exec": "^1.1.0",
"@actions/github": "^5.1.1",
"@actions/glob": "^0.3.0",
"@actions/http-client": "^1.0.11",
"@actions/io": "^1.1.1",
"@actions/tool-cache": "^1.7.1",
"@octokit/core": "^3.5.1",
"@octokit/types": "^6.34.0",
"semver": "^7.5.2",
"uuid": "^8.3.2"
"@actions/cache": "^3.2.3",
"@actions/core": "^1.10.1",
"@actions/exec": "^1.1.1",
"@actions/github": "^6.0.0",
"@actions/glob": "^0.4.0",
"@actions/http-client": "^2.2.0",
"@actions/io": "^1.1.3",
"@actions/tool-cache": "^2.0.1",
"@octokit/core": "^5.1.0",
"@octokit/types": "^12.0.0",
"semver": "^7.5.4",
"uuid": "^9.0.1"
},
"devDependencies": {
"@types/jest": "^27.5.2",
"@types/node": "^18.15.11",
"@types/semver": "^7.3.13",
"@types/uuid": "^8.3.4",
"@typescript-eslint/parser": "^5.8.1",
"@vercel/ncc": "^0.33.4",
"eslint": "^8.6.0",
"eslint-plugin-github": "^4.3.5",
"eslint-plugin-jest": "^25.3.4",
"jest": "^29.5.0",
"@types/jest": "^29.5.11",
"@types/node": "^20.11.10",
"@types/semver": "^7.5.6",
"@types/uuid": "^9.0.8",
"@typescript-eslint/eslint-plugin": "^6.19.1",
"@typescript-eslint/parser": "^6.19.1",
"@vercel/ncc": "^0.38.1",
"eslint": "^8.56.0",
"eslint-plugin-github": "^4.10.1",
"eslint-plugin-jest": "^27.6.3",
"eslint-plugin-jsonc": "^2.13.0",
"eslint-plugin-prettier": "^5.1.3",
"jest": "^29.7.0",
"js-yaml": "^4.1.0",
"prettier": "2.5.1",
"ts-jest": "^29.1.0",
"typescript": "^5.0.4"
"prettier": "^3.2.4",
"prettier-eslint": "^16.3.0",
"ts-jest": "^29.1.2",
"typescript": "^5.3.3"
}
}

View File

@@ -15,6 +15,8 @@ export const IS_LINUX = process.platform === 'linux'
export const IS_MACOS = process.platform === 'darwin'
export const IS_WINDOWS = process.platform === 'win32'
export const EXECUTABLE_SUFFIX = IS_WINDOWS ? '.exe' : ''
export const DISTRIBUTION_GRAALVM = 'graalvm'
export const DISTRIBUTION_GRAALVM_COMMUNITY = 'graalvm-community'
export const DISTRIBUTION_MANDREL = 'mandrel'
@@ -40,6 +42,9 @@ export const GDS_GRAALVM_PRODUCT_ID = 'D53FAE8052773FFAE0530F15000AA6C6'
export const ENV_GITHUB_EVENT_NAME = 'GITHUB_EVENT_NAME'
export const EVENT_NAME_PULL_REQUEST = 'pull_request'
export const ERROR_REQUEST =
'Please file an issue at: https://github.com/graalvm/setup-graalvm/issues.'
export const ERROR_HINT =
'If you think this is a mistake, please file an issue at: https://github.com/graalvm/setup-graalvm/issues.'
@@ -49,6 +54,25 @@ export type LatestReleaseResponse =
export type MatchingRefsResponse =
otypes.Endpoints['GET /repos/{owner}/{repo}/git/matching-refs/{ref}']['response']
export type ReleasesResponse =
otypes.Endpoints['GET /repos/{owner}/{repo}/releases']['response']
export type ContentsResponse =
otypes.Endpoints['GET /repos/{owner}/{repo}/contents/{path}']['response']
export interface OracleGraalVMEAFile {
filename: string
arch: 'aarch64' | 'x64'
platform: 'darwin' | 'linux' | 'windows'
}
export interface OracleGraalVMEAVersion {
version: string
latest?: boolean
download_base_url: string
files: OracleGraalVMEAFile[]
}
function determineJDKArchitecture(): string {
switch (process.arch) {
case 'x64': {

View File

@@ -369,8 +369,8 @@ function createReport(data: BuildOutput): string {
details.total_bytes
)}</td>
<td align="left">${objectCount}${bytesToHuman(
details.image_heap.resources.bytes
)} for ${details.image_heap.resources.count.toLocaleString()} resources</td>
details.image_heap.resources.bytes
)} for ${details.image_heap.resources.count.toLocaleString()} resources</td>
</tr>${debugInfoLine}
<tr>
<td align="left"><a href="${DOCS_BASE}#glossary-other-data" target="_blank">Other data</a></td>
@@ -404,16 +404,16 @@ function createReport(data: BuildOutput): string {
<td align="left">${bytesToHuman(
resources.memory.peak_rss_bytes
)} (${toPercent(
resources.memory.peak_rss_bytes,
resources.memory.system_total
)} of ${bytesToHuman(resources.memory.system_total)} system memory)</td>
resources.memory.peak_rss_bytes,
resources.memory.system_total
)} of ${bytesToHuman(resources.memory.system_total)} system memory)</td>
</tr>
<tr>
<td align="left"><a href="${DOCS_BASE}#glossary-cpu-load" target="_blank">CPU load</a></td>
<td align="left">${resources.cpu.load.toFixed(3)} (${toPercent(
resources.cpu.load,
resources.cpu.total_cores
)} of ${resources.cpu.total_cores} CPU cores)</td>
resources.cpu.load,
resources.cpu.total_cores
)} of ${resources.cpu.total_cores} CPU cores)</td>
</tr>
</tbody>
</table>

View File

@@ -6,8 +6,7 @@ import * as io from '@actions/io'
import * as path from 'path'
import * as stream from 'stream'
import * as util from 'util'
import {IHeaders} from '@actions/http-client/interfaces'
import {IncomingHttpHeaders} from 'http'
import {IncomingHttpHeaders, OutgoingHttpHeaders} from 'http'
import {RetryHelper} from '@actions/tool-cache/lib/retry-helper'
import {calculateSHA256} from './utils'
import {ok} from 'assert'
@@ -32,7 +31,7 @@ export async function downloadGraalVMEELegacy(
version: string,
javaVersion: string
): Promise<string> {
const userAgent = `GraalVMGitHubAction/1.1.4 (arch:${c.GRAALVM_ARCH}; os:${c.GRAALVM_PLATFORM}; java:${javaVersion})`
const userAgent = `GraalVMGitHubAction/1.1.9 (arch:${c.GRAALVM_ARCH}; os:${c.GRAALVM_PLATFORM}; java:${javaVersion})`
const baseArtifact = await fetchArtifact(
userAgent,
'isBase:True',
@@ -132,7 +131,7 @@ class HTTPError extends Error {
async function downloadTool(
url: string,
userAgent: string,
headers?: IHeaders
headers?: OutgoingHttpHeaders
): Promise<string> {
const dest = path.join(getTempDirectory(), uuidv4())
await io.mkdirP(path.dirname(dest))
@@ -169,7 +168,7 @@ async function downloadToolAttempt(
url: string,
userAgent: string,
dest: string,
headers?: IHeaders
headers?: OutgoingHttpHeaders
): Promise<string> {
if (fs.existsSync(dest)) {
throw new Error(`Destination file path ${dest} already exists`)

View File

@@ -1,7 +1,9 @@
import * as c from './constants'
import * as semver from 'semver'
import {
downloadAndExtractJDK,
downloadExtractAndCacheJDK,
getContents,
getLatestRelease,
getMatchingTags,
getTaggedRelease
@@ -9,10 +11,11 @@ import {
import {downloadGraalVMEELegacy} from './gds'
import {downloadTool} from '@actions/tool-cache'
import {basename} from 'path'
import {gt as semverGt, valid as semverValid} from 'semver'
const GRAALVM_DL_BASE = 'https://download.oracle.com/graalvm'
const GRAALVM_CE_DL_BASE = `https://github.com/graalvm/${c.GRAALVM_RELEASES_REPO}/releases/download`
const ORACLE_GRAALVM_REPO_EA_BUILDS = 'oracle-graalvm-ea-builds'
const ORACLE_GRAALVM_REPO_EA_BUILDS_LATEST_SYMBOL = 'latest-ea'
const GRAALVM_REPO_DEV_BUILDS = 'graalvm-ce-dev-builds'
const GRAALVM_JDK_TAG_PREFIX = 'jdk-'
const GRAALVM_TAG_PREFIX = 'vm-'
@@ -25,19 +28,91 @@ export async function setUpGraalVMJDK(
if (javaVersionOrDev === c.VERSION_DEV) {
return setUpGraalVMJDKDevBuild()
}
const javaVersion = javaVersionOrDev
let javaVersion = javaVersionOrDev
const toolName = determineToolName(javaVersion, false)
let downloadName = toolName
let downloadUrl: string
if (javaVersion.includes('.')) {
const majorJavaVersion = javaVersion.split('.')[0]
downloadUrl = `${GRAALVM_DL_BASE}/${majorJavaVersion}/archive/${toolName}${c.GRAALVM_FILE_EXTENSION}`
if (javaVersion.endsWith('-ea')) {
downloadUrl = await findLatestEABuildDownloadUrl(javaVersion)
const filename = basename(downloadUrl)
const resolvedVersion = semver.valid(semver.coerce(filename))
if (!resolvedVersion) {
throw new Error(
`Unable to determine resolved version based on '${filename}'. ${c.ERROR_REQUEST}`
)
}
javaVersion = resolvedVersion
} else if (javaVersion.includes('.')) {
if (semver.valid(javaVersion)) {
const majorJavaVersion = semver.major(javaVersion)
const minorJavaVersion = semver.minor(javaVersion)
const patchJavaVersion = semver.patch(javaVersion)
const isGARelease = minorJavaVersion === 0 && patchJavaVersion === 0
if (isGARelease) {
// For GA versions of JDKs, /archive/ does not use minor and patch version (see https://www.oracle.com/java/technologies/jdk-script-friendly-urls/)
downloadName = determineToolName(majorJavaVersion.toString(), false)
}
downloadUrl = `${GRAALVM_DL_BASE}/${majorJavaVersion}/archive/${downloadName}${c.GRAALVM_FILE_EXTENSION}`
} else {
throw new Error(
`java-version set to '${javaVersion}'. Please make sure the java-version is set correctly. ${c.ERROR_HINT}`
)
}
} else {
downloadUrl = `${GRAALVM_DL_BASE}/${javaVersion}/latest/${toolName}${c.GRAALVM_FILE_EXTENSION}`
downloadUrl = `${GRAALVM_DL_BASE}/${javaVersion}/latest/${downloadName}${c.GRAALVM_FILE_EXTENSION}`
}
const downloader = async () => downloadGraalVMJDK(downloadUrl, javaVersion)
return downloadExtractAndCacheJDK(downloader, toolName, javaVersion)
}
export async function findLatestEABuildDownloadUrl(
javaEaVersion: string
): Promise<string> {
const filePath = `versions/${javaEaVersion}.json`
let response
try {
response = await getContents(ORACLE_GRAALVM_REPO_EA_BUILDS, filePath)
} catch (error) {
throw new Error(
`Unable to resolve download URL for '${javaEaVersion}'. Please make sure the java-version is set correctly. ${c.ERROR_HINT}`
)
}
if (
Array.isArray(response) ||
response.type !== 'file' ||
!response.content
) {
throw new Error(
`Unexpected response when resolving download URL for '${javaEaVersion}'. ${c.ERROR_REQUEST}`
)
}
const versionData = JSON.parse(
Buffer.from(response.content, 'base64').toString('utf-8')
)
let latestVersion
if (javaEaVersion === ORACLE_GRAALVM_REPO_EA_BUILDS_LATEST_SYMBOL) {
latestVersion = versionData as c.OracleGraalVMEAVersion
} else {
latestVersion = (versionData as c.OracleGraalVMEAVersion[]).find(
v => v.latest
)
if (!latestVersion) {
throw new Error(
`Unable to find latest version for '${javaEaVersion}'. ${c.ERROR_REQUEST}`
)
}
}
const file = latestVersion.files.find(
f => f.arch === c.JDK_ARCH && f.platform === c.GRAALVM_PLATFORM
)
if (!file || !file.filename.startsWith('graalvm-jdk-')) {
throw new Error(
`Unable to find file metadata for '${javaEaVersion}'. ${c.ERROR_REQUEST}`
)
}
return `${latestVersion.download_base_url}${file.filename}`
}
export async function setUpGraalVMJDKCE(
javaVersionOrDev: string
): Promise<string> {
@@ -71,8 +146,8 @@ export async function findLatestGraalVMJDKCEJavaVersion(
for (const matchingRef of matchingRefs) {
const currentVersion = matchingRef.ref.substring(versionNumberStartIndex)
if (
semverValid(currentVersion) &&
semverGt(currentVersion, highestVersion)
semver.valid(currentVersion) &&
semver.gt(currentVersion, highestVersion)
) {
highestVersion = currentVersion
}

View File

@@ -3,7 +3,7 @@ import * as core from '@actions/core'
import * as graalvm from './graalvm'
import * as semver from 'semver'
import {isFeatureAvailable as isCacheAvailable} from '@actions/cache'
import {join} from 'path'
import {basename, join} from 'path'
import {restore} from './features/cache'
import {setUpDependencies} from './dependencies'
import {setUpGUComponents} from './gu'
@@ -12,6 +12,7 @@ import {checkForUpdates} from './features/check-for-updates'
import {setUpNativeImageMusl} from './features/musl'
import {setUpWindowsEnvironment} from './msvc'
import {setUpNativeImageBuildReports} from './features/reports'
import {exec} from '@actions/exec'
async function run(): Promise<void> {
try {
@@ -29,9 +30,15 @@ async function run(): Promise<void> {
const enableCheckForUpdates =
core.getInput(c.INPUT_CHECK_FOR_UPDATES) === 'true'
const enableNativeImageMusl = core.getInput(c.INPUT_NI_MUSL) === 'true'
const isGraalVMforJDK17OrLater =
distribution.length > 0 || graalVMVersion.length == 0
if (c.IS_WINDOWS) {
setUpWindowsEnvironment(graalVMVersion)
setUpWindowsEnvironment(
javaVersion,
graalVMVersion,
isGraalVMforJDK17OrLater
)
}
await setUpDependencies(components)
if (enableNativeImageMusl) {
@@ -39,8 +46,6 @@ async function run(): Promise<void> {
}
// Download GraalVM JDK
const isGraalVMforJDK17OrLater =
distribution.length > 0 || graalVMVersion.length == 0
let graalVMHome
if (isGraalVMforJDK17OrLater) {
if (
@@ -58,13 +63,7 @@ async function run(): Promise<void> {
graalVMHome = await graalvm.setUpGraalVMJDKCE(javaVersion)
break
case c.DISTRIBUTION_MANDREL:
if (graalVMVersion.startsWith(c.MANDREL_NAMESPACE)) {
graalVMHome = await setUpMandrel(graalVMVersion, javaVersion)
} else {
throw new Error(
`Mandrel requires the 'version' option (see https://github.com/graalvm/setup-graalvm/tree/main#options).`
)
}
graalVMHome = await setUpMandrel(graalVMVersion, javaVersion)
break
case '':
if (javaVersion === c.VERSION_DEV) {
@@ -157,6 +156,12 @@ async function run(): Promise<void> {
await restore(cache)
}
setUpNativeImageBuildReports(isGraalVMforJDK17OrLater, graalVMVersion)
core.startGroup(`Successfully set up '${basename(graalVMHome)}'`)
await exec(join(graalVMHome, 'bin', `java${c.EXECUTABLE_SUFFIX}`), [
javaVersion.startsWith('8') ? '-version' : '--version'
])
core.endGroup()
} catch (error) {
if (error instanceof Error) core.setFailed(error.message)
}

View File

@@ -1,27 +1,33 @@
import * as c from './constants'
import * as httpClient from '@actions/http-client'
import {downloadExtractAndCacheJDK, getLatestRelease} from './utils'
import {downloadTool} from '@actions/tool-cache'
import {basename} from 'path'
const MANDREL_REPO = 'mandrel'
const MANDREL_TAG_PREFIX = c.MANDREL_NAMESPACE
export const MANDREL_REPO = 'mandrel'
export const MANDREL_TAG_PREFIX = c.MANDREL_NAMESPACE
const MANDREL_DL_BASE = 'https://github.com/graalvm/mandrel/releases/download'
const DISCO_API_BASE = 'https://api.foojay.io/disco/v3.0/packages/jdks'
interface JdkData {
message: string
result: any
}
export async function setUpMandrel(
graalvmVersion: string,
mandrelVersion: string,
javaVersion: string
): Promise<string> {
const mandrelVersion = graalvmVersion.substring(
c.MANDREL_NAMESPACE.length,
graalvmVersion.length
)
const version = stripMandrelNamespace(mandrelVersion)
let mandrelHome
switch (mandrelVersion) {
switch (version) {
case '':
// fetch latest if no version is specified
case 'latest':
mandrelHome = await setUpMandrelLatest(javaVersion)
break
default:
mandrelHome = await setUpMandrelRelease(mandrelVersion, javaVersion)
mandrelHome = await setUpMandrelRelease(version, javaVersion)
break
}
@@ -29,32 +35,110 @@ export async function setUpMandrel(
}
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)
const latest_release_url = await getLatestMandrelReleaseUrl(javaVersion)
const version_tag = getTagFromURI(latest_release_url)
const version = stripMandrelNamespace(version_tag)
const toolName = determineToolName(javaVersion)
return downloadExtractAndCacheJDK(
async () => downloadTool(latest_release_url),
toolName,
version
)
}
// Download URIs are of the form https://github.com/graalvm/mandrel/releases/download/<tag>/<archive-name>
function getTagFromURI(uri: string): string {
const parts = uri.split('/')
try {
return parts[parts.length - 2]
} catch (error) {
throw new Error(`Failed to extract tag from URI ${uri}: ${error}`)
}
}
export async function getLatestMandrelReleaseUrl(
javaVersion: string
): Promise<string> {
const url = `${DISCO_API_BASE}?jdk_version=${javaVersion}&distribution=${c.DISTRIBUTION_MANDREL}&architecture=${c.JDK_ARCH}&operating_system=${c.JDK_PLATFORM}&latest=per_distro`
const _http = new httpClient.HttpClient()
const response = await _http.getJson<JdkData>(url)
if (response.statusCode !== 200) {
throw new Error(
`Failed to fetch latest Mandrel release for Java ${javaVersion} from DISCO API: ${response.result}`
)
}
const result = response.result?.result[0]
try {
const pkg_info_uri = result.links.pkg_info_uri
return await getLatestMandrelReleaseUrlHelper(
_http,
javaVersion,
pkg_info_uri
)
} catch (error) {
throw new Error(
`Failed to get latest Mandrel release for Java ${javaVersion} from DISCO API: ${error}`
)
}
}
async function getLatestMandrelReleaseUrlHelper(
_http: httpClient.HttpClient,
java_version: string,
pkg_info_uri: string
): Promise<string> {
const response = await _http.getJson<JdkData>(pkg_info_uri)
if (response.statusCode !== 200) {
throw new Error(
`Failed to fetch package info of latest Mandrel release for Java ${java_version} from DISCO API: ${response.result}`
)
}
const result = response.result?.result[0]
try {
return result.direct_download_uri
} catch (error) {
throw new Error(
`Failed to get download URI of latest Mandrel release for Java ${java_version} from DISCO API: ${error}`
)
}
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}`
const toolName = determineToolName(javaVersion)
return downloadExtractAndCacheJDK(
async () => downloadTool(downloadUrl),
async () => downloadMandrelJDK(version, javaVersion),
toolName,
version
)
}
async function downloadMandrelJDK(
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}`
try {
return await downloadTool(downloadUrl)
} catch (error) {
if (error instanceof Error && error.message.includes('404')) {
// Not Found
throw new Error(
`Failed to download ${basename(
downloadUrl
)}. Are you sure version: '${version}' and java-version: '${javaVersion}' are correct?`
)
}
throw new Error(
`Failed to download ${basename(downloadUrl)} (error: ${error}).`
)
}
}
function determineMandrelIdentifier(
version: string,
javaVersion: string
@@ -65,3 +149,14 @@ function determineMandrelIdentifier(
function determineToolName(javaVersion: string): string {
return `mandrel-java${javaVersion}-${c.GRAALVM_PLATFORM}`
}
export function stripMandrelNamespace(graalVMVersion: string) {
if (graalVMVersion.startsWith(c.MANDREL_NAMESPACE)) {
return graalVMVersion.substring(
c.MANDREL_NAMESPACE.length,
graalVMVersion.length
)
} else {
return graalVMVersion
}
}

View File

@@ -1,4 +1,5 @@
import * as core from '@actions/core'
import * as semver from 'semver'
import {execSync} from 'child_process'
import {existsSync} from 'fs'
import {VERSION_DEV} from './constants'
@@ -27,9 +28,32 @@ function findVcvarsallPath(): string {
throw new Error('Failed to find vcvarsall.bat')
}
export function setUpWindowsEnvironment(graalVMVersion: string): void {
if (graalVMVersion === VERSION_DEV) {
return // no longer required in dev builds
export function needsWindowsEnvironmentSetup(
javaVersion: string,
graalVMVersion: string,
isGraalVMforJDK17OrLater: boolean
): boolean {
if (javaVersion === VERSION_DEV || graalVMVersion === VERSION_DEV) {
return false // no longer required in dev builds
} else if (isGraalVMforJDK17OrLater) {
return false // no longer required in GraalVM for JDK 17 and later.
}
return true
}
export function setUpWindowsEnvironment(
javaVersion: string,
graalVMVersion: string,
isGraalVMforJDK17OrLater: boolean
): void {
if (
!needsWindowsEnvironmentSetup(
javaVersion,
graalVMVersion,
isGraalVMforJDK17OrLater
)
) {
return
}
core.startGroup('Updating Windows environment...')

View File

@@ -2,6 +2,7 @@ import * as c from './constants'
import * as core from '@actions/core'
import * as github from '@actions/github'
import * as httpClient from '@actions/http-client'
import * as semver from 'semver'
import * as tc from '@actions/tool-cache'
import {ExecOptions, exec as e} from '@actions/exec'
import {readFileSync, readdirSync} from 'fs'
@@ -47,6 +48,22 @@ export async function getLatestRelease(
).data
}
export async function getContents(
repo: string,
path: string
): Promise<c.ContentsResponse['data']> {
const githubToken = getGitHubToken()
const options = githubToken.length > 0 ? {auth: githubToken} : {}
const octokit = new GitHubDotCom(options)
return (
await octokit.request('GET /repos/{owner}/{repo}/contents/{path}', {
owner: c.GRAALVM_GH_USER,
repo,
path
})
).data
}
export async function getTaggedRelease(
repo: string,
tag: string
@@ -135,17 +152,25 @@ function findJavaHomeInSubfolder(searchPath: string): string {
}
}
/**
* This helper turns GraalVM version numbers (e.g., `22.0.0.2`) into valid
* semver.org versions (e.g., `22.0.0-2`), which is needed because
* @actions/tool-cache uses `semver` to validate versions.
*/
export function toSemVer(version: string): string {
const parts = version.split('.')
const major = parts[0]
const minor = parts.length > 1 ? parts[1] : '0'
const patch = parts.length > 2 ? parts.slice(2).join('-') : '0'
return `${major}.${minor}.${patch}`
if (parts.length === 4) {
/**
* Turn legacy GraalVM version numbers (e.g., `22.0.0.2`) into valid
* semver.org versions (e.g., `22.0.0-2`).
*/
return `${parts[0]}.${parts[1]}.${parts.slice(2).join('-')}`
}
const versionParts = version.split('-', 2)
const suffix = versionParts.length === 2 ? '-' + versionParts[1] : ''
const validVersion = semver.valid(semver.coerce(versionParts[0]) + suffix)
if (!validVersion) {
throw new Error(
`Unable to convert '${version}' to semantic version. ${c.ERROR_HINT}`
)
}
return validVersion
}
export function isPREvent(): boolean {