mirror of
https://github.com/actions/setup-java.git
synced 2026-06-23 08:19:41 +00:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2061db5b9b | |||
| c1835719f6 | |||
| 8a5fc42d92 | |||
| 05917d5627 | |||
| 651865a8a8 | |||
| 5431e71f9a | |||
| 4baa9b45d2 | |||
| 34df7e6dff | |||
| a263f84254 | |||
| 6929a11922 | |||
| ad52b8c6db | |||
| 2321ab295d | |||
| 849c8f0094 |
@@ -0,0 +1,6 @@
|
||||
# Ignore list
|
||||
/*
|
||||
|
||||
# Do not ignore these folders:
|
||||
!__tests__/
|
||||
!src/
|
||||
@@ -0,0 +1,51 @@
|
||||
// This is a reusable configuration file copied from https://github.com/actions/reusable-workflows/tree/main/reusable-configurations. Please don't make changes to this file as it's the subject of an automatic update.
|
||||
module.exports = {
|
||||
extends: [
|
||||
'eslint:recommended',
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
'plugin:eslint-plugin-jest/recommended',
|
||||
'eslint-config-prettier'
|
||||
],
|
||||
parser: '@typescript-eslint/parser',
|
||||
plugins: ['@typescript-eslint', 'eslint-plugin-node', 'eslint-plugin-jest'],
|
||||
rules: {
|
||||
'@typescript-eslint/no-require-imports': 'error',
|
||||
'@typescript-eslint/no-non-null-assertion': 'off',
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
'@typescript-eslint/no-empty-function': 'off',
|
||||
'@typescript-eslint/ban-ts-comment': [
|
||||
'error',
|
||||
{
|
||||
'ts-ignore': 'allow-with-description'
|
||||
}
|
||||
],
|
||||
'no-console': 'error',
|
||||
'yoda': 'error',
|
||||
'prefer-const': [
|
||||
'error',
|
||||
{
|
||||
destructuring: 'all'
|
||||
}
|
||||
],
|
||||
'no-control-regex': 'off',
|
||||
'no-constant-condition': ['error', {checkLoops: false}],
|
||||
'node/no-extraneous-import': 'error'
|
||||
},
|
||||
overrides: [
|
||||
{
|
||||
files: ['**/*{test,spec}.ts'],
|
||||
rules: {
|
||||
'@typescript-eslint/no-unused-vars': 'off',
|
||||
'jest/no-standalone-expect': 'off',
|
||||
'jest/no-conditional-expect': 'off',
|
||||
'no-console': 'off',
|
||||
|
||||
}
|
||||
}
|
||||
],
|
||||
env: {
|
||||
node: true,
|
||||
es6: true,
|
||||
'jest/globals': true
|
||||
}
|
||||
};
|
||||
@@ -76,7 +76,7 @@ steps:
|
||||
with:
|
||||
distribution: 'temurin' # See 'Supported distributions' for available options
|
||||
java-version: '25'
|
||||
- run: java HelloWorldApp.java
|
||||
- run: java --version
|
||||
```
|
||||
|
||||
#### Azul Zulu OpenJDK
|
||||
@@ -87,7 +87,7 @@ steps:
|
||||
with:
|
||||
distribution: 'zulu' # See 'Supported distributions' for available options
|
||||
java-version: '25'
|
||||
- run: java HelloWorldApp.java
|
||||
- run: java --version
|
||||
```
|
||||
|
||||
#### Supported version syntax
|
||||
@@ -112,6 +112,7 @@ Currently, the following distributions are supported:
|
||||
| `dragonwell` | [Alibaba Dragonwell JDK](https://dragonwell-jdk.io/) | [`dragonwell` license](https://www.aliyun.com/product/dragonwell/)
|
||||
| `sapmachine` | [SAP SapMachine JDK/JRE](https://sapmachine.io/) | [`sapmachine` license](https://github.com/SAP/SapMachine/blob/sapmachine/LICENSE)
|
||||
| `graalvm` | [Oracle GraalVM](https://www.graalvm.org/) | [`graalvm` license](https://www.oracle.com/downloads/licenses/graal-free-license.html)
|
||||
| `graalvm-community` | [GraalVM Community](https://github.com/graalvm/graalvm-ce-builds/releases) | [`graalvm-community` license](https://github.com/oracle/graal/blob/master/LICENSE)
|
||||
| `jetbrains` | [JetBrains Runtime](https://github.com/JetBrains/JetBrainsRuntime/) | [`jetbrains` license](https://github.com/JetBrains/JetBrainsRuntime/blob/main/LICENSE)
|
||||
| `jdkfile` | Custom JDK Installation | |
|
||||
|
||||
@@ -120,6 +121,7 @@ Currently, the following distributions are supported:
|
||||
> - AdoptOpenJDK got moved to Eclipse Temurin and won't be updated anymore. It is highly recommended to migrate workflows from `adopt` and `adopt-openj9`, to `temurin` and `semeru` respectively, to keep receiving software and security updates. See more details in the [Good-bye AdoptOpenJDK post](https://blog.adoptopenjdk.net/2021/08/goodbye-adoptopenjdk-hello-adoptium/).
|
||||
> - For Azul Zulu OpenJDK architectures x64 and arm64 are mapped to x86 / arm with proper hw_bitness.
|
||||
> - To comply with the GraalVM Free Terms and Conditions (GFTC) license, it is recommended to use GraalVM JDK 17 version 17.0.12, as this is the only version of GraalVM JDK 17 available under the GFTC license. Additionally, it is encouraged to consider upgrading to GraalVM JDK 21, which offers the latest features and improvements.
|
||||
> - GraalVM Community is available as `distribution: 'graalvm-community'` for stable JDK 17 and later releases published on GitHub.
|
||||
|
||||
**NOTE:** Oracle JDK 17 licensing varies by patch level. As shown on the [JDK 17 Archive](https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html) (versions up to 17.0.12 are under the [NFTC](https://www.oracle.com/downloads/licenses/no-fee-license.html) license) and the [JDK 17.0.13+ Archive](https://www.oracle.com/java/technologies/javase/jdk17-0-13-later-archive-downloads.html) (versions 17.0.13 and later are under the [OTN](https://www.oracle.com/downloads/licenses/javase-license1.html) license). To stay on the free NFTC license, use `distribution: 'oracle'` with `java-version: '17.0.12'` (or earlier) instead of the floating `'17'`. Alternatively, upgrade to Oracle JDK 21+, which remains under the NFTC license.
|
||||
|
||||
@@ -221,7 +223,7 @@ steps:
|
||||
distribution: 'temurin'
|
||||
java-version: '25'
|
||||
check-latest: true
|
||||
- run: java HelloWorldApp.java
|
||||
- run: java --version
|
||||
```
|
||||
|
||||
### Testing against different Java versions
|
||||
@@ -240,7 +242,7 @@ jobs:
|
||||
with:
|
||||
distribution: '<distribution>'
|
||||
java-version: ${{ matrix.java }}
|
||||
- run: java HelloWorldApp.java
|
||||
- run: java --version
|
||||
```
|
||||
|
||||
### Install multiple JDKs
|
||||
|
||||
@@ -3,7 +3,11 @@ import * as tc from '@actions/tool-cache';
|
||||
import * as http from '@actions/http-client';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import {GraalVMDistribution} from '../../src/distributions/graalvm/installer';
|
||||
import {
|
||||
GraalVMCommunityDistribution,
|
||||
GraalVMDistribution
|
||||
} from '../../src/distributions/graalvm/installer';
|
||||
import {getJavaDistribution} from '../../src/distributions/distribution-factory';
|
||||
import {JavaInstallerOptions} from '../../src/distributions/base-models';
|
||||
import * as util from '../../src/util';
|
||||
|
||||
@@ -41,6 +45,7 @@ beforeAll(() => {
|
||||
|
||||
describe('GraalVMDistribution', () => {
|
||||
let distribution: GraalVMDistribution;
|
||||
let communityDistribution: GraalVMCommunityDistribution;
|
||||
let mockHttpClient: jest.Mocked<http.HttpClient>;
|
||||
let spyCoreError: jest.SpyInstance;
|
||||
|
||||
@@ -55,9 +60,11 @@ describe('GraalVMDistribution', () => {
|
||||
jest.clearAllMocks();
|
||||
|
||||
distribution = new GraalVMDistribution(defaultOptions);
|
||||
communityDistribution = new GraalVMCommunityDistribution(defaultOptions);
|
||||
|
||||
mockHttpClient = new http.HttpClient() as jest.Mocked<http.HttpClient>;
|
||||
(distribution as any).http = mockHttpClient;
|
||||
(communityDistribution as any).http = mockHttpClient;
|
||||
|
||||
(util.getDownloadArchiveExtension as jest.Mock).mockReturnValue('tar.gz');
|
||||
|
||||
@@ -242,6 +249,23 @@ describe('GraalVMDistribution', () => {
|
||||
path: '/cached/java/path'
|
||||
});
|
||||
});
|
||||
|
||||
it('should use a dedicated toolcache folder for GraalVM Community', async () => {
|
||||
const result = await (communityDistribution as any).downloadTool(
|
||||
javaRelease
|
||||
);
|
||||
|
||||
expect(tc.cacheDir).toHaveBeenCalledWith(
|
||||
path.join('/tmp/extracted', 'graalvm-jdk-17.0.5'),
|
||||
'Java_GraalVM_Community_jdk',
|
||||
'17.0.5',
|
||||
'x64'
|
||||
);
|
||||
expect(result).toEqual({
|
||||
version: '17.0.5',
|
||||
path: '/cached/java/path'
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('findPackageForDownload', () => {
|
||||
@@ -948,5 +972,107 @@ describe('GraalVMDistribution', () => {
|
||||
configurable: true
|
||||
});
|
||||
});
|
||||
|
||||
describe('GraalVMCommunityDistribution', () => {
|
||||
beforeEach(() => {
|
||||
jest
|
||||
.spyOn(communityDistribution, 'getPlatform')
|
||||
.mockReturnValue('linux');
|
||||
});
|
||||
|
||||
it('should resolve an exact GraalVM Community version from GitHub releases', async () => {
|
||||
mockHttpClient.getJson.mockResolvedValue({
|
||||
result: [
|
||||
{
|
||||
draft: false,
|
||||
prerelease: false,
|
||||
assets: [
|
||||
{
|
||||
name: 'graalvm-community-jdk-21.0.2_linux-x64_bin.tar.gz',
|
||||
browser_download_url:
|
||||
'https://github.com/graalvm/graalvm-ce-builds/releases/download/jdk-21.0.2/graalvm-community-jdk-21.0.2_linux-x64_bin.tar.gz'
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
statusCode: 200,
|
||||
headers: {}
|
||||
});
|
||||
|
||||
const result = await (
|
||||
communityDistribution as any
|
||||
).findPackageForDownload('21.0.2');
|
||||
|
||||
expect(result).toEqual({
|
||||
url: 'https://github.com/graalvm/graalvm-ce-builds/releases/download/jdk-21.0.2/graalvm-community-jdk-21.0.2_linux-x64_bin.tar.gz',
|
||||
version: '21.0.2'
|
||||
});
|
||||
});
|
||||
|
||||
it('should resolve the latest GraalVM Community release for a major version', async () => {
|
||||
mockHttpClient.getJson.mockResolvedValue({
|
||||
result: [
|
||||
{
|
||||
draft: false,
|
||||
prerelease: false,
|
||||
assets: [
|
||||
{
|
||||
name: 'graalvm-community-jdk-21.0.1_linux-x64_bin.tar.gz',
|
||||
browser_download_url:
|
||||
'https://github.com/graalvm/graalvm-ce-builds/releases/download/jdk-21.0.1/graalvm-community-jdk-21.0.1_linux-x64_bin.tar.gz'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
draft: false,
|
||||
prerelease: false,
|
||||
assets: [
|
||||
{
|
||||
name: 'graalvm-community-jdk-21.0.2_linux-x64_bin.tar.gz',
|
||||
browser_download_url:
|
||||
'https://github.com/graalvm/graalvm-ce-builds/releases/download/jdk-21.0.2/graalvm-community-jdk-21.0.2_linux-x64_bin.tar.gz'
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
statusCode: 200,
|
||||
headers: {}
|
||||
});
|
||||
|
||||
const result = await (
|
||||
communityDistribution as any
|
||||
).findPackageForDownload('21');
|
||||
|
||||
expect(result).toEqual({
|
||||
url: 'https://github.com/graalvm/graalvm-ce-builds/releases/download/jdk-21.0.2/graalvm-community-jdk-21.0.2_linux-x64_bin.tar.gz',
|
||||
version: '21.0.2'
|
||||
});
|
||||
});
|
||||
|
||||
it('should reject GraalVM Community early access requests', async () => {
|
||||
(communityDistribution as any).stable = false;
|
||||
|
||||
await expect(
|
||||
(communityDistribution as any).findPackageForDownload('23')
|
||||
).rejects.toThrow(
|
||||
'GraalVM Community does not provide early access builds'
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('distribution factory', () => {
|
||||
const defaultOptions: JavaInstallerOptions = {
|
||||
version: '17',
|
||||
architecture: 'x64',
|
||||
packageType: 'jdk',
|
||||
checkLatest: false
|
||||
};
|
||||
|
||||
it('should map graalvm-community to the community installer', () => {
|
||||
const community = getJavaDistribution('graalvm-community', defaultOptions);
|
||||
|
||||
expect(community).toBeInstanceOf(GraalVMCommunityDistribution);
|
||||
});
|
||||
});
|
||||
|
||||
Vendored
+121
-13
@@ -78771,6 +78771,7 @@ var JavaDistribution;
|
||||
JavaDistribution["Dragonwell"] = "dragonwell";
|
||||
JavaDistribution["SapMachine"] = "sapmachine";
|
||||
JavaDistribution["GraalVM"] = "graalvm";
|
||||
JavaDistribution["GraalVMCommunity"] = "graalvm-community";
|
||||
JavaDistribution["JetBrains"] = "jetbrains";
|
||||
})(JavaDistribution || (JavaDistribution = {}));
|
||||
function getJavaDistribution(distributionName, installerOptions, jdkFile) {
|
||||
@@ -78802,6 +78803,8 @@ function getJavaDistribution(distributionName, installerOptions, jdkFile) {
|
||||
return new installer_11.SapMachineDistribution(installerOptions);
|
||||
case JavaDistribution.GraalVM:
|
||||
return new installer_12.GraalVMDistribution(installerOptions);
|
||||
case JavaDistribution.GraalVMCommunity:
|
||||
return new installer_12.GraalVMCommunityDistribution(installerOptions);
|
||||
case JavaDistribution.JetBrains:
|
||||
return new installer_13.JetBrainsDistribution(installerOptions);
|
||||
default:
|
||||
@@ -79069,23 +79072,29 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.GraalVMDistribution = void 0;
|
||||
exports.GraalVMCommunityDistribution = exports.GraalVMDistribution = void 0;
|
||||
const core = __importStar(__nccwpck_require__(37484));
|
||||
const tc = __importStar(__nccwpck_require__(33472));
|
||||
const fs_1 = __importDefault(__nccwpck_require__(79896));
|
||||
const path_1 = __importDefault(__nccwpck_require__(16928));
|
||||
const semver_1 = __importDefault(__nccwpck_require__(62088));
|
||||
const base_installer_1 = __nccwpck_require__(79935);
|
||||
const http_client_1 = __nccwpck_require__(54844);
|
||||
const util_1 = __nccwpck_require__(54527);
|
||||
const GRAALVM_DL_BASE = 'https://download.oracle.com/graalvm';
|
||||
const GRAALVM_DOWNLOAD_URL = 'https://www.graalvm.org/downloads/';
|
||||
const GRAALVM_COMMUNITY_RELEASES_URL = 'https://api.github.com/repos/graalvm/graalvm-ce-builds/releases?per_page=100';
|
||||
const GRAALVM_COMMUNITY_RELEASES_PAGE_ORIGIN = 'https://api.github.com';
|
||||
const GRAALVM_COMMUNITY_DOWNLOAD_URL = 'https://github.com/graalvm/graalvm-ce-builds/releases';
|
||||
const GRAALVM_COMMUNITY_ASSET_PREFIX = 'graalvm-community-jdk-';
|
||||
const GRAALVM_COMMUNITY_VERSION_PATTERN = /^\d+(?:\.\d+)*$/;
|
||||
const IS_WINDOWS = process.platform === 'win32';
|
||||
const GRAALVM_PLATFORM = IS_WINDOWS ? 'windows' : process.platform;
|
||||
const GRAALVM_MIN_VERSION = 17;
|
||||
const SUPPORTED_ARCHITECTURES = ['x64', 'aarch64'];
|
||||
class GraalVMDistribution extends base_installer_1.JavaBase {
|
||||
constructor(installerOptions) {
|
||||
super('GraalVM', installerOptions);
|
||||
constructor(installerOptions, distributionName = 'GraalVM') {
|
||||
super(distributionName, installerOptions);
|
||||
}
|
||||
downloadTool(javaRelease) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
@@ -79119,19 +79128,33 @@ class GraalVMDistribution extends base_installer_1.JavaBase {
|
||||
}
|
||||
findPackageForDownload(range) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
// Add input validation
|
||||
this.validateVersionRange(range);
|
||||
const arch = this.getSupportedArchitecture();
|
||||
if (!this.stable) {
|
||||
return this.findEABuildDownloadUrl(`${range}-ea`);
|
||||
}
|
||||
const { platform, extension, major } = this.validateStableBuildRequest(range);
|
||||
const fileUrl = this.constructFileUrl(range, major, platform, arch, extension);
|
||||
const response = yield this.http.head(fileUrl);
|
||||
this.handleHttpResponse(response, range);
|
||||
return { url: fileUrl, version: range };
|
||||
});
|
||||
}
|
||||
validateVersionRange(range) {
|
||||
if (!range || typeof range !== 'string') {
|
||||
throw new Error('Version range is required and must be a string');
|
||||
}
|
||||
}
|
||||
getSupportedArchitecture() {
|
||||
const arch = this.distributionArchitecture();
|
||||
if (!SUPPORTED_ARCHITECTURES.includes(arch)) {
|
||||
throw new Error(`Unsupported architecture: ${this.architecture}. Supported architectures are: ${SUPPORTED_ARCHITECTURES.join(', ')}`);
|
||||
}
|
||||
if (!this.stable) {
|
||||
return this.findEABuildDownloadUrl(`${range}-ea`);
|
||||
return arch;
|
||||
}
|
||||
validateStableBuildRequest(range) {
|
||||
if (this.packageType !== 'jdk') {
|
||||
throw new Error('GraalVM provides only the `jdk` package type');
|
||||
throw new Error(`${this.distribution} provides only the \`jdk\` package type`);
|
||||
}
|
||||
const platform = this.getPlatform();
|
||||
const extension = (0, util_1.getDownloadArchiveExtension)();
|
||||
@@ -79141,13 +79164,13 @@ class GraalVMDistribution extends base_installer_1.JavaBase {
|
||||
throw new Error(`Invalid version format: ${range}`);
|
||||
}
|
||||
if (majorVersion < GRAALVM_MIN_VERSION) {
|
||||
throw new Error(`GraalVM is only supported for JDK ${GRAALVM_MIN_VERSION} and later. Requested version: ${major}`);
|
||||
throw new Error(`${this.distribution} is only supported for JDK ${GRAALVM_MIN_VERSION} and later. Requested version: ${major}`);
|
||||
}
|
||||
const fileUrl = this.constructFileUrl(range, major, platform, arch, extension);
|
||||
const response = yield this.http.head(fileUrl);
|
||||
this.handleHttpResponse(response, range);
|
||||
return { url: fileUrl, version: range };
|
||||
});
|
||||
return {
|
||||
platform,
|
||||
major,
|
||||
extension
|
||||
};
|
||||
}
|
||||
constructFileUrl(range, major, platform, arch, extension) {
|
||||
return range.includes('.')
|
||||
@@ -79239,6 +79262,91 @@ class GraalVMDistribution extends base_installer_1.JavaBase {
|
||||
}
|
||||
}
|
||||
exports.GraalVMDistribution = GraalVMDistribution;
|
||||
class GraalVMCommunityDistribution extends GraalVMDistribution {
|
||||
constructor(installerOptions) {
|
||||
super(installerOptions, 'GraalVM Community');
|
||||
}
|
||||
get toolcacheFolderName() {
|
||||
return `Java_GraalVM_Community_${this.packageType}`;
|
||||
}
|
||||
findPackageForDownload(range) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
this.validateVersionRange(range);
|
||||
if (!this.stable) {
|
||||
throw new Error('GraalVM Community does not provide early access builds');
|
||||
}
|
||||
const arch = this.getSupportedArchitecture();
|
||||
const { platform, extension } = this.validateStableBuildRequest(range);
|
||||
// GraalVM Community asset names embed the platform, architecture and
|
||||
// archive type, e.g. `graalvm-community-jdk-21.0.2_linux-x64_bin.tar.gz`.
|
||||
const assetSuffix = `_${platform}-${arch}_bin.${extension}`;
|
||||
const availableVersions = yield this.getAvailableVersions(assetSuffix);
|
||||
const satisfiedVersion = availableVersions
|
||||
.filter(item => (0, util_1.isVersionSatisfies)(range, item.version))
|
||||
.sort((a, b) => -semver_1.default.compareBuild(a.version, b.version))[0];
|
||||
if (!satisfiedVersion) {
|
||||
const error = this.createVersionNotFoundError(range, availableVersions.map(item => item.version), `Platform: ${platform}`);
|
||||
error.message += `\nPlease check if this version is available at ${GRAALVM_COMMUNITY_DOWNLOAD_URL}.`;
|
||||
throw error;
|
||||
}
|
||||
return satisfiedVersion;
|
||||
});
|
||||
}
|
||||
getAvailableVersions(assetSuffix) {
|
||||
var _a;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const headers = (0, util_1.getGitHubHttpHeaders)();
|
||||
const versions = new Map();
|
||||
let releasesUrl = GRAALVM_COMMUNITY_RELEASES_URL;
|
||||
for (let pageIndex = 0; releasesUrl && pageIndex < util_1.MAX_PAGINATION_PAGES; pageIndex++) {
|
||||
const response = yield this.http.getJson(releasesUrl, headers);
|
||||
const releases = Array.isArray(response.result) ? response.result : [];
|
||||
if (releases.length === 0) {
|
||||
break;
|
||||
}
|
||||
for (const release of releases) {
|
||||
if (release.draft || release.prerelease) {
|
||||
continue;
|
||||
}
|
||||
for (const asset of (_a = release.assets) !== null && _a !== void 0 ? _a : []) {
|
||||
const version = this.extractAssetVersion(asset.name, assetSuffix);
|
||||
if (version) {
|
||||
versions.set(version, {
|
||||
version,
|
||||
url: asset.browser_download_url
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
releasesUrl = this.getNextReleasesUrl(response.headers);
|
||||
}
|
||||
return [...versions.values()];
|
||||
});
|
||||
}
|
||||
// Returns the GraalVM JDK version encoded in a release asset name when it
|
||||
// matches the requested platform/architecture/archive suffix, otherwise null.
|
||||
extractAssetVersion(assetName, assetSuffix) {
|
||||
if (!assetName.startsWith(GRAALVM_COMMUNITY_ASSET_PREFIX) ||
|
||||
!assetName.endsWith(assetSuffix)) {
|
||||
return null;
|
||||
}
|
||||
const rawVersion = assetName.slice(GRAALVM_COMMUNITY_ASSET_PREFIX.length, -assetSuffix.length);
|
||||
if (!GRAALVM_COMMUNITY_VERSION_PATTERN.test(rawVersion)) {
|
||||
return null;
|
||||
}
|
||||
return (0, util_1.convertVersionToSemver)(rawVersion);
|
||||
}
|
||||
getNextReleasesUrl(headers) {
|
||||
const nextUrl = (0, util_1.getNextPageUrlFromLinkHeader)(headers);
|
||||
if (nextUrl &&
|
||||
!(0, util_1.validatePaginationUrl)(nextUrl, GRAALVM_COMMUNITY_RELEASES_PAGE_ORIGIN)) {
|
||||
core.warning(`Ignoring pagination link with unexpected origin: ${nextUrl}`);
|
||||
return null;
|
||||
}
|
||||
return nextUrl;
|
||||
}
|
||||
}
|
||||
exports.GraalVMCommunityDistribution = GraalVMCommunityDistribution;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
+59
-18
@@ -10,8 +10,10 @@
|
||||
- [Alibaba Dragonwell](#Alibaba-Dragonwell)
|
||||
- [SapMachine](#SapMachine)
|
||||
- [GraalVM](#GraalVM)
|
||||
- [GraalVM Community](#GraalVM-Community)
|
||||
- [JetBrains](#JetBrains)
|
||||
- [Installing custom Java package type](#Installing-custom-Java-package-type)
|
||||
- [JavaFX Maven project](#JavaFX-Maven-project)
|
||||
- [Installing custom Java architecture](#Installing-custom-Java-architecture)
|
||||
- [Installing custom Java distribution from local file](#Installing-Java-from-local-file)
|
||||
- [Testing against different Java distributions](#Testing-against-different-Java-distributions)
|
||||
@@ -36,7 +38,7 @@ steps:
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: '21'
|
||||
- run: java -cp java HelloWorldApp
|
||||
- run: java --version
|
||||
```
|
||||
|
||||
### Adopt
|
||||
@@ -49,7 +51,7 @@ steps:
|
||||
with:
|
||||
distribution: 'adopt-hotspot'
|
||||
java-version: '11'
|
||||
- run: java -cp java HelloWorldApp
|
||||
- run: java --version
|
||||
```
|
||||
|
||||
### Zulu
|
||||
@@ -62,7 +64,7 @@ steps:
|
||||
distribution: 'zulu'
|
||||
java-version: '21'
|
||||
java-package: jdk # optional (jdk, jre, jdk+fx or jre+fx) - defaults to jdk
|
||||
- run: java -cp java HelloWorldApp
|
||||
- run: java --version
|
||||
```
|
||||
|
||||
### Liberica
|
||||
@@ -75,7 +77,7 @@ steps:
|
||||
distribution: 'liberica'
|
||||
java-version: '21'
|
||||
java-package: jdk # optional (jdk, jre, jdk+fx or jre+fx) - defaults to jdk
|
||||
- run: java -cp java HelloWorldApp
|
||||
- run: java --version
|
||||
```
|
||||
|
||||
### Microsoft
|
||||
@@ -87,7 +89,7 @@ steps:
|
||||
with:
|
||||
distribution: 'microsoft'
|
||||
java-version: '21'
|
||||
- run: java -cp java HelloWorldApp
|
||||
- run: java --version
|
||||
```
|
||||
|
||||
### Using Microsoft distribution on GHES
|
||||
@@ -116,7 +118,7 @@ steps:
|
||||
with:
|
||||
distribution: 'corretto'
|
||||
java-version: '21'
|
||||
- run: java -cp java HelloWorldApp
|
||||
- run: java --version
|
||||
```
|
||||
|
||||
### Oracle
|
||||
@@ -129,7 +131,7 @@ steps:
|
||||
with:
|
||||
distribution: 'oracle'
|
||||
java-version: '21'
|
||||
- run: java -cp java HelloWorldApp
|
||||
- run: java --version
|
||||
```
|
||||
|
||||
### Alibaba Dragonwell
|
||||
@@ -142,7 +144,7 @@ steps:
|
||||
with:
|
||||
distribution: 'dragonwell'
|
||||
java-version: '8'
|
||||
- run: java -cp java HelloWorldApp
|
||||
- run: java --version
|
||||
```
|
||||
|
||||
### SapMachine
|
||||
@@ -154,7 +156,7 @@ steps:
|
||||
with:
|
||||
distribution: 'sapmachine'
|
||||
java-version: '21'
|
||||
- run: java -cp java HelloWorldApp
|
||||
- run: java --version
|
||||
```
|
||||
|
||||
### GraalVM
|
||||
@@ -167,6 +169,21 @@ steps:
|
||||
with:
|
||||
distribution: 'graalvm'
|
||||
java-version: '21'
|
||||
- run: |
|
||||
java --version
|
||||
native-image --version
|
||||
```
|
||||
|
||||
### GraalVM Community
|
||||
**NOTE:** GraalVM Community is available for stable JDK 17 and later releases.
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'graalvm-community'
|
||||
java-version: '21'
|
||||
- run: |
|
||||
java -cp java HelloWorldApp
|
||||
native-image -cp java HelloWorldApp
|
||||
@@ -186,7 +203,7 @@ steps:
|
||||
with:
|
||||
distribution: 'jetbrains'
|
||||
java-version: '11'
|
||||
- run: java -cp java HelloWorldApp
|
||||
- run: java --version
|
||||
```
|
||||
|
||||
The JetBrains installer uses the GitHub API to fetch the latest version. If you believe your project is going to be running into rate limits, you can provide a
|
||||
@@ -202,7 +219,7 @@ steps:
|
||||
java-package: 'jdk' # optional (jdk, jre, jdk+jcef, jre+jcef, jdk+ft, or jre+ft) - defaults to jdk
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
- run: java -cp java HelloWorldApp
|
||||
- run: java --version
|
||||
```
|
||||
|
||||
You can specify your package type (as shown in the [releases page](https://github.com/JetBrains/JetBrainsRuntime/releases/)) in the `java-package` parameter.
|
||||
@@ -225,7 +242,31 @@ steps:
|
||||
distribution: '<distribution>'
|
||||
java-version: '11'
|
||||
java-package: jdk # optional (jdk or jre) - defaults to jdk
|
||||
- run: java -cp java HelloWorldApp
|
||||
- run: java --version
|
||||
```
|
||||
|
||||
### JavaFX Maven project
|
||||
|
||||
For JavaFX projects that use Maven, use `jdk+fx` (or `jre+fx`) as the `java-package` value together with a distribution that supports it (e.g. `zulu` or `liberica`). Then include the [`javafx-maven-plugin`](https://openjfx.io/openjfx-docs/#maven) in your `pom.xml` as described in the [Getting Started with JavaFX](https://openjfx.io/openjfx-docs/#maven) guide.
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'zulu'
|
||||
java-version: '21'
|
||||
java-package: jdk+fx
|
||||
cache: maven
|
||||
- name: Build with Maven
|
||||
run: mvn --no-transfer-progress compile
|
||||
```
|
||||
|
||||
To run the JavaFX application in CI:
|
||||
|
||||
```yaml
|
||||
- name: Run with Maven
|
||||
run: mvn --no-transfer-progress javafx:run
|
||||
```
|
||||
|
||||
## Installing custom Java architecture
|
||||
@@ -238,7 +279,7 @@ steps:
|
||||
distribution: '<distribution>'
|
||||
java-version: '11'
|
||||
architecture: x86 # optional - default value derived from the runner machine
|
||||
- run: java -cp java HelloWorldApp
|
||||
- run: java --version
|
||||
```
|
||||
|
||||
## Installing Java from local file
|
||||
@@ -256,7 +297,7 @@ steps:
|
||||
java-version: '11.0.0'
|
||||
architecture: x64
|
||||
|
||||
- run: java -cp java HelloWorldApp
|
||||
- run: java --version
|
||||
```
|
||||
|
||||
If your use-case requires a custom distribution (in the example, alpine-linux is used) or a version that is not provided by setup-java and you want to always install the latest version during runtime, then you can use the following code to auto-download the latest JDK, determine the semver needed for setup-java, and setup-java will take care of the installation and caching on the VM:
|
||||
@@ -281,7 +322,7 @@ If your use-case requires a custom distribution (in the example, alpine-linux is
|
||||
jdkFile: ${{ runner.temp }}/java_package.tar.gz
|
||||
java-version: {{ steps.fetch_latest_jdk.outputs.java_version }}
|
||||
architecture: x64
|
||||
- run: java -cp java HelloWorldApp
|
||||
- run: java --version
|
||||
```
|
||||
|
||||
## Testing against different Java distributions
|
||||
@@ -302,7 +343,7 @@ jobs:
|
||||
with:
|
||||
distribution: ${{ matrix.distribution }}
|
||||
java-version: ${{ matrix.java }}
|
||||
- run: java -cp java HelloWorldApp
|
||||
- run: java --version
|
||||
```
|
||||
|
||||
#### Testing against different platforms
|
||||
@@ -322,7 +363,7 @@ jobs:
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: ${{ matrix.java }}
|
||||
- run: java -cp java HelloWorldApp
|
||||
- run: java --version
|
||||
```
|
||||
|
||||
## Publishing using Apache Maven
|
||||
@@ -580,7 +621,7 @@ steps:
|
||||
distribution: 'temurin'
|
||||
java-version: '11'
|
||||
mvn-toolchain-id: 'some_other_id'
|
||||
- run: java -cp java HelloWorldApp
|
||||
- run: java --version
|
||||
```
|
||||
|
||||
In case you install multiple versions of Java at once you can use the same syntax as used in `java-versions`. Please note that you have to declare an ID for all Java versions that will be installed or the `mvn-toolchain-id` instruction will be skipped wholesale due to mapping ambiguities.
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
import js from '@eslint/js';
|
||||
import tseslint from 'typescript-eslint';
|
||||
import jestPlugin from 'eslint-plugin-jest';
|
||||
import nodePlugin from 'eslint-plugin-n';
|
||||
import eslintConfigPrettier from 'eslint-config-prettier';
|
||||
import globals from 'globals';
|
||||
|
||||
export default tseslint.config(
|
||||
{
|
||||
ignores: [
|
||||
'dist/',
|
||||
'lib/',
|
||||
'node_modules/',
|
||||
'coverage/',
|
||||
'**/*.js',
|
||||
'**/*.cjs',
|
||||
'**/*.mjs',
|
||||
'**/*.d.ts'
|
||||
]
|
||||
},
|
||||
{
|
||||
files: ['src/**/*.ts', '__tests__/**/*.ts'],
|
||||
extends: [
|
||||
js.configs.recommended,
|
||||
...tseslint.configs.recommended,
|
||||
jestPlugin.configs['flat/recommended'],
|
||||
eslintConfigPrettier
|
||||
],
|
||||
plugins: {
|
||||
n: nodePlugin
|
||||
},
|
||||
languageOptions: {
|
||||
ecmaVersion: 2021,
|
||||
sourceType: 'module',
|
||||
globals: {
|
||||
...globals.node,
|
||||
...globals.es2021
|
||||
}
|
||||
},
|
||||
rules: {
|
||||
'@typescript-eslint/no-require-imports': 'error',
|
||||
'@typescript-eslint/no-non-null-assertion': 'off',
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
'@typescript-eslint/no-empty-function': 'off',
|
||||
'@typescript-eslint/ban-ts-comment': [
|
||||
'error',
|
||||
{
|
||||
'ts-ignore': 'allow-with-description'
|
||||
}
|
||||
],
|
||||
'no-console': 'error',
|
||||
yoda: 'error',
|
||||
'prefer-const': [
|
||||
'error',
|
||||
{
|
||||
destructuring: 'all'
|
||||
}
|
||||
],
|
||||
'no-control-regex': 'off',
|
||||
'no-constant-condition': ['error', {checkLoops: false}],
|
||||
// ESLint 10's recommended set adds `preserve-caught-error`, which the
|
||||
// previous ESLint 8 recommended config did not enable. Keep it off to
|
||||
// preserve the prior lint behavior; adopting it would require attaching
|
||||
// an Error `cause` (ES2022) and is out of scope for this upgrade.
|
||||
'preserve-caught-error': 'off',
|
||||
'n/no-extraneous-import': 'error'
|
||||
}
|
||||
},
|
||||
{
|
||||
files: ['**/*{test,spec}.ts'],
|
||||
languageOptions: {
|
||||
globals: {
|
||||
...globals.jest
|
||||
}
|
||||
},
|
||||
rules: {
|
||||
'@typescript-eslint/no-unused-vars': 'off',
|
||||
'jest/no-standalone-expect': 'off',
|
||||
'jest/no-conditional-expect': 'off',
|
||||
'no-console': 'off'
|
||||
}
|
||||
}
|
||||
);
|
||||
Generated
+715
-596
File diff suppressed because it is too large
Load Diff
+8
-9
@@ -11,8 +11,8 @@
|
||||
"build": "ncc build -o dist/setup src/setup-java.ts && ncc build -o dist/cleanup src/cleanup-java.ts",
|
||||
"format": "prettier --no-error-on-unmatched-pattern --config ./.prettierrc.js --write \"**/*.{ts,yml,yaml}\"",
|
||||
"format-check": "prettier --no-error-on-unmatched-pattern --config ./.prettierrc.js --check \"**/*.{ts,yml,yaml}\"",
|
||||
"lint": "eslint \"src/**/*.ts\" \"__tests__/**/*.ts\"",
|
||||
"lint:fix": "eslint \"src/**/*.ts\" \"__tests__/**/*.ts\" --fix",
|
||||
"lint": "eslint --config ./.eslintrc.js \"**/*.ts\"",
|
||||
"lint:fix": "eslint --config ./.eslintrc.js \"**/*.ts\" --fix",
|
||||
"prerelease": "npm run-script build",
|
||||
"release": "git add -f dist/setup/index.js dist/cleanup/index.js",
|
||||
"test": "jest"
|
||||
@@ -40,22 +40,21 @@
|
||||
"xmlbuilder2": "^4.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^10.0.1",
|
||||
"@types/jest": "^30.0.0",
|
||||
"@types/node": "^26.0.0",
|
||||
"@types/semver": "^7.5.8",
|
||||
"@typescript-eslint/eslint-plugin": "^8.48.0",
|
||||
"@typescript-eslint/parser": "^8.61.1",
|
||||
"@vercel/ncc": "^0.44.0",
|
||||
"eslint": "^10.5.0",
|
||||
"eslint": "^8.57.0",
|
||||
"eslint-config-prettier": "^10.1.8",
|
||||
"eslint-plugin-jest": "^29.15.2",
|
||||
"eslint-plugin-n": "^18.1.0",
|
||||
"globals": "^17.7.0",
|
||||
"eslint-plugin-jest": "^29.0.1",
|
||||
"eslint-plugin-node": "^11.1.0",
|
||||
"jest": "^30.4.2",
|
||||
"jest-circus": "^30.4.2",
|
||||
"prettier": "^3.6.2",
|
||||
"ts-jest": "^29.4.11",
|
||||
"typescript": "^5.3.3",
|
||||
"typescript-eslint": "^8.62.0"
|
||||
"typescript": "^5.3.3"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/actions/setup-java/issues"
|
||||
|
||||
@@ -11,7 +11,10 @@ import {CorrettoDistribution} from './corretto/installer';
|
||||
import {OracleDistribution} from './oracle/installer';
|
||||
import {DragonwellDistribution} from './dragonwell/installer';
|
||||
import {SapMachineDistribution} from './sapmachine/installer';
|
||||
import {GraalVMDistribution} from './graalvm/installer';
|
||||
import {
|
||||
GraalVMCommunityDistribution,
|
||||
GraalVMDistribution
|
||||
} from './graalvm/installer';
|
||||
import {JetBrainsDistribution} from './jetbrains/installer';
|
||||
|
||||
enum JavaDistribution {
|
||||
@@ -29,6 +32,7 @@ enum JavaDistribution {
|
||||
Dragonwell = 'dragonwell',
|
||||
SapMachine = 'sapmachine',
|
||||
GraalVM = 'graalvm',
|
||||
GraalVMCommunity = 'graalvm-community',
|
||||
JetBrains = 'jetbrains'
|
||||
}
|
||||
|
||||
@@ -74,6 +78,8 @@ export function getJavaDistribution(
|
||||
return new SapMachineDistribution(installerOptions);
|
||||
case JavaDistribution.GraalVM:
|
||||
return new GraalVMDistribution(installerOptions);
|
||||
case JavaDistribution.GraalVMCommunity:
|
||||
return new GraalVMCommunityDistribution(installerOptions);
|
||||
case JavaDistribution.JetBrains:
|
||||
return new JetBrainsDistribution(installerOptions);
|
||||
default:
|
||||
|
||||
@@ -2,6 +2,7 @@ import * as core from '@actions/core';
|
||||
import * as tc from '@actions/tool-cache';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import semver from 'semver';
|
||||
import {JavaBase} from '../base-installer';
|
||||
import {HttpCodes} from '@actions/http-client';
|
||||
import {GraalVMEAVersion} from './models';
|
||||
@@ -11,14 +12,26 @@ import {
|
||||
JavaInstallerResults
|
||||
} from '../base-models';
|
||||
import {
|
||||
convertVersionToSemver,
|
||||
extractJdkFile,
|
||||
getDownloadArchiveExtension,
|
||||
getGitHubHttpHeaders,
|
||||
renameWinArchive
|
||||
getNextPageUrlFromLinkHeader,
|
||||
isVersionSatisfies,
|
||||
MAX_PAGINATION_PAGES,
|
||||
renameWinArchive,
|
||||
validatePaginationUrl
|
||||
} from '../../util';
|
||||
|
||||
const GRAALVM_DL_BASE = 'https://download.oracle.com/graalvm';
|
||||
const GRAALVM_DOWNLOAD_URL = 'https://www.graalvm.org/downloads/';
|
||||
const GRAALVM_COMMUNITY_RELEASES_URL =
|
||||
'https://api.github.com/repos/graalvm/graalvm-ce-builds/releases?per_page=100';
|
||||
const GRAALVM_COMMUNITY_RELEASES_PAGE_ORIGIN = 'https://api.github.com';
|
||||
const GRAALVM_COMMUNITY_DOWNLOAD_URL =
|
||||
'https://github.com/graalvm/graalvm-ce-builds/releases';
|
||||
const GRAALVM_COMMUNITY_ASSET_PREFIX = 'graalvm-community-jdk-';
|
||||
const GRAALVM_COMMUNITY_VERSION_PATTERN = /^\d+(?:\.\d+)*$/;
|
||||
const IS_WINDOWS = process.platform === 'win32';
|
||||
const GRAALVM_PLATFORM = IS_WINDOWS ? 'windows' : process.platform;
|
||||
const GRAALVM_MIN_VERSION = 17;
|
||||
@@ -26,9 +39,23 @@ const SUPPORTED_ARCHITECTURES = ['x64', 'aarch64'] as const;
|
||||
type SupportedArchitecture = (typeof SUPPORTED_ARCHITECTURES)[number];
|
||||
type OsVersions = 'linux' | 'macos' | 'windows';
|
||||
|
||||
interface GraalVMCommunityAsset {
|
||||
name: string;
|
||||
browser_download_url: string;
|
||||
}
|
||||
|
||||
interface GraalVMCommunityRelease {
|
||||
draft: boolean;
|
||||
prerelease: boolean;
|
||||
assets: GraalVMCommunityAsset[];
|
||||
}
|
||||
|
||||
export class GraalVMDistribution extends JavaBase {
|
||||
constructor(installerOptions: JavaInstallerOptions) {
|
||||
super('GraalVM', installerOptions);
|
||||
constructor(
|
||||
installerOptions: JavaInstallerOptions,
|
||||
distributionName = 'GraalVM'
|
||||
) {
|
||||
super(distributionName, installerOptions);
|
||||
}
|
||||
|
||||
protected async downloadTool(
|
||||
@@ -85,40 +112,14 @@ export class GraalVMDistribution extends JavaBase {
|
||||
protected async findPackageForDownload(
|
||||
range: string
|
||||
): Promise<JavaDownloadRelease> {
|
||||
// Add input validation
|
||||
if (!range || typeof range !== 'string') {
|
||||
throw new Error('Version range is required and must be a string');
|
||||
}
|
||||
|
||||
const arch = this.distributionArchitecture();
|
||||
if (!SUPPORTED_ARCHITECTURES.includes(arch as SupportedArchitecture)) {
|
||||
throw new Error(
|
||||
`Unsupported architecture: ${this.architecture}. Supported architectures are: ${SUPPORTED_ARCHITECTURES.join(', ')}`
|
||||
);
|
||||
}
|
||||
this.validateVersionRange(range);
|
||||
const arch = this.getSupportedArchitecture();
|
||||
|
||||
if (!this.stable) {
|
||||
return this.findEABuildDownloadUrl(`${range}-ea`);
|
||||
}
|
||||
|
||||
if (this.packageType !== 'jdk') {
|
||||
throw new Error('GraalVM provides only the `jdk` package type');
|
||||
}
|
||||
|
||||
const platform = this.getPlatform();
|
||||
const extension = getDownloadArchiveExtension();
|
||||
const major = range.includes('.') ? range.split('.')[0] : range;
|
||||
const majorVersion = parseInt(major);
|
||||
|
||||
if (isNaN(majorVersion)) {
|
||||
throw new Error(`Invalid version format: ${range}`);
|
||||
}
|
||||
|
||||
if (majorVersion < GRAALVM_MIN_VERSION) {
|
||||
throw new Error(
|
||||
`GraalVM is only supported for JDK ${GRAALVM_MIN_VERSION} and later. Requested version: ${major}`
|
||||
);
|
||||
}
|
||||
const {platform, extension, major} = this.validateStableBuildRequest(range);
|
||||
|
||||
const fileUrl = this.constructFileUrl(
|
||||
range,
|
||||
@@ -134,6 +135,56 @@ export class GraalVMDistribution extends JavaBase {
|
||||
return {url: fileUrl, version: range};
|
||||
}
|
||||
|
||||
protected validateVersionRange(range: string): void {
|
||||
if (!range || typeof range !== 'string') {
|
||||
throw new Error('Version range is required and must be a string');
|
||||
}
|
||||
}
|
||||
|
||||
protected getSupportedArchitecture(): SupportedArchitecture {
|
||||
const arch = this.distributionArchitecture();
|
||||
if (!SUPPORTED_ARCHITECTURES.includes(arch as SupportedArchitecture)) {
|
||||
throw new Error(
|
||||
`Unsupported architecture: ${this.architecture}. Supported architectures are: ${SUPPORTED_ARCHITECTURES.join(', ')}`
|
||||
);
|
||||
}
|
||||
|
||||
return arch as SupportedArchitecture;
|
||||
}
|
||||
|
||||
protected validateStableBuildRequest(range: string): {
|
||||
platform: OsVersions;
|
||||
extension: string;
|
||||
major: string;
|
||||
} {
|
||||
if (this.packageType !== 'jdk') {
|
||||
throw new Error(
|
||||
`${this.distribution} provides only the \`jdk\` package type`
|
||||
);
|
||||
}
|
||||
|
||||
const platform = this.getPlatform();
|
||||
const extension = getDownloadArchiveExtension();
|
||||
const major = range.includes('.') ? range.split('.')[0] : range;
|
||||
const majorVersion = parseInt(major);
|
||||
|
||||
if (isNaN(majorVersion)) {
|
||||
throw new Error(`Invalid version format: ${range}`);
|
||||
}
|
||||
|
||||
if (majorVersion < GRAALVM_MIN_VERSION) {
|
||||
throw new Error(
|
||||
`${this.distribution} is only supported for JDK ${GRAALVM_MIN_VERSION} and later. Requested version: ${major}`
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
platform,
|
||||
major,
|
||||
extension
|
||||
};
|
||||
}
|
||||
|
||||
private constructFileUrl(
|
||||
range: string,
|
||||
major: string,
|
||||
@@ -280,3 +331,131 @@ export class GraalVMDistribution extends JavaBase {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export class GraalVMCommunityDistribution extends GraalVMDistribution {
|
||||
constructor(installerOptions: JavaInstallerOptions) {
|
||||
super(installerOptions, 'GraalVM Community');
|
||||
}
|
||||
|
||||
protected get toolcacheFolderName(): string {
|
||||
return `Java_GraalVM_Community_${this.packageType}`;
|
||||
}
|
||||
|
||||
protected async findPackageForDownload(
|
||||
range: string
|
||||
): Promise<JavaDownloadRelease> {
|
||||
this.validateVersionRange(range);
|
||||
|
||||
if (!this.stable) {
|
||||
throw new Error('GraalVM Community does not provide early access builds');
|
||||
}
|
||||
|
||||
const arch = this.getSupportedArchitecture();
|
||||
const {platform, extension} = this.validateStableBuildRequest(range);
|
||||
// GraalVM Community asset names embed the platform, architecture and
|
||||
// archive type, e.g. `graalvm-community-jdk-21.0.2_linux-x64_bin.tar.gz`.
|
||||
const assetSuffix = `_${platform}-${arch}_bin.${extension}`;
|
||||
const availableVersions = await this.getAvailableVersions(assetSuffix);
|
||||
|
||||
const satisfiedVersion = availableVersions
|
||||
.filter(item => isVersionSatisfies(range, item.version))
|
||||
.sort((a, b) => -semver.compareBuild(a.version, b.version))[0];
|
||||
|
||||
if (!satisfiedVersion) {
|
||||
const error = this.createVersionNotFoundError(
|
||||
range,
|
||||
availableVersions.map(item => item.version),
|
||||
`Platform: ${platform}`
|
||||
);
|
||||
error.message += `\nPlease check if this version is available at ${GRAALVM_COMMUNITY_DOWNLOAD_URL}.`;
|
||||
throw error;
|
||||
}
|
||||
|
||||
return satisfiedVersion;
|
||||
}
|
||||
|
||||
private async getAvailableVersions(
|
||||
assetSuffix: string
|
||||
): Promise<JavaDownloadRelease[]> {
|
||||
const headers = getGitHubHttpHeaders();
|
||||
const versions = new Map<string, JavaDownloadRelease>();
|
||||
let releasesUrl: string | null = GRAALVM_COMMUNITY_RELEASES_URL;
|
||||
|
||||
for (
|
||||
let pageIndex = 0;
|
||||
releasesUrl && pageIndex < MAX_PAGINATION_PAGES;
|
||||
pageIndex++
|
||||
) {
|
||||
const response = await this.http.getJson<GraalVMCommunityRelease[]>(
|
||||
releasesUrl,
|
||||
headers
|
||||
);
|
||||
|
||||
const releases = Array.isArray(response.result) ? response.result : [];
|
||||
if (releases.length === 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
for (const release of releases) {
|
||||
if (release.draft || release.prerelease) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (const asset of release.assets ?? []) {
|
||||
const version = this.extractAssetVersion(asset.name, assetSuffix);
|
||||
if (version) {
|
||||
versions.set(version, {
|
||||
version,
|
||||
url: asset.browser_download_url
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
releasesUrl = this.getNextReleasesUrl(response.headers);
|
||||
}
|
||||
|
||||
return [...versions.values()];
|
||||
}
|
||||
|
||||
// Returns the GraalVM JDK version encoded in a release asset name when it
|
||||
// matches the requested platform/architecture/archive suffix, otherwise null.
|
||||
private extractAssetVersion(
|
||||
assetName: string,
|
||||
assetSuffix: string
|
||||
): string | null {
|
||||
if (
|
||||
!assetName.startsWith(GRAALVM_COMMUNITY_ASSET_PREFIX) ||
|
||||
!assetName.endsWith(assetSuffix)
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const rawVersion = assetName.slice(
|
||||
GRAALVM_COMMUNITY_ASSET_PREFIX.length,
|
||||
-assetSuffix.length
|
||||
);
|
||||
|
||||
if (!GRAALVM_COMMUNITY_VERSION_PATTERN.test(rawVersion)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return convertVersionToSemver(rawVersion);
|
||||
}
|
||||
|
||||
private getNextReleasesUrl(
|
||||
headers: Record<string, string | string[] | undefined>
|
||||
): string | null {
|
||||
const nextUrl = getNextPageUrlFromLinkHeader(headers);
|
||||
if (
|
||||
nextUrl &&
|
||||
!validatePaginationUrl(nextUrl, GRAALVM_COMMUNITY_RELEASES_PAGE_ORIGIN)
|
||||
) {
|
||||
core.warning(
|
||||
`Ignoring pagination link with unexpected origin: ${nextUrl}`
|
||||
);
|
||||
return null;
|
||||
}
|
||||
return nextUrl;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user