mirror of
https://github.com/actions/setup-java.git
synced 2025-04-20 18:06:45 +00:00
Merge "v2-preview" branch into "main" (#150)
* actions/setup-java@v2 - Support different distributions (#132) * Implement support for custom vendors in setup-java * minor improvements * minor refactoring * Add unit tests and e2e tests * Update documentation for setup-java@v2 release * minor improvements * regenerate dist * fix comments * resolve comments * resolve comments * fix tests * Update README.md Co-authored-by: George Adams <george.adams@microsoft.com> * Apply suggestions from code review Co-authored-by: Konrad Pabjan <konradpabjan@github.com> * fix minor nitpicks * handle 4th digit * pull latest main * Update README.md * rename adoptium to adopt * rename adoptium to adopt * rename adoptium to adopt * Update README.md * make java-version and distribution required for action * update readme * fix tests * fix e2e tests Co-authored-by: George Adams <george.adams@microsoft.com> Co-authored-by: Konrad Pabjan <konradpabjan@github.com> * Add "overwrite-settings" input parameter (#136) * add overwrite-settings parameter * fix e2e tests * print debug * fix e2e tests * add comment * remove comment * Add "Contents/Home" postfix on macOS if provider creates it (#139) * Update e2e-versions.yml * Update e2e-versions.yml * implement fix * Update e2e-versions.yml * Update installer.ts * fix filter logic * Update e2e-versions.yml * remove extra logic * Update e2e-versions.yml * Add check-latest flag (#141) * add changes for check-latest * run prerelease script * resolving comments * fixing tests * fix spelling * improve core.info messages * run format * run prerelease * change version to fix test * resolve comment for check-latest * Update README.md * added hosted tool cache section * Apply suggestions from code review Co-authored-by: Maxim Lobanov <v-malob@microsoft.com> Co-authored-by: Konrad Pabjan <konradpabjan@github.com> * Avoid "+" sign in Java path in v2-preview (#145) * try to handle _ versions * more logs * more debug * test 1 * more fixes * fix typo * Update e2e-versions.yml * add unit-tests * remove debug info from tests * debug pre-cached versions * change e2e tests to ubuntu-latest * update npm licenses Co-authored-by: George Adams <george.adams@microsoft.com> Co-authored-by: Konrad Pabjan <konradpabjan@github.com> Co-authored-by: Dmitry Shibanov <dmitry-shibanov@github.com>
This commit is contained in:
parent
ebb424f2cb
commit
b53500dabc
67 changed files with 40956 additions and 22218 deletions
141
src/distributions/adopt/installer.ts
Normal file
141
src/distributions/adopt/installer.ts
Normal file
|
@ -0,0 +1,141 @@
|
|||
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 { IAdoptAvailableVersions } from './models';
|
||||
import { JavaInstallerOptions, JavaDownloadRelease, JavaInstallerResults } from '../base-models';
|
||||
import { MACOS_JAVA_CONTENT_POSTFIX } from '../../constants';
|
||||
import { extractJdkFile, getDownloadArchiveExtension, isVersionSatisfies } from '../../util';
|
||||
|
||||
export class AdoptDistribution extends JavaBase {
|
||||
constructor(installerOptions: JavaInstallerOptions) {
|
||||
super('Adopt', installerOptions);
|
||||
}
|
||||
|
||||
protected async findPackageForDownload(version: string): Promise<JavaDownloadRelease> {
|
||||
const availableVersionsRaw = await this.getAvailableVersions();
|
||||
const availableVersionsWithBinaries = availableVersionsRaw
|
||||
.filter(item => item.binaries.length > 0)
|
||||
.map(item => {
|
||||
return {
|
||||
version: item.version_data.semver,
|
||||
url: item.binaries[0].package.link
|
||||
} as JavaDownloadRelease;
|
||||
});
|
||||
|
||||
const satisfiedVersions = availableVersionsWithBinaries
|
||||
.filter(item => isVersionSatisfies(version, item.version))
|
||||
.sort((a, b) => {
|
||||
return -semver.compareBuild(a.version, b.version);
|
||||
});
|
||||
|
||||
const resolvedFullVersion = satisfiedVersions.length > 0 ? satisfiedVersions[0] : null;
|
||||
if (!resolvedFullVersion) {
|
||||
const availableOptions = availableVersionsWithBinaries.map(item => item.version).join(', ');
|
||||
const availableOptionsMessage = availableOptions
|
||||
? `\nAvailable versions: ${availableOptions}`
|
||||
: '';
|
||||
throw new Error(
|
||||
`Could not find satisfied version for SemVer '${version}'. ${availableOptionsMessage}`
|
||||
);
|
||||
}
|
||||
|
||||
return resolvedFullVersion;
|
||||
}
|
||||
|
||||
protected async downloadTool(javaRelease: JavaDownloadRelease): Promise<JavaInstallerResults> {
|
||||
let javaPath: string;
|
||||
let extractedJavaPath: string;
|
||||
|
||||
core.info(
|
||||
`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`
|
||||
);
|
||||
const javaArchivePath = await tc.downloadTool(javaRelease.url);
|
||||
|
||||
core.info(`Extracting Java archive...`);
|
||||
let extension = getDownloadArchiveExtension();
|
||||
|
||||
extractedJavaPath = await extractJdkFile(javaArchivePath, extension);
|
||||
|
||||
const archiveName = fs.readdirSync(extractedJavaPath)[0];
|
||||
const archivePath = path.join(extractedJavaPath, archiveName);
|
||||
const version = this.getToolcacheVersionName(javaRelease.version);
|
||||
|
||||
javaPath = await tc.cacheDir(archivePath, this.toolcacheFolderName, version, this.architecture);
|
||||
|
||||
return { version: javaRelease.version, path: javaPath };
|
||||
}
|
||||
|
||||
private async getAvailableVersions(): Promise<IAdoptAvailableVersions[]> {
|
||||
const platform = this.getPlatformOption();
|
||||
const arch = this.architecture;
|
||||
const imageType = this.packageType;
|
||||
const versionRange = encodeURI('[1.0,100.0]'); // retrieve all available versions
|
||||
const releaseType = this.stable ? 'ga' : 'ea';
|
||||
|
||||
console.time('adopt-retrieve-available-versions');
|
||||
|
||||
const baseRequestArguments = [
|
||||
`project=jdk`,
|
||||
'vendor=adoptopenjdk',
|
||||
`heap_size=normal`,
|
||||
`jvm_impl=hotspot`,
|
||||
'sort_method=DEFAULT',
|
||||
'sort_order=DESC',
|
||||
`os=${platform}`,
|
||||
`architecture=${arch}`,
|
||||
`image_type=${imageType}`,
|
||||
`release_type=${releaseType}`
|
||||
].join('&');
|
||||
|
||||
// need to iterate through all pages to retrieve the list of all versions
|
||||
// Adopt API doesn't provide way to retrieve the count of pages to iterate so infinity loop
|
||||
let page_index = 0;
|
||||
const availableVersions: IAdoptAvailableVersions[] = [];
|
||||
while (true) {
|
||||
const requestArguments = `${baseRequestArguments}&page_size=20&page=${page_index}`;
|
||||
const availableVersionsUrl = `https://api.adoptopenjdk.net/v3/assets/version/${versionRange}?${requestArguments}`;
|
||||
if (core.isDebug() && page_index === 0) {
|
||||
// url is identical except page_index so print it once for debug
|
||||
core.debug(`Gathering available versions from '${availableVersionsUrl}'`);
|
||||
}
|
||||
|
||||
const paginationPage = (
|
||||
await this.http.getJson<IAdoptAvailableVersions[]>(availableVersionsUrl)
|
||||
).result;
|
||||
if (paginationPage === null || paginationPage.length === 0) {
|
||||
// break infinity loop because we have reached end of pagination
|
||||
break;
|
||||
}
|
||||
|
||||
availableVersions.push(...paginationPage);
|
||||
page_index++;
|
||||
}
|
||||
|
||||
if (core.isDebug()) {
|
||||
core.startGroup('Print information about available versions');
|
||||
console.timeEnd('adopt-retrieve-available-versions');
|
||||
console.log(`Available versions: [${availableVersions.length}]`);
|
||||
console.log(availableVersions.map(item => item.version_data.semver).join(', '));
|
||||
core.endGroup();
|
||||
}
|
||||
|
||||
return availableVersions;
|
||||
}
|
||||
|
||||
private getPlatformOption(): string {
|
||||
// Adopt has own platform names so need to map them
|
||||
switch (process.platform) {
|
||||
case 'darwin':
|
||||
return 'mac';
|
||||
case 'win32':
|
||||
return 'windows';
|
||||
default:
|
||||
return process.platform;
|
||||
}
|
||||
}
|
||||
}
|
38
src/distributions/adopt/models.ts
Normal file
38
src/distributions/adopt/models.ts
Normal file
|
@ -0,0 +1,38 @@
|
|||
// Models from https://api.adoptopenjdk.net/swagger-ui/#/Assets/get_v3_assets_version__version
|
||||
|
||||
export interface IAdoptAvailableVersions {
|
||||
binaries: [
|
||||
{
|
||||
architecture: string;
|
||||
heap_size: string;
|
||||
image_type: string;
|
||||
jvm_impl: string;
|
||||
os: string;
|
||||
package: {
|
||||
checksum: string;
|
||||
checksum_link: string;
|
||||
download_count: number;
|
||||
link: string;
|
||||
metadata_link: string;
|
||||
name: string;
|
||||
size: string;
|
||||
};
|
||||
project: string;
|
||||
scm_ref: string;
|
||||
updated_at: string;
|
||||
}
|
||||
];
|
||||
id: string;
|
||||
release_link: string;
|
||||
release_name: string;
|
||||
release_type: string;
|
||||
vendor: string;
|
||||
version_data: {
|
||||
build: number;
|
||||
major: number;
|
||||
minor: number;
|
||||
openjdk_version: string;
|
||||
security: string;
|
||||
semver: string;
|
||||
};
|
||||
}
|
151
src/distributions/base-installer.ts
Normal file
151
src/distributions/base-installer.ts
Normal file
|
@ -0,0 +1,151 @@
|
|||
import * as tc from '@actions/tool-cache';
|
||||
import * as core from '@actions/core';
|
||||
import * as fs from 'fs';
|
||||
import semver from 'semver';
|
||||
import path from 'path';
|
||||
import * as httpm from '@actions/http-client';
|
||||
import { getToolcachePath, getVersionFromToolcachePath, isVersionSatisfies } from '../util';
|
||||
import { JavaDownloadRelease, JavaInstallerOptions, JavaInstallerResults } from './base-models';
|
||||
import { MACOS_JAVA_CONTENT_POSTFIX } from '../constants';
|
||||
|
||||
export abstract class JavaBase {
|
||||
protected http: httpm.HttpClient;
|
||||
protected version: string;
|
||||
protected architecture: string;
|
||||
protected packageType: string;
|
||||
protected stable: boolean;
|
||||
protected checkLatest: boolean;
|
||||
|
||||
constructor(protected distribution: string, installerOptions: JavaInstallerOptions) {
|
||||
this.http = new httpm.HttpClient('actions/setup-java', undefined, {
|
||||
allowRetries: true,
|
||||
maxRetries: 3
|
||||
});
|
||||
|
||||
({ version: this.version, stable: this.stable } = this.normalizeVersion(
|
||||
installerOptions.version
|
||||
));
|
||||
this.architecture = installerOptions.architecture;
|
||||
this.packageType = installerOptions.packageType;
|
||||
this.checkLatest = installerOptions.checkLatest;
|
||||
}
|
||||
|
||||
protected abstract downloadTool(javaRelease: JavaDownloadRelease): Promise<JavaInstallerResults>;
|
||||
protected abstract findPackageForDownload(range: string): Promise<JavaDownloadRelease>;
|
||||
|
||||
public async setupJava(): Promise<JavaInstallerResults> {
|
||||
let foundJava = this.findInToolcache();
|
||||
if (foundJava && !this.checkLatest) {
|
||||
core.info(`Resolved Java ${foundJava.version} from tool-cache`);
|
||||
} else {
|
||||
core.info('Trying to resolve the latest version from remote');
|
||||
const javaRelease = await this.findPackageForDownload(this.version);
|
||||
core.info(`Resolved latest version as ${javaRelease.version}`);
|
||||
if (foundJava?.version === javaRelease.version) {
|
||||
core.info(`Resolved Java ${foundJava.version} from tool-cache`);
|
||||
} else {
|
||||
core.info('Trying to download...');
|
||||
foundJava = await this.downloadTool(javaRelease);
|
||||
core.info(`Java ${foundJava.version} was downloaded`);
|
||||
}
|
||||
}
|
||||
|
||||
// JDK folder may contain postfix "Contents/Home" on macOS
|
||||
const macOSPostfixPath = path.join(foundJava.path, MACOS_JAVA_CONTENT_POSTFIX);
|
||||
if (process.platform === 'darwin' && fs.existsSync(macOSPostfixPath)) {
|
||||
foundJava.path = macOSPostfixPath;
|
||||
}
|
||||
|
||||
core.info(`Setting Java ${foundJava.version} as the default`);
|
||||
this.setJavaDefault(foundJava.version, foundJava.path);
|
||||
|
||||
return foundJava;
|
||||
}
|
||||
|
||||
protected get toolcacheFolderName(): string {
|
||||
return `Java_${this.distribution}_${this.packageType}`;
|
||||
}
|
||||
|
||||
protected getToolcacheVersionName(version: string): string {
|
||||
if (!this.stable) {
|
||||
if (version.includes('+')) {
|
||||
return version.replace('+', '-ea.');
|
||||
} else {
|
||||
return `${version}-ea`;
|
||||
}
|
||||
}
|
||||
|
||||
// Kotlin and some Java dependencies don't work properly when Java path contains "+" sign
|
||||
// so replace "/hostedtoolcache/Java/11.0.3+4/x64" to "/hostedtoolcache/Java/11.0.3-4/x64" when saves to cache
|
||||
// related issue: https://github.com/actions/virtual-environments/issues/3014
|
||||
return version.replace('+', '-');
|
||||
}
|
||||
|
||||
protected findInToolcache(): JavaInstallerResults | null {
|
||||
// we can't use tc.find directly because firstly, we need to filter versions by stability flag
|
||||
// if *-ea is provided, take only ea versions from toolcache, otherwise - only stable versions
|
||||
const availableVersions = tc
|
||||
.findAllVersions(this.toolcacheFolderName, this.architecture)
|
||||
.map(item => {
|
||||
return {
|
||||
version: item
|
||||
.replace('-ea.', '+')
|
||||
.replace(/-ea$/, '')
|
||||
// Kotlin and some Java dependencies don't work properly when Java path contains "+" sign
|
||||
// so replace "/hostedtoolcache/Java/11.0.3-4/x64" to "/hostedtoolcache/Java/11.0.3+4/x64" when retrieves to cache
|
||||
// related issue: https://github.com/actions/virtual-environments/issues/3014
|
||||
.replace('-', '+'),
|
||||
path: getToolcachePath(this.toolcacheFolderName, item, this.architecture) || '',
|
||||
stable: !item.includes('-ea')
|
||||
};
|
||||
})
|
||||
.filter(item => item.stable === this.stable);
|
||||
|
||||
const satisfiedVersions = availableVersions
|
||||
.filter(item => isVersionSatisfies(this.version, item.version))
|
||||
.filter(item => item.path)
|
||||
.sort((a, b) => {
|
||||
return -semver.compareBuild(a.version, b.version);
|
||||
});
|
||||
if (!satisfiedVersions || satisfiedVersions.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
version: satisfiedVersions[0].version,
|
||||
path: satisfiedVersions[0].path
|
||||
};
|
||||
}
|
||||
|
||||
protected normalizeVersion(version: string) {
|
||||
let stable = true;
|
||||
|
||||
if (version.endsWith('-ea')) {
|
||||
version = version.replace(/-ea$/, '');
|
||||
stable = false;
|
||||
} else if (version.includes('-ea.')) {
|
||||
// transform '11.0.3-ea.2' -> '11.0.3+2'
|
||||
version = version.replace('-ea.', '+');
|
||||
stable = false;
|
||||
}
|
||||
|
||||
if (!semver.validRange(version)) {
|
||||
throw new Error(
|
||||
`The string '${version}' is not valid SemVer notation for a Java version. Please check README file for code snippets and more detailed information`
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
version,
|
||||
stable
|
||||
};
|
||||
}
|
||||
|
||||
protected setJavaDefault(version: string, toolPath: string) {
|
||||
core.exportVariable('JAVA_HOME', toolPath);
|
||||
core.addPath(path.join(toolPath, 'bin'));
|
||||
core.setOutput('distribution', this.distribution);
|
||||
core.setOutput('path', toolPath);
|
||||
core.setOutput('version', version);
|
||||
}
|
||||
}
|
16
src/distributions/base-models.ts
Normal file
16
src/distributions/base-models.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
export interface JavaInstallerOptions {
|
||||
version: string;
|
||||
architecture: string;
|
||||
packageType: string;
|
||||
checkLatest: boolean;
|
||||
}
|
||||
|
||||
export interface JavaInstallerResults {
|
||||
version: string;
|
||||
path: string;
|
||||
}
|
||||
|
||||
export interface JavaDownloadRelease {
|
||||
version: string;
|
||||
url: string;
|
||||
}
|
28
src/distributions/distribution-factory.ts
Normal file
28
src/distributions/distribution-factory.ts
Normal file
|
@ -0,0 +1,28 @@
|
|||
import { AdoptDistribution } from './adopt/installer';
|
||||
import { JavaBase } from './base-installer';
|
||||
import { JavaInstallerOptions } from './base-models';
|
||||
import { LocalDistribution } from './local/installer';
|
||||
import { ZuluDistribution } from './zulu/installer';
|
||||
|
||||
enum JavaDistribution {
|
||||
Adopt = 'adopt',
|
||||
Zulu = 'zulu',
|
||||
JdkFile = 'jdkfile'
|
||||
}
|
||||
|
||||
export function getJavaDistribution(
|
||||
distributionName: string,
|
||||
installerOptions: JavaInstallerOptions,
|
||||
jdkFile?: string
|
||||
): JavaBase | null {
|
||||
switch (distributionName) {
|
||||
case JavaDistribution.JdkFile:
|
||||
return new LocalDistribution(installerOptions, jdkFile);
|
||||
case JavaDistribution.Adopt:
|
||||
return new AdoptDistribution(installerOptions);
|
||||
case JavaDistribution.Zulu:
|
||||
return new ZuluDistribution(installerOptions);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
76
src/distributions/local/installer.ts
Normal file
76
src/distributions/local/installer.ts
Normal file
|
@ -0,0 +1,76 @@
|
|||
import * as tc from '@actions/tool-cache';
|
||||
import * as core from '@actions/core';
|
||||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import semver from 'semver';
|
||||
|
||||
import { JavaBase } from '../base-installer';
|
||||
import { JavaInstallerOptions, JavaDownloadRelease, JavaInstallerResults } from '../base-models';
|
||||
import { extractJdkFile } from '../../util';
|
||||
import { MACOS_JAVA_CONTENT_POSTFIX } from '../../constants';
|
||||
|
||||
export class LocalDistribution extends JavaBase {
|
||||
constructor(installerOptions: JavaInstallerOptions, private jdkFile?: string) {
|
||||
super('jdkfile', installerOptions);
|
||||
}
|
||||
|
||||
public async setupJava(): Promise<JavaInstallerResults> {
|
||||
let foundJava = this.findInToolcache();
|
||||
|
||||
if (foundJava) {
|
||||
core.info(`Resolved Java ${foundJava.version} from tool-cache`);
|
||||
} else {
|
||||
core.info(`Java ${this.version} was not found in tool-cache. Trying to unpack JDK file...`);
|
||||
if (!this.jdkFile) {
|
||||
throw new Error("'jdkFile' is not specified");
|
||||
}
|
||||
const jdkFilePath = path.resolve(this.jdkFile);
|
||||
const stats = fs.statSync(jdkFilePath);
|
||||
|
||||
if (!stats.isFile()) {
|
||||
throw new Error(`JDK file was not found in path '${jdkFilePath}'`);
|
||||
}
|
||||
|
||||
core.info(`Extracting Java from '${jdkFilePath}'`);
|
||||
|
||||
const extractedJavaPath = await extractJdkFile(jdkFilePath);
|
||||
const archiveName = fs.readdirSync(extractedJavaPath)[0];
|
||||
const archivePath = path.join(extractedJavaPath, archiveName);
|
||||
const javaVersion = this.version;
|
||||
|
||||
let javaPath = await tc.cacheDir(
|
||||
archivePath,
|
||||
this.toolcacheFolderName,
|
||||
this.getToolcacheVersionName(javaVersion),
|
||||
this.architecture
|
||||
);
|
||||
|
||||
// for different Java distributions, postfix can exist or not so need to check both cases
|
||||
if (
|
||||
process.platform === 'darwin' &&
|
||||
fs.existsSync(path.join(javaPath, MACOS_JAVA_CONTENT_POSTFIX))
|
||||
) {
|
||||
javaPath = path.join(javaPath, MACOS_JAVA_CONTENT_POSTFIX);
|
||||
}
|
||||
|
||||
foundJava = {
|
||||
version: javaVersion,
|
||||
path: javaPath
|
||||
};
|
||||
}
|
||||
|
||||
core.info(`Setting Java ${foundJava.version} as default`);
|
||||
|
||||
this.setJavaDefault(foundJava.version, foundJava.path);
|
||||
return foundJava;
|
||||
}
|
||||
|
||||
protected async findPackageForDownload(version: string): Promise<JavaDownloadRelease> {
|
||||
throw new Error('This method should not be implemented in local file provider');
|
||||
}
|
||||
|
||||
protected async downloadTool(javaRelease: JavaDownloadRelease): Promise<JavaInstallerResults> {
|
||||
throw new Error('This method should not be implemented in local file provider');
|
||||
}
|
||||
}
|
163
src/distributions/zulu/installer.ts
Normal file
163
src/distributions/zulu/installer.ts
Normal file
|
@ -0,0 +1,163 @@
|
|||
import * as core from '@actions/core';
|
||||
import * as tc from '@actions/tool-cache';
|
||||
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
import semver from 'semver';
|
||||
|
||||
import { JavaBase } from '../base-installer';
|
||||
import { IZuluVersions } from './models';
|
||||
import { extractJdkFile, getDownloadArchiveExtension, isVersionSatisfies } from '../../util';
|
||||
import { JavaDownloadRelease, JavaInstallerOptions, JavaInstallerResults } from '../base-models';
|
||||
|
||||
export class ZuluDistribution extends JavaBase {
|
||||
constructor(installerOptions: JavaInstallerOptions) {
|
||||
super('Zulu', installerOptions);
|
||||
}
|
||||
|
||||
protected async findPackageForDownload(version: string): Promise<JavaDownloadRelease> {
|
||||
const availableVersionsRaw = await this.getAvailableVersions();
|
||||
const availableVersions = availableVersionsRaw.map(item => {
|
||||
return {
|
||||
version: this.convertVersionToSemver(item.jdk_version),
|
||||
url: item.url,
|
||||
zuluVersion: this.convertVersionToSemver(item.zulu_version)
|
||||
};
|
||||
});
|
||||
|
||||
const satisfiedVersions = availableVersions
|
||||
.filter(item => isVersionSatisfies(version, item.version))
|
||||
.sort((a, b) => {
|
||||
// Azul provides two versions: jdk_version and azul_version
|
||||
// we should sort by both fields by descending
|
||||
return (
|
||||
-semver.compareBuild(a.version, b.version) ||
|
||||
-semver.compareBuild(a.zuluVersion, b.zuluVersion)
|
||||
);
|
||||
})
|
||||
.map(item => {
|
||||
return {
|
||||
version: item.version,
|
||||
url: item.url
|
||||
} as JavaDownloadRelease;
|
||||
});
|
||||
|
||||
const resolvedFullVersion = satisfiedVersions.length > 0 ? satisfiedVersions[0] : null;
|
||||
if (!resolvedFullVersion) {
|
||||
const availableOptions = availableVersions.map(item => item.version).join(', ');
|
||||
const availableOptionsMessage = availableOptions
|
||||
? `\nAvailable versions: ${availableOptions}`
|
||||
: '';
|
||||
throw new Error(
|
||||
`Could not find satisfied version for semver ${version}. ${availableOptionsMessage}`
|
||||
);
|
||||
}
|
||||
|
||||
return resolvedFullVersion;
|
||||
}
|
||||
|
||||
protected async downloadTool(javaRelease: JavaDownloadRelease): Promise<JavaInstallerResults> {
|
||||
let extractedJavaPath: string;
|
||||
|
||||
core.info(
|
||||
`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`
|
||||
);
|
||||
const javaArchivePath = await tc.downloadTool(javaRelease.url);
|
||||
|
||||
core.info(`Extracting Java archive...`);
|
||||
let extension = getDownloadArchiveExtension();
|
||||
|
||||
extractedJavaPath = await extractJdkFile(javaArchivePath, extension);
|
||||
|
||||
const archiveName = fs.readdirSync(extractedJavaPath)[0];
|
||||
const archivePath = path.join(extractedJavaPath, archiveName);
|
||||
|
||||
const javaPath = await tc.cacheDir(
|
||||
archivePath,
|
||||
this.toolcacheFolderName,
|
||||
this.getToolcacheVersionName(javaRelease.version),
|
||||
this.architecture
|
||||
);
|
||||
|
||||
return { version: javaRelease.version, path: javaPath };
|
||||
}
|
||||
|
||||
private async getAvailableVersions(): Promise<IZuluVersions[]> {
|
||||
const { arch, hw_bitness, abi } = this.getArchitectureOptions();
|
||||
const [bundleType, features] = this.packageType.split('+');
|
||||
const platform = this.getPlatformOption();
|
||||
const extension = getDownloadArchiveExtension();
|
||||
const javafx = features?.includes('fx') ?? false;
|
||||
const releaseStatus = this.stable ? 'ga' : 'ea';
|
||||
|
||||
console.time('azul-retrieve-available-versions');
|
||||
const requestArguments = [
|
||||
`os=${platform}`,
|
||||
`ext=${extension}`,
|
||||
`bundle_type=${bundleType}`,
|
||||
`javafx=${javafx}`,
|
||||
`arch=${arch}`,
|
||||
`hw_bitness=${hw_bitness}`,
|
||||
`release_status=${releaseStatus}`,
|
||||
abi ? `abi=${abi}` : null,
|
||||
features ? `features=${features}` : null
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join('&');
|
||||
|
||||
const availableVersionsUrl = `https://api.azul.com/zulu/download/community/v1.0/bundles/?${requestArguments}`;
|
||||
if (core.isDebug()) {
|
||||
core.debug(`Gathering available versions from '${availableVersionsUrl}'`);
|
||||
}
|
||||
|
||||
const availableVersions =
|
||||
(await this.http.getJson<Array<IZuluVersions>>(availableVersionsUrl)).result ?? [];
|
||||
|
||||
if (core.isDebug()) {
|
||||
core.startGroup('Print information about available versions');
|
||||
console.timeEnd('azul-retrieve-available-versions');
|
||||
console.log(`Available versions: [${availableVersions.length}]`);
|
||||
console.log(availableVersions.map(item => item.jdk_version.join('.')).join(', '));
|
||||
core.endGroup();
|
||||
}
|
||||
|
||||
return availableVersions;
|
||||
}
|
||||
|
||||
private getArchitectureOptions(): {
|
||||
arch: string;
|
||||
hw_bitness: string;
|
||||
abi: string;
|
||||
} {
|
||||
if (this.architecture == 'x64') {
|
||||
return { arch: 'x86', hw_bitness: '64', abi: '' };
|
||||
} else if (this.architecture == 'x86') {
|
||||
return { arch: 'x86', hw_bitness: '32', abi: '' };
|
||||
} else {
|
||||
return { arch: this.architecture, hw_bitness: '', abi: '' };
|
||||
}
|
||||
}
|
||||
|
||||
private getPlatformOption(): string {
|
||||
// Azul has own platform names so need to map them
|
||||
switch (process.platform) {
|
||||
case 'darwin':
|
||||
return 'macos';
|
||||
case 'win32':
|
||||
return 'windows';
|
||||
default:
|
||||
return process.platform;
|
||||
}
|
||||
}
|
||||
|
||||
// Azul API returns jdk_version as array of digits like [11, 0, 2, 1]
|
||||
private convertVersionToSemver(version_array: number[]) {
|
||||
const mainVersion = version_array.slice(0, 3).join('.');
|
||||
if (version_array.length > 3) {
|
||||
// intentionally ignore more than 4 numbers because it is invalid semver
|
||||
return `${mainVersion}+${version_array[3]}`;
|
||||
}
|
||||
|
||||
return mainVersion;
|
||||
}
|
||||
}
|
9
src/distributions/zulu/models.ts
Normal file
9
src/distributions/zulu/models.ts
Normal file
|
@ -0,0 +1,9 @@
|
|||
// Models from https://app.swaggerhub.com/apis-docs/azul/zulu-download-community/1.0
|
||||
|
||||
export interface IZuluVersions {
|
||||
id: number;
|
||||
name: string;
|
||||
url: string;
|
||||
jdk_version: Array<number>;
|
||||
zulu_version: Array<number>;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue