Skip to content

Commit

Permalink
Add distribution_url property to override download URL
Browse files Browse the repository at this point in the history
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 #60
  • Loading branch information
sgammon committed Sep 13, 2023
1 parent 0e29e36 commit 4f805f7
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 15 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`<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]. |
| `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.*

Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
20 changes: 12 additions & 8 deletions src/graalvm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {
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 {
Expand All @@ -39,10 +42,11 @@ export async function setUpGraalVMJDK(
}

export async function setUpGraalVMJDKCE(
javaVersionOrDev: string
javaVersionOrDev: string,
customDistributionUrl: string
): Promise<string> {
if (javaVersionOrDev === c.VERSION_DEV) {
return setUpGraalVMJDKDevBuild()
return setUpGraalVMJDKDevBuild(customDistributionUrl)
}
let javaVersion = javaVersionOrDev
if (!javaVersion.includes('.')) {
Expand All @@ -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)
}
Expand Down Expand Up @@ -114,13 +118,13 @@ async function downloadGraalVMJDK(

// Support for GraalVM dev builds

export async function setUpGraalVMJDKDevBuild(): Promise<string> {
export async function setUpGraalVMJDKDevBuild(customDistributionUrl: string): Promise<string> {
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)
}

Expand Down
15 changes: 8 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ async function run(): Promise<void> {
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)
Expand Down Expand Up @@ -45,10 +46,10 @@ async function run(): Promise<void> {
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)) {
Expand All @@ -64,12 +65,12 @@ async function run(): Promise<void> {
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:
Expand All @@ -85,7 +86,7 @@ async function run(): Promise<void> {
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,
Expand All @@ -107,9 +108,9 @@ async function run(): Promise<void> {
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:
Expand Down

0 comments on commit 4f805f7

Please sign in to comment.