Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Liberica Native Image Kit as new distribution #87

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:
java --version
native-image --version
test-ce: # make sure the action works on a clean machine without building
needs: test
needs: test
name: CE ${{ matrix.version }} + JDK${{ matrix.java-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
Expand Down Expand Up @@ -243,6 +243,48 @@ jobs:
java --version
native-image --version
if: runner.os == 'Windows'
test-liberica:
needs: test
name: Liberica (${{ matrix.java-version }}, '${{ matrix.version }}', ${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
matrix:
java-version: ['17', '21.0.2']
version: ['', 'std', 'full']
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v4
- name: Run setup-graalvm action
uses: ./
with:
distribution: liberica
java-version: ${{ matrix.java-version }}
version: ${{ matrix.version }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We actually am phasing out version in favor of just the java-version. It seems there are different variants of Liberica. Can these also be pulled by setup-java and if yes, how?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT this is controlled by the java-package parameter:

java-package: The packaging variant of the chosen distribution. Possible values: jdk, jre, jdk+fx, jre+fx. Default value: jdk

The value of jdk corresponds to version: std, and jdk+fx corresponds to version: full

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Mapping jdk+fx to full seems like a hack, assuming fx stands for JavaFX? If Liberica users are more familiar with std and full, I'm ok with using those directly, maybe also allowing jdk and jdk+fx for full compatibility with setup-java. In any case, we should add the java-package input from setup-java and not use the version input for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I've added the java-package: jdk | jdk+fx input

github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Check environment
run: |
echo "GRAALVM_HOME: $GRAALVM_HOME"
[[ "$GRAALVM_HOME" == *"$RUNNER_TOOL_CACHE"* ]] || exit 12
echo "JAVA_HOME: $JAVA_HOME"
java --version
java --version | fgrep -qw ${{ matrix.java-version }} || exit 23
native-image --version
native-image --version | fgrep -qw ${{ matrix.java-version }} || exit 24
if: runner.os != 'Windows'
- name: Check Windows environment
shell: pwsh
run: |
echo "GRAALVM_HOME: $env:GRAALVM_HOME"
echo "JAVA_HOME: $env:JAVA_HOME"
java --version
if (!(java --version | findstr \<${{ matrix.java-version }}\>)) {
exit 23
}
native-image --version
if (!(native-image --version | findstr \<${{ matrix.java-version }}\>)) {
exit 24
}
if: runner.os == 'Windows'
test-native-image-windows:
name: native-image on windows-latest
runs-on: windows-latest
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,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)
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].
This GitHub action sets up [Oracle GraalVM][graalvm-medium], GraalVM [Community Edition (CE)][repo], [Enterprise Edition (EE)][graalvm-ee], [Mandrel][mandrel], or [Liberica Native Image Kit][liberica] as well as [Native Image][native-image] and GraalVM components such as [Truffle languages][truffle-languages].

## Key Features

This action:

- 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))
- 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, [Mandrel][mandrel], and [Liberica Native Image Kit][liberica] (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))
Expand Down Expand Up @@ -188,7 +188,7 @@ can be replaced with:
| Name | Default | Description |
|-----------------|:--------:|-------------|
| `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> |
| `distribution` | `'graalvm'` | GraalVM distribution <ul><li>Oracle GraalVM: `'graalvm'`</li><li>GraalVM Community Edition: `'graalvm-community'`</li><li>Mandrel: `'mandrel'`</li><li>Liberica: `'liberica'`</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]. |
Expand All @@ -197,7 +197,7 @@ can be replaced with:
| `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.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. |
| `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, <br>`std` (default) or `full` for Liberica|
| `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.*
Expand All @@ -222,6 +222,7 @@ Only pull requests from committers that can be verified as having signed the OCA
[graalvm-dl]: https://www.oracle.com/java/technologies/downloads/
[graalvm-medium]: https://medium.com/graalvm/a-new-graalvm-release-and-new-free-license-4aab483692f5
[graalvm-ee]: https://www.oracle.com/downloads/graalvm-downloads.html
[liberica]: https://bell-sw.com/liberica-native-image-kit/
[mandrel]: https://github.com/graalvm/mandrel
[mandrel-releases]: https://github.com/graalvm/mandrel/releases
[mandrel-stable]: https://github.com/graalvm/mandrel/releases/latest
Expand Down
3 changes: 2 additions & 1 deletion __tests__/graalvm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
findHighestJavaVersion,
findLatestEABuildDownloadUrl
} from '../src/graalvm'
import {GRAALVM_RELEASES_REPO} from '../src/constants'
import {GRAALVM_GH_USER, GRAALVM_RELEASES_REPO} from '../src/constants'

process.env['RUNNER_TOOL_CACHE'] = path.join(__dirname, 'TOOL_CACHE')
process.env['RUNNER_TEMP'] = path.join(__dirname, 'TEMP')
Expand Down Expand Up @@ -53,6 +53,7 @@ test('find version/javaVersion', async () => {
expect(error.message).toContain('Unable to find the latest Java version for')

const latestRelease = await getTaggedRelease(
GRAALVM_GH_USER,
GRAALVM_RELEASES_REPO,
'vm-22.3.1'
)
Expand Down
138 changes: 138 additions & 0 deletions __tests__/liberica.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import * as liberica from '../src/liberica'
import * as c from '../src/constants'
import * as path from 'path'
import * as semver from 'semver'
import {expect, test} from '@jest/globals'

process.env['RUNNER_TOOL_CACHE'] = path.join(__dirname, 'TOOL_CACHE')
process.env['RUNNER_TEMP'] = path.join(__dirname, 'TEMP')

test('find latest JDK version', async () => {
// Make sure the action can find the latest Java version for known major versions
await expectLatestToBe('11', atLeast('11.0.22+12'))
await expectLatestToBe('11.0.22', upToBuild('11.0.22+12'))
await expectLatestToBe('11.0.22+12', exactly('11.0.22+12'))

await expectLatestToBe('17', atLeast('17.0.10+13'))
await expectLatestToBe('17.0.10', upToBuild('17.0.10+13'))
await expectLatestToBe('17.0.10+13', exactly('17.0.10+13'))

await expectLatestToBe('21', atLeast('21.0.2+14'))
await expectLatestToBe('21.0.2', upToBuild('21.0.2+14'))
await expectLatestToBe('21.0.2+14', exactly('21.0.2+14'))

// Outdated major version
await expectLatestToFail('20')

// Outdated CPU versions
await expectLatestToFail('11.0.2') // should not resolve to 11.0.22
await expectLatestToFail('17.0.1') // should not resolve to 17.0.10
await expectLatestToFail('17.0.7+11')
await expectLatestToFail('21.0.0+8')
await expectLatestToFail('21.0.1')

// Incorrect build number
await expectLatestToFail('17.0.10+10')
}, 30000)

test('find asset URL', async () => {
await expectURL('11.0.22+12', '', 'bellsoft-liberica-vm-openjdk11.0.22')
await expectURL('17.0.10+13', 'std', 'bellsoft-liberica-vm-openjdk17.0.10')

if (!c.IS_LINUX) {
// This check can fail on Linux because there's no `full` version for aarch64 and/or musl
await expectURL(
'21.0.2+14',
'full',
'bellsoft-liberica-vm-full-openjdk21.0.2'
)
}
}, 10000)

type verifier = (
version: string,
major: number,
minor: number,
patch: number
) => void

function atLeast(expectedMinVersion: string): verifier {
const expectedMajor = semver.major(expectedMinVersion)
return function (
version: string,
major: number,
minor: number,
patch: number
) {
expect(major).toBe(expectedMajor)
if (semver.compareBuild(version, expectedMinVersion) < 0) {
throw new Error(`Version ${version} is older than ${expectedMinVersion}`)
}
}
}

function upToBuild(expectedMinVersion: string): verifier {
const expectedMinor = semver.minor(expectedMinVersion)
const expectedPatch = semver.patch(expectedMinVersion)
const atLeastVerifier = atLeast(expectedMinVersion)
return function (
version: string,
major: number,
minor: number,
patch: number
) {
atLeastVerifier(version, major, minor, patch)
expect(minor).toBe(expectedMinor)
expect(patch).toBe(expectedPatch)
}
}

function exactly(expectedVersion: string): verifier {
return function (
version: string,
major: number,
minor: number,
patch: number
) {
if (semver.compareBuild(version, expectedVersion) != 0) {
throw new Error(`Expected version ${expectedVersion} but got ${version}`)
}
}
}

async function expectLatestToBe(pattern: string, verify: verifier) {
const result = await liberica.findLatestLibericaJavaVersion(pattern)
expect(semver.valid(result)).toBeDefined()
const major = semver.major(result)
const minor = semver.minor(result)
const patch = semver.patch(result)
verify(result, major, minor, patch)
}

async function expectLatestToFail(pattern: string) {
try {
const result = await liberica.findLatestLibericaJavaVersion(pattern)
throw new Error(
`findLatest(${pattern}) should have failed but returned ${result}`
)
} catch (err) {
if (!(err instanceof Error)) {
throw new Error(`Unexpected non-Error: ${err}`)
}
expect(err.message).toContain(
`Unable to find the latest version for JDK${pattern}`
)
}
}

async function expectURL(
javaVersion: string,
version: string,
expectedPrefix: string
) {
const url = await liberica.findLibericaURL(javaVersion, version)
expect(url).toBeDefined()
const parts = url.split('/')
const file = parts[parts.length - 1]
expect(file.startsWith(expectedPrefix)).toBe(true)
}
16 changes: 10 additions & 6 deletions dist/cleanup/index.js

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

Loading