Add support for Mandrel.

This commit is contained in:
Fabio Niephaus 2022-01-03 09:00:36 +01:00 committed by Fabio Niephaus
parent 7a1abedd1b
commit eff06eabf9
7 changed files with 179 additions and 9 deletions

View File

@ -41,6 +41,14 @@ jobs:
java-version: '17'
components: 'native-image'
os: windows-2016
- version: 'mandrel-latest'
java-version: '11'
components: ''
os: ubuntu-latest
- version: 'mandrel-21.3.0.0-Final'
java-version: '17'
components: ''
os: windows-latest
steps:
- uses: actions/checkout@v2
- name: Run setup-graalvm action

View File

@ -5,7 +5,7 @@ This GitHub action sets up [GraalVM Community Edition][repo] and GraalVM compone
This action:
- supports GraalVM CE [releases], [dev builds][dev-builds], and building from [source][repo] (see [options](#options))
- supports GraalVM CE [releases], [dev builds][dev-builds], building from [source][repo], and [Mandrel][mandrel] (see [options](#options))
- has built-in support for GraalVM components and the [GraalVM updater][gu]
- exports a `$GRAALVM_HOME` environment variable
- adds `$GRAALVM_HOME/bin` to the `$PATH` environment variable<br>(GraalVM tools such as `gu` and GraalVM languages can be invoked directly)
@ -89,7 +89,7 @@ jobs:
| Name | Default | Description |
|-----------------|:--------:|-------------|
| `version`<br>*(required)* | n/a | `X.Y.Z` (e.g., `22.0.0`) for a specific [GraalVM release][releases]<br>`latest` for [latest stable release][stable],<br>`dev` for [latest dev build][dev-build],<br>`trunk` for building GraalVM from [source][repo] (slow, can take several minutes). |
| `version`<br>*(required)* | n/a | `X.Y.Z` (e.g., `22.0.0`) for a specific [GraalVM release][releases]<br>`latest` for [latest stable release][stable],<br>`dev` for [latest dev build][dev-build],<br>`trunk` for building GraalVM from [source][repo] (slow, can take several minutes),<br>`mandrel-X.Y.Z` (e.g., `mandrel-21.3.0.0-Final`) for a specific [Mandrel release][mandrel-releases], or<br>`mandrel-latest` for [latest Mandrel stable release][mandrel-stable]. |
| `java-version`<br>*(required)* | n/a | `'11'` or `'17'` for a specific Java version.<br>(`'8'` and `'16'` are supported for GraalVM 21.2 and earlier.) |
| `components` | `''` | Comma-spearated list of GraalVM components (e.g., `native-image` or `ruby,nodejs`) that will be installed by the [GraalVM Updater][gu]. |
| `github-token` | `''` | Token for communication with the GitHub API. Please set to `${{ secrets.GITHUB_TOKEN }}` (see [templates](#templates)) to allow the action to authenticate with the GitHub API, which helps to reduce rate limiting issues. |
@ -106,6 +106,9 @@ Only pull requests from committers that can be verified as having signed the OCA
[dev-builds]: https://github.com/graalvm/graalvm-ce-dev-builds
[graalvm-languages]: https://www.graalvm.org/reference-manual/languages/
[gu]: https://www.graalvm.org/reference-manual/graalvm-updater/
[mandrel]: https://github.com/graalvm/mandrel
[mandrel-releases]: https://github.com/graalvm/mandrel/releases
[mandrel-stable]: https://github.com/graalvm/mandrel/releases/latest
[native-image]: https://www.graalvm.org/native-image/
[oca]: https://oca.opensource.oracle.com
[releases]: https://github.com/graalvm/graalvm-ce-builds/releases

95
dist/index.js generated vendored
View File

@ -7,7 +7,7 @@ require('./sourcemap-register.js');/******/ (() => { // webpackBootstrap
"use strict";
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.JDK_HOME_SUFFIX = exports.GRAALVM_PLATFORM = exports.GRAALVM_GH_USER = exports.GRAALVM_FILE_EXTENSION = exports.GRAALVM_BASE = exports.VERSION_TRUNK = exports.VERSION_LATEST = exports.VERSION_DEV = exports.IS_WINDOWS = exports.IS_MACOS = void 0;
exports.MANDREL_NAMESPACE = exports.JDK_HOME_SUFFIX = exports.GRAALVM_PLATFORM = exports.GRAALVM_GH_USER = exports.GRAALVM_FILE_EXTENSION = exports.GRAALVM_BASE = exports.VERSION_TRUNK = exports.VERSION_LATEST = exports.VERSION_DEV = exports.IS_WINDOWS = exports.IS_MACOS = void 0;
const os_1 = __nccwpck_require__(2037);
const path_1 = __nccwpck_require__(1017);
exports.IS_MACOS = process.platform === 'darwin';
@ -20,6 +20,7 @@ exports.GRAALVM_FILE_EXTENSION = exports.IS_WINDOWS ? '.zip' : '.tar.gz';
exports.GRAALVM_GH_USER = 'graalvm';
exports.GRAALVM_PLATFORM = exports.IS_WINDOWS ? 'windows' : process.platform;
exports.JDK_HOME_SUFFIX = exports.IS_MACOS ? '/Contents/Home' : '';
exports.MANDREL_NAMESPACE = 'mandrel-';
/***/ }),
@ -400,6 +401,7 @@ const io_1 = __nccwpck_require__(7436);
const dependencies_1 = __nccwpck_require__(6031);
const gu_1 = __nccwpck_require__(3466);
const graalvm_trunk_1 = __nccwpck_require__(7538);
const mandrel_1 = __nccwpck_require__(438);
const msvc_1 = __nccwpck_require__(4765);
function run() {
return __awaiter(this, void 0, void 0, function* () {
@ -427,7 +429,12 @@ function run() {
graalVMHome = yield (0, graalvm_trunk_1.setUpGraalVMTrunk)(javaVersion, components);
break;
default:
graalVMHome = yield graalvm.setUpGraalVMRelease(graalvmVersion, javaVersion);
if (graalvmVersion.startsWith(c.MANDREL_NAMESPACE)) {
graalVMHome = yield (0, mandrel_1.setUpMandrel)(graalvmVersion, javaVersion);
}
else {
graalVMHome = yield graalvm.setUpGraalVMRelease(graalvmVersion, javaVersion);
}
break;
}
// Activate GraalVM
@ -442,6 +449,9 @@ function run() {
if (graalvmVersion === c.VERSION_TRUNK) {
// components built from source, nothing to do
}
else if (graalvmVersion.startsWith(c.MANDREL_NAMESPACE)) {
core.warning(`Mandrel does not support GraalVM components: ${componentsString}`);
}
else {
yield (0, gu_1.setUpGUComponents)(graalVMHome, components);
}
@ -456,6 +466,87 @@ function run() {
run();
/***/ }),
/***/ 438:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.setUpMandrel = void 0;
const c = __importStar(__nccwpck_require__(5105));
const utils_1 = __nccwpck_require__(918);
const MANDREL_REPO = 'mandrel';
const MANDREL_TAG_PREFIX = c.MANDREL_NAMESPACE;
const MANDREL_DL_BASE = 'https://github.com/graalvm/mandrel/releases/download';
function setUpMandrel(graalvmVersion, javaVersion) {
return __awaiter(this, void 0, void 0, function* () {
const mandrelVersion = graalvmVersion.substring(c.MANDREL_NAMESPACE.length, graalvmVersion.length);
let mandrelHome;
switch (mandrelVersion) {
case 'latest':
mandrelHome = yield setUpMandrelLatest(javaVersion);
break;
default:
mandrelHome = yield setUpMandrelRelease(mandrelVersion, javaVersion);
break;
}
return mandrelHome;
});
}
exports.setUpMandrel = setUpMandrel;
function setUpMandrelLatest(javaVersion) {
return __awaiter(this, void 0, void 0, function* () {
const latestRelease = yield (0, utils_1.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);
}
throw new Error(`Could not find latest Mandrel release: ${tag_name}`);
});
}
function setUpMandrelRelease(version, javaVersion) {
return __awaiter(this, void 0, void 0, function* () {
const identifier = determineMandrelIdentifier(version, javaVersion);
const downloadUrl = `${MANDREL_DL_BASE}/${MANDREL_TAG_PREFIX}${version}/${identifier}${c.GRAALVM_FILE_EXTENSION}`;
return (0, utils_1.downloadAndExtractJDK)(downloadUrl);
});
}
function determineMandrelIdentifier(version, javaVersion) {
return `mandrel-java${javaVersion}-${c.GRAALVM_PLATFORM}-amd64-${version}`;
}
/***/ }),
/***/ 4765:

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@ -15,5 +15,7 @@ export const GRAALVM_GH_USER = 'graalvm'
export const GRAALVM_PLATFORM = IS_WINDOWS ? 'windows' : process.platform
export const JDK_HOME_SUFFIX = IS_MACOS ? '/Contents/Home' : ''
export const MANDREL_NAMESPACE = 'mandrel-'
export type LatestReleaseResponse =
otypes.Endpoints['GET /repos/{owner}/{repo}/releases/latest']['response']

View File

@ -6,6 +6,7 @@ import {mkdirP} from '@actions/io'
import {setUpDependencies} from './dependencies'
import {setUpGUComponents} from './gu'
import {setUpGraalVMTrunk} from './graalvm-trunk'
import {setUpMandrel} from './mandrel'
import {setUpWindowsEnvironment} from './msvc'
async function run(): Promise<void> {
@ -37,10 +38,14 @@ async function run(): Promise<void> {
graalVMHome = await setUpGraalVMTrunk(javaVersion, components)
break
default:
graalVMHome = await graalvm.setUpGraalVMRelease(
graalvmVersion,
javaVersion
)
if (graalvmVersion.startsWith(c.MANDREL_NAMESPACE)) {
graalVMHome = await setUpMandrel(graalvmVersion, javaVersion)
} else {
graalVMHome = await graalvm.setUpGraalVMRelease(
graalvmVersion,
javaVersion
)
}
break
}
@ -56,6 +61,10 @@ async function run(): Promise<void> {
if (components.length > 0) {
if (graalvmVersion === c.VERSION_TRUNK) {
// components built from source, nothing to do
} else if (graalvmVersion.startsWith(c.MANDREL_NAMESPACE)) {
core.warning(
`Mandrel does not support GraalVM components: ${componentsString}`
)
} else {
await setUpGUComponents(graalVMHome, components)
}

57
src/mandrel.ts Normal file
View File

@ -0,0 +1,57 @@
import * as c from './constants'
import {downloadAndExtractJDK, getLatestRelease} from './utils'
const MANDREL_REPO = 'mandrel'
const MANDREL_TAG_PREFIX = c.MANDREL_NAMESPACE
const MANDREL_DL_BASE = 'https://github.com/graalvm/mandrel/releases/download'
export async function setUpMandrel(
graalvmVersion: string,
javaVersion: string
): Promise<string> {
const mandrelVersion = graalvmVersion.substring(
c.MANDREL_NAMESPACE.length,
graalvmVersion.length
)
let mandrelHome
switch (mandrelVersion) {
case 'latest':
mandrelHome = await setUpMandrelLatest(javaVersion)
break
default:
mandrelHome = await setUpMandrelRelease(mandrelVersion, javaVersion)
break
}
return mandrelHome
}
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)
}
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}`
return downloadAndExtractJDK(downloadUrl)
}
function determineMandrelIdentifier(
version: string,
javaVersion: string
): string {
return `mandrel-java${javaVersion}-${c.GRAALVM_PLATFORM}-amd64-${version}`
}