From 0711c08964f86c1721bebb824b2ac856457e0f55 Mon Sep 17 00:00:00 2001 From: Sam Gammon Date: Wed, 13 Sep 2023 16:07:39 -0700 Subject: [PATCH] Add `distribution_url` property to override download URL. Adds a `distribution_url` property to the action, which overrides the download URL unconditionally. It is up to the caller to provide an archive which works on their Github Actions runner; there is no way (at this time) to vary the distribution URL by architecture or OS. - feat: add `distribution_url` input option - feat: honor `distribution_url` in all branches - chore: update docs with `distribution_url` info Fixes and closes graalvm/setup-graalvm#60 Signed-off-by: Sam Gammon --- README.md | 1 + action.yml | 4 ++++ src/constants.ts | 1 + src/graalvm.ts | 20 ++++++++++++-------- src/main.ts | 15 ++++++++------- 5 files changed, 26 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index ab79d75..dfe6f0c 100644 --- a/README.md +++ b/README.md @@ -178,6 +178,7 @@ jobs: | `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`
`mandrel-X.Y.Z` (e.g., `mandrel-21.3.0.0-Final`) for a specific [Mandrel release][mandrel-releases],
`mandrel-latest` for [latest Mandrel stable release][mandrel-stable]. | | `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)). | +| `distribution_url` | `''` | Custom GraalVM distribution URL to use; should point to an archive which has the same structure as a GraalVM release. Must be a `zip` or `tar.gz`. | **) Make sure that Native Image is used only once per build job. Otherwise, the report is only generated for the last Native Image build.* diff --git a/action.yml b/action.yml index 1eac87a..de63780 100644 --- a/action.yml +++ b/action.yml @@ -12,6 +12,10 @@ inputs: description: 'GraalVM distribution. See the list of available distributions in the README file.' required: false default: '' + distribution_url: + description: 'Custom GraalVM distribution URL. Expects an archive in the same structure as a GraalVM release.' + required: false + default: '' components: required: false description: 'Comma-separated list of GraalVM components to be installed.' diff --git a/src/constants.ts b/src/constants.ts index a021f0e..743a072 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -4,6 +4,7 @@ export const INPUT_VERSION = 'version' export const INPUT_GDS_TOKEN = 'gds-token' export const INPUT_JAVA_VERSION = 'java-version' export const INPUT_DISTRIBUTION = 'distribution' +export const INPUT_DISTRIBUTION_URL = 'distribution_url' export const INPUT_COMPONENTS = 'components' export const INPUT_GITHUB_TOKEN = 'github-token' export const INPUT_SET_JAVA_HOME = 'set-java-home' diff --git a/src/graalvm.ts b/src/graalvm.ts index edf7ef7..e663348 100644 --- a/src/graalvm.ts +++ b/src/graalvm.ts @@ -20,15 +20,18 @@ const GRAALVM_TAG_PREFIX = 'vm-' // Support for GraalVM for JDK 17 and later export async function setUpGraalVMJDK( - javaVersionOrDev: string + javaVersionOrDev: string, + customDistributionUrl: string ): Promise { if (javaVersionOrDev === c.VERSION_DEV) { - return setUpGraalVMJDKDevBuild() + return setUpGraalVMJDKDevBuild(customDistributionUrl) } const javaVersion = javaVersionOrDev const toolName = determineToolName(javaVersion, false) let downloadUrl: string - if (javaVersion.includes('.')) { + if (customDistributionUrl) { + downloadUrl = customDistributionUrl; + } else if (javaVersion.includes('.')) { const majorJavaVersion = javaVersion.split('.')[0] downloadUrl = `${GRAALVM_DL_BASE}/${majorJavaVersion}/archive/${toolName}${c.GRAALVM_FILE_EXTENSION}` } else { @@ -39,10 +42,11 @@ export async function setUpGraalVMJDK( } export async function setUpGraalVMJDKCE( - javaVersionOrDev: string + javaVersionOrDev: string, + customDistributionUrl: string ): Promise { if (javaVersionOrDev === c.VERSION_DEV) { - return setUpGraalVMJDKDevBuild() + return setUpGraalVMJDKDevBuild(customDistributionUrl) } let javaVersion = javaVersionOrDev if (!javaVersion.includes('.')) { @@ -54,7 +58,7 @@ export async function setUpGraalVMJDKCE( ) } const toolName = determineToolName(javaVersion, true) - const downloadUrl = `${GRAALVM_CE_DL_BASE}/jdk-${javaVersion}/${toolName}${c.GRAALVM_FILE_EXTENSION}` + const downloadUrl = customDistributionUrl || `${GRAALVM_CE_DL_BASE}/jdk-${javaVersion}/${toolName}${c.GRAALVM_FILE_EXTENSION}` const downloader = async () => downloadGraalVMJDK(downloadUrl, javaVersion) return downloadExtractAndCacheJDK(downloader, toolName, javaVersion) } @@ -114,13 +118,13 @@ async function downloadGraalVMJDK( // Support for GraalVM dev builds -export async function setUpGraalVMJDKDevBuild(): Promise { +export async function setUpGraalVMJDKDevBuild(customDistributionUrl: string): Promise { const latestDevBuild = await getLatestRelease(GRAALVM_REPO_DEV_BUILDS) const resolvedJavaVersion = findHighestJavaVersion( latestDevBuild, c.VERSION_DEV ) - const downloadUrl = findDownloadUrl(latestDevBuild, resolvedJavaVersion) + const downloadUrl = customDistributionUrl || findDownloadUrl(latestDevBuild, resolvedJavaVersion) return downloadAndExtractJDK(downloadUrl) } diff --git a/src/main.ts b/src/main.ts index 7775671..5e56d41 100644 --- a/src/main.ts +++ b/src/main.ts @@ -17,6 +17,7 @@ async function run(): Promise { try { const javaVersion = core.getInput(c.INPUT_JAVA_VERSION, {required: true}) const distribution = core.getInput(c.INPUT_DISTRIBUTION) + const customDistributionUrl = core.getInput(c.INPUT_DISTRIBUTION_URL) const graalVMVersion = core.getInput(c.INPUT_VERSION) const gdsToken = core.getInput(c.INPUT_GDS_TOKEN) const componentsString: string = core.getInput(c.INPUT_COMPONENTS) @@ -45,10 +46,10 @@ async function run(): Promise { if (isGraalVMforJDK17OrLater) { switch (distribution) { case c.DISTRIBUTION_GRAALVM: - graalVMHome = await graalvm.setUpGraalVMJDK(javaVersion) + graalVMHome = await graalvm.setUpGraalVMJDK(javaVersion, customDistributionUrl) break case c.DISTRIBUTION_GRAALVM_COMMUNITY: - graalVMHome = await graalvm.setUpGraalVMJDKCE(javaVersion) + graalVMHome = await graalvm.setUpGraalVMJDKCE(javaVersion, customDistributionUrl) break case c.DISTRIBUTION_MANDREL: if (graalVMVersion.startsWith(c.MANDREL_NAMESPACE)) { @@ -64,12 +65,12 @@ async function run(): Promise { core.info( `This build is using GraalVM Community Edition. To select a specific distribution, use the 'distribution' option (see https://github.com/graalvm/setup-graalvm/tree/main#options).` ) - graalVMHome = await graalvm.setUpGraalVMJDKDevBuild() + graalVMHome = await graalvm.setUpGraalVMJDKDevBuild(customDistributionUrl) } else { core.info( `This build is using the new Oracle GraalVM. To select a specific distribution, use the 'distribution' option (see https://github.com/graalvm/setup-graalvm/tree/main#options).` ) - graalVMHome = await graalvm.setUpGraalVMJDK(javaVersion) + graalVMHome = await graalvm.setUpGraalVMJDK(javaVersion, customDistributionUrl) } break default: @@ -85,7 +86,7 @@ async function run(): Promise { core.info( `This build is using the new Oracle GraalVM. To select a specific distribution, use the 'distribution' option (see https://github.com/graalvm/setup-graalvm/tree/main#options).` ) - graalVMHome = await graalvm.setUpGraalVMJDK(javaVersion) + graalVMHome = await graalvm.setUpGraalVMJDK(javaVersion, customDistributionUrl) } else { graalVMHome = await graalvm.setUpGraalVMLatest_22_X( gdsToken, @@ -107,9 +108,9 @@ async function run(): Promise { core.warning( `GraalVM dev builds are only available for JDK 21. This build is now using a stable release of GraalVM for JDK ${javaVersion}.` ) - graalVMHome = await graalvm.setUpGraalVMJDK(javaVersion) + graalVMHome = await graalvm.setUpGraalVMJDK(javaVersion, customDistributionUrl) } else { - graalVMHome = await graalvm.setUpGraalVMJDKDevBuild() + graalVMHome = await graalvm.setUpGraalVMJDKDevBuild(customDistributionUrl) } break default: