Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d72e3dbf5f | ||
|
|
22551b2bec | ||
|
|
bf3e45bce6 | ||
|
|
1588b03f82 | ||
|
|
6df9f698c6 | ||
|
|
2408275e34 | ||
|
|
a638430bc0 | ||
|
|
3bd233e767 | ||
|
|
c99915cc1a | ||
|
|
a0f131ece5 | ||
|
|
a1b47fdf04 | ||
|
|
129a551a10 | ||
|
|
b8dc5fccfb | ||
|
|
1c219f5b27 | ||
|
|
2a93b69fdf | ||
|
|
0b782b6b90 | ||
|
|
d5b07dd118 | ||
|
|
40dc6ae006 | ||
|
|
cde0daed27 | ||
|
|
22b65d7de0 | ||
|
|
c2fd2d6d8e | ||
|
|
2b3d0bde8f |
6
.github/workflows/check-dist.yml
vendored
6
.github/workflows/check-dist.yml
vendored
@@ -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
|
||||
|
||||
25
.github/workflows/test.yml
vendored
25
.github/workflows/test.yml
vendored
@@ -27,9 +27,17 @@ 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: '22-ea'
|
||||
distribution: 'graalvm'
|
||||
os: ubuntu-latest
|
||||
- java-version: '21'
|
||||
distribution: ''
|
||||
os: ubuntu-latest
|
||||
@@ -40,6 +48,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
|
||||
@@ -187,7 +198,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 +207,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 +314,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'
|
||||
|
||||
59
README.md
59
README.md
@@ -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
|
||||
@@ -162,6 +134,35 @@ 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 |
|
||||
@@ -176,7 +177,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.*
|
||||
|
||||
@@ -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:.*/)
|
||||
)
|
||||
})
|
||||
|
||||
@@ -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()
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
75
__tests__/mandrel.test.ts
Normal file
75
__tests__/mandrel.test.ts
Normal 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}`)
|
||||
}
|
||||
})
|
||||
34
__tests__/utils.test.ts
Normal file
34
__tests__/utils.test.ts
Normal 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')
|
||||
}
|
||||
})
|
||||
@@ -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
33096
dist/cleanup/index.js
generated
vendored
File diff suppressed because one or more lines are too long
32719
dist/main/index.js
generated
vendored
32719
dist/main/index.js
generated
vendored
File diff suppressed because one or more lines are too long
9449
package-lock.json
generated
9449
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
56
package.json
56
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "setup-graalvm",
|
||||
"version": "1.1.4",
|
||||
"version": "1.1.7",
|
||||
"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"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,9 @@ 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']
|
||||
|
||||
function determineJDKArchitecture(): string {
|
||||
switch (process.arch) {
|
||||
case 'x64': {
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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.7 (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`)
|
||||
|
||||
@@ -1,18 +1,21 @@
|
||||
import * as c from './constants'
|
||||
import * as semver from 'semver'
|
||||
import {
|
||||
downloadAndExtractJDK,
|
||||
downloadExtractAndCacheJDK,
|
||||
getLatestPrerelease,
|
||||
getLatestRelease,
|
||||
getMatchingTags,
|
||||
getTaggedRelease
|
||||
getTaggedRelease,
|
||||
toSemVer
|
||||
} from './utils'
|
||||
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-dev-builds'
|
||||
const GRAALVM_REPO_DEV_BUILDS = 'graalvm-ce-dev-builds'
|
||||
const GRAALVM_JDK_TAG_PREFIX = 'jdk-'
|
||||
const GRAALVM_TAG_PREFIX = 'vm-'
|
||||
@@ -27,17 +30,54 @@ export async function setUpGraalVMJDK(
|
||||
}
|
||||
const 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 (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 if (javaVersion === '22-ea') {
|
||||
downloadUrl = await findLatestEABuildDownloadUrl(javaVersion)
|
||||
} 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)
|
||||
}
|
||||
|
||||
async function findLatestEABuildDownloadUrl(
|
||||
javaEaVersion: string
|
||||
): Promise<string> {
|
||||
const latestPrerelease = await getLatestPrerelease(
|
||||
ORACLE_GRAALVM_REPO_EA_BUILDS
|
||||
)
|
||||
const expectedFileNamePrefix = 'graalvm-jdk-'
|
||||
const expectedFileNameSuffix = `_${c.JDK_PLATFORM}-${c.JDK_ARCH}_bin${c.GRAALVM_FILE_EXTENSION}`
|
||||
for (const asset of latestPrerelease.assets) {
|
||||
if (
|
||||
asset.name.startsWith(expectedFileNamePrefix) &&
|
||||
asset.name.endsWith(expectedFileNameSuffix)
|
||||
) {
|
||||
return asset.browser_download_url
|
||||
}
|
||||
}
|
||||
throw new Error(
|
||||
`Could not find Oracle GraalVM build for ${javaEaVersion}. ${c.ERROR_HINT}`
|
||||
)
|
||||
}
|
||||
|
||||
export async function setUpGraalVMJDKCE(
|
||||
javaVersionOrDev: string
|
||||
): Promise<string> {
|
||||
@@ -71,8 +111,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
|
||||
}
|
||||
|
||||
@@ -58,13 +58,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) {
|
||||
|
||||
139
src/mandrel.ts
139
src/mandrel.ts
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
46
src/utils.ts
46
src/utils.ts
@@ -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'
|
||||
@@ -33,6 +34,25 @@ export async function exec(
|
||||
}
|
||||
}
|
||||
|
||||
export async function getLatestPrerelease(
|
||||
repo: string
|
||||
): Promise<c.ReleasesResponse['data'][number]> {
|
||||
const githubToken = getGitHubToken()
|
||||
const options = githubToken.length > 0 ? {auth: githubToken} : {}
|
||||
const octokit = new GitHubDotCom(options)
|
||||
const releases: c.ReleasesResponse['data'] = (
|
||||
await octokit.request('GET /repos/{owner}/{repo}/releases', {
|
||||
owner: c.GRAALVM_GH_USER,
|
||||
repo
|
||||
})
|
||||
).data
|
||||
const firstPrerelease = releases.find(r => r.prerelease)
|
||||
if (!firstPrerelease) {
|
||||
throw new Error(`Unable to find latest prerelease in ${repo}`)
|
||||
}
|
||||
return firstPrerelease
|
||||
}
|
||||
|
||||
export async function getLatestRelease(
|
||||
repo: string
|
||||
): Promise<c.LatestReleaseResponse['data']> {
|
||||
@@ -135,17 +155,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 {
|
||||
|
||||
Reference in New Issue
Block a user