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 all 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.java-package }}', ${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
matrix:
java-version: ['17', '21.0.2']
java-package: ['', 'jdk', 'jdk+fx']
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 }}
java-package: ${{ matrix.java-package }}
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
8 changes: 5 additions & 3 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,8 @@ 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> |
| `java-package` | `'jdk'` | The package type (`'jdk'` or `'jdk+fx'`). Currently applies to Liberica only. |
| `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 Down Expand Up @@ -222,6 +223,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', 'jdk', 'bellsoft-liberica-vm-openjdk17.0.10')

if (!c.IS_LINUX) {
// This check can fail on Linux because there's no `jdk+fx` package for aarch64 and/or musl
await expectURL(
'21.0.2+14',
'jdk+fx',
'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,
javaPackage: string,
expectedPrefix: string
) {
const url = await liberica.findLibericaURL(javaVersion, javaPackage)
expect(url).toBeDefined()
const parts = url.split('/')
const file = parts[parts.length - 1]
expect(file.startsWith(expectedPrefix)).toBe(true)
}
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ inputs:
java-version:
required: true
description: 'Java version. See examples of supported syntax in the README file.'
java-package:
description: 'The package type (jdk or jdk+fx). Currently applies to Liberica only.'
required: false
default: 'jdk'
distribution:
description: 'GraalVM distribution. See the list of available distributions in the README file.'
required: false
Expand Down
17 changes: 11 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
Loading