Skip to content

Commit

Permalink
Use java-package input instead of version
Browse files Browse the repository at this point in the history
  • Loading branch information
petermz committed Mar 18, 2024
1 parent ad288a9 commit 25bad63
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 35 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,12 @@ jobs:
if: runner.os == 'Windows'
test-liberica:
needs: test
name: Liberica (${{ matrix.java-version }}, '${{ matrix.version }}', ${{ matrix.os }})
name: Liberica (${{ matrix.java-version }}, '${{ matrix.java-package }}', ${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
matrix:
java-version: ['17', '21.0.2']
version: ['', 'std', 'full']
java-package: ['', 'jdk', 'jdk+fx']
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v4
Expand All @@ -259,7 +259,7 @@ jobs:
with:
distribution: liberica
java-version: ${{ matrix.java-version }}
version: ${{ matrix.version }}
java-package: ${{ matrix.java-package }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Check environment
run: |
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ can be replaced with:
|-----------------|:--------:|-------------|
| `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><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 All @@ -197,7 +198,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, <br>`std` (default) or `full` for Liberica|
| `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.*
Expand Down
10 changes: 5 additions & 5 deletions __tests__/liberica.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ test('find latest JDK version', async () => {

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')
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 `full` version for aarch64 and/or musl
// This check can fail on Linux because there's no `jdk+fx` package for aarch64 and/or musl
await expectURL(
'21.0.2+14',
'full',
'jdk+fx',
'bellsoft-liberica-vm-full-openjdk21.0.2'
)
}
Expand Down Expand Up @@ -127,10 +127,10 @@ async function expectLatestToFail(pattern: string) {

async function expectURL(
javaVersion: string,
version: string,
javaPackage: string,
expectedPrefix: string
) {
const url = await liberica.findLibericaURL(javaVersion, version)
const url = await liberica.findLibericaURL(javaVersion, javaPackage)
expect(url).toBeDefined()
const parts = url.split('/')
const file = parts[parts.length - 1]
Expand Down
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
3 changes: 2 additions & 1 deletion dist/cleanup/index.js

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

26 changes: 15 additions & 11 deletions dist/main/index.js

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

1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as otypes from '@octokit/types'
export const INPUT_VERSION = 'version'
export const INPUT_GDS_TOKEN = 'gds-token'
export const INPUT_JAVA_VERSION = 'java-version'
export const INPUT_JAVA_PACKAGE = 'java-package'
export const INPUT_DISTRIBUTION = 'distribution'
export const INPUT_COMPONENTS = 'components'
export const INPUT_GITHUB_TOKEN = 'github-token'
Expand Down
26 changes: 13 additions & 13 deletions src/liberica.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ const LIBERICA_VM_PREFIX = 'bellsoft-liberica-vm-'

export async function setUpLiberica(
javaVersion: string,
version: string
javaPackage: string
): Promise<string> {
const resolvedJavaVersion = await findLatestLibericaJavaVersion(javaVersion)
const downloadUrl = await findLibericaURL(resolvedJavaVersion, version)
const toolName = determineToolName(javaVersion, version)
const downloadUrl = await findLibericaURL(resolvedJavaVersion, javaPackage)
const toolName = determineToolName(javaVersion, javaPackage)
return downloadExtractAndCacheJDK(
async () => downloadTool(downloadUrl),
toolName,
Expand Down Expand Up @@ -61,16 +61,16 @@ export async function findLatestLibericaJavaVersion(

export async function findLibericaURL(
javaVersion: string,
version: string
javaPackage: string
): Promise<string> {
const release = await getTaggedRelease(
LIBERICA_GH_USER,
LIBERICA_RELEASES_REPO,
LIBERICA_JDK_TAG_PREFIX + javaVersion
)
const platform = determinePlatformPart()
const assetPrefix = `${LIBERICA_VM_PREFIX}${determineToolVersionPart(
version
const assetPrefix = `${LIBERICA_VM_PREFIX}${determineVariantPart(
javaPackage
)}openjdk${javaVersion}`
const assetSuffix = `-${platform}${c.GRAALVM_FILE_EXTENSION}`
for (const asset of release.assets) {
Expand All @@ -82,18 +82,18 @@ export async function findLibericaURL(
}
}
throw new Error(
`Unable to find asset for java-version: ${javaVersion}, version: ${version}, platform: ${platform}`
`Unable to find asset for java-version: ${javaVersion}, java-package: ${javaPackage}, platform: ${platform}`
)
}

function determineToolVersionPart(version: string) {
return version === 'std' || version === '' ? '' : `${version}-`
function determineToolName(javaVersion: string, javaPackage: string) {
const variant = determineVariantPart(javaPackage)
const platform = determinePlatformPart()
return `${LIBERICA_VM_PREFIX}${variant}openjdk${javaVersion}-${platform}`
}

function determineToolName(javaVersion: string, version: string) {
return `${LIBERICA_VM_PREFIX}${determineToolVersionPart(
version
)}openjdk${javaVersion}-${determinePlatformPart()}`
function determineVariantPart(javaPackage: string) {
return javaPackage !== null && javaPackage.includes('+fx') ? 'full-' : ''
}

function determinePlatformPart() {
Expand Down
3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {exec} from '@actions/exec'
async function run(): Promise<void> {
try {
const javaVersion = core.getInput(c.INPUT_JAVA_VERSION, {required: true})
const javaPackage = core.getInput(c.INPUT_JAVA_PACKAGE)
const distribution = core.getInput(c.INPUT_DISTRIBUTION)
const graalVMVersion = core.getInput(c.INPUT_VERSION)
const gdsToken = core.getInput(c.INPUT_GDS_TOKEN)
Expand Down Expand Up @@ -63,7 +64,7 @@ async function run(): Promise<void> {
graalVMHome = await setUpMandrel(graalVMVersion, javaVersion)
break
case c.DISTRIBUTION_LIBERICA:
graalVMHome = await setUpLiberica(javaVersion, graalVMVersion)
graalVMHome = await setUpLiberica(javaVersion, javaPackage)
break
case '':
if (javaVersion === c.VERSION_DEV) {
Expand Down

0 comments on commit 25bad63

Please sign in to comment.