mirror of
https://github.com/graalvm/setup-graalvm.git
synced 2025-03-13 14:30:15 +08:00
Merge remote-tracking branch 'upstream/main'
# Conflicts: # dist/main/index.js
This commit is contained in:
commit
4f45574efe
15
.github/workflows/test.yml
vendored
15
.github/workflows/test.yml
vendored
@ -40,6 +40,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 +190,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 +199,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 +306,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'
|
||||
|
@ -176,7 +176,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.*
|
||||
|
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}`)
|
||||
}
|
||||
})
|
137838
dist/main/index.js
generated
vendored
137838
dist/main/index.js
generated
vendored
File diff suppressed because one or more lines are too long
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "setup-graalvm",
|
||||
"version": "1.1.4",
|
||||
"version": "1.1.5",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "setup-graalvm",
|
||||
"version": "1.1.4",
|
||||
"version": "1.1.5",
|
||||
"license": "UPL",
|
||||
"dependencies": {
|
||||
"@actions/cache": "^3.0.4",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "setup-graalvm",
|
||||
"version": "1.1.4",
|
||||
"version": "1.1.5",
|
||||
"private": true,
|
||||
"description": "GitHub Action for GraalVM",
|
||||
"main": "lib/main.js",
|
||||
|
@ -32,7 +32,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.5 (arch:${c.GRAALVM_ARCH}; os:${c.GRAALVM_PLATFORM}; java:${javaVersion})`
|
||||
const baseArtifact = await fetchArtifact(
|
||||
userAgent,
|
||||
'isBase:True',
|
||||
|
@ -1,4 +1,5 @@
|
||||
import * as c from './constants'
|
||||
import * as semver from 'semver'
|
||||
import {
|
||||
downloadAndExtractJDK,
|
||||
downloadExtractAndCacheJDK,
|
||||
@ -9,7 +10,6 @@ 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`
|
||||
@ -26,11 +26,25 @@ export async function setUpGraalVMJDK(
|
||||
return setUpGraalVMJDKDevBuild()
|
||||
}
|
||||
const javaVersion = javaVersionOrDev
|
||||
const toolName = determineToolName(javaVersion, false)
|
||||
let toolName = determineToolName(javaVersion, false)
|
||||
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
|
||||
let downloadName = toolName
|
||||
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}`
|
||||
}
|
||||
@ -71,8 +85,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
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user