mirror of
https://github.com/actions/setup-java.git
synced 2025-04-21 10:26:46 +00:00
Merge branch 'main' into include-versions.properties-in-cache-key
This commit is contained in:
commit
450ead13d3
103 changed files with 143854 additions and 125027 deletions
30
src/auth.ts
30
src/auth.ts
|
@ -5,23 +5,25 @@ import * as io from '@actions/io';
|
|||
import * as fs from 'fs';
|
||||
import * as os from 'os';
|
||||
|
||||
import { create as xmlCreate } from 'xmlbuilder2';
|
||||
import {create as xmlCreate} from 'xmlbuilder2';
|
||||
import * as constants from './constants';
|
||||
import * as gpg from './gpg';
|
||||
import { getBooleanInput } from './util';
|
||||
|
||||
export const M2_DIR = '.m2';
|
||||
export const SETTINGS_FILE = 'settings.xml';
|
||||
import {getBooleanInput} from './util';
|
||||
|
||||
export async function configureAuthentication() {
|
||||
const id = core.getInput(constants.INPUT_SERVER_ID);
|
||||
const username = core.getInput(constants.INPUT_SERVER_USERNAME);
|
||||
const password = core.getInput(constants.INPUT_SERVER_PASSWORD);
|
||||
const settingsDirectory =
|
||||
core.getInput(constants.INPUT_SETTINGS_PATH) || path.join(os.homedir(), M2_DIR);
|
||||
const overwriteSettings = getBooleanInput(constants.INPUT_OVERWRITE_SETTINGS, true);
|
||||
core.getInput(constants.INPUT_SETTINGS_PATH) ||
|
||||
path.join(os.homedir(), constants.M2_DIR);
|
||||
const overwriteSettings = getBooleanInput(
|
||||
constants.INPUT_OVERWRITE_SETTINGS,
|
||||
true
|
||||
);
|
||||
const gpgPrivateKey =
|
||||
core.getInput(constants.INPUT_GPG_PRIVATE_KEY) || constants.INPUT_DEFAULT_GPG_PRIVATE_KEY;
|
||||
core.getInput(constants.INPUT_GPG_PRIVATE_KEY) ||
|
||||
constants.INPUT_DEFAULT_GPG_PRIVATE_KEY;
|
||||
const gpgPassphrase =
|
||||
core.getInput(constants.INPUT_GPG_PASSPHRASE) ||
|
||||
(gpgPrivateKey ? constants.INPUT_DEFAULT_GPG_PASSPHRASE : undefined);
|
||||
|
@ -54,7 +56,7 @@ export async function createAuthenticationSettings(
|
|||
overwriteSettings: boolean,
|
||||
gpgPassphrase: string | undefined = undefined
|
||||
) {
|
||||
core.info(`Creating ${SETTINGS_FILE} with server-id: ${id}`);
|
||||
core.info(`Creating ${constants.MVN_SETTINGS_FILE} with server-id: ${id}`);
|
||||
// when an alternate m2 location is specified use only that location (no .m2 directory)
|
||||
// otherwise use the home/.m2/ path
|
||||
await io.mkdirP(settingsDirectory);
|
||||
|
@ -72,7 +74,7 @@ export function generate(
|
|||
password: string,
|
||||
gpgPassphrase?: string | undefined
|
||||
) {
|
||||
const xmlObj: { [key: string]: any } = {
|
||||
const xmlObj: {[key: string]: any} = {
|
||||
settings: {
|
||||
'@xmlns': 'http://maven.apache.org/SETTINGS/1.0.0',
|
||||
'@xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
|
||||
|
@ -105,8 +107,12 @@ export function generate(
|
|||
});
|
||||
}
|
||||
|
||||
async function write(directory: string, settings: string, overwriteSettings: boolean) {
|
||||
const location = path.join(directory, SETTINGS_FILE);
|
||||
async function write(
|
||||
directory: string,
|
||||
settings: string,
|
||||
overwriteSettings: boolean
|
||||
) {
|
||||
const location = path.join(directory, constants.MVN_SETTINGS_FILE);
|
||||
const settingsExists = fs.existsSync(location);
|
||||
if (settingsExists && overwriteSettings) {
|
||||
core.info(`Overwriting existing file ${location}`);
|
||||
|
|
70
src/cache.ts
70
src/cache.ts
|
@ -2,7 +2,7 @@
|
|||
* @fileoverview this file provides methods handling dependency cache
|
||||
*/
|
||||
|
||||
import { join } from 'path';
|
||||
import {join} from 'path';
|
||||
import os from 'os';
|
||||
import * as cache from '@actions/cache';
|
||||
import * as core from '@actions/core';
|
||||
|
@ -13,7 +13,7 @@ const CACHE_MATCHED_KEY = 'cache-matched-key';
|
|||
const CACHE_KEY_PREFIX = 'setup-java';
|
||||
|
||||
interface PackageManager {
|
||||
id: 'maven' | 'gradle';
|
||||
id: 'maven' | 'gradle' | 'sbt';
|
||||
/**
|
||||
* Paths of the file that specify the files to cache.
|
||||
*/
|
||||
|
@ -29,14 +29,51 @@ const supportedPackageManager: PackageManager[] = [
|
|||
},
|
||||
{
|
||||
id: 'gradle',
|
||||
path: [join(os.homedir(), '.gradle', 'caches'), join(os.homedir(), '.gradle', 'wrapper')],
|
||||
path: [
|
||||
join(os.homedir(), '.gradle', 'caches'),
|
||||
join(os.homedir(), '.gradle', 'wrapper')
|
||||
],
|
||||
// https://github.com/actions/cache/blob/0638051e9af2c23d10bb70fa9beffcad6cff9ce3/examples.md#java---gradle
|
||||
pattern: ['**/*.gradle*', '**/gradle-wrapper.properties', '**/versions.properties']
|
||||
pattern: [
|
||||
'**/*.gradle*',
|
||||
'**/gradle-wrapper.properties',
|
||||
'buildSrc/**/Versions.kt',
|
||||
'buildSrc/**/Dependencies.kt',
|
||||
'gradle/*.versions.toml',
|
||||
'**/versions.properties'
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'sbt',
|
||||
path: [
|
||||
join(os.homedir(), '.ivy2', 'cache'),
|
||||
join(os.homedir(), '.sbt'),
|
||||
getCoursierCachePath(),
|
||||
// Some files should not be cached to avoid resolution problems.
|
||||
// In particular the resolution of snapshots (ideological gap between maven/ivy).
|
||||
'!' + join(os.homedir(), '.sbt', '*.lock'),
|
||||
'!' + join(os.homedir(), '**', 'ivydata-*.properties')
|
||||
],
|
||||
pattern: [
|
||||
'**/*.sbt',
|
||||
'**/project/build.properties',
|
||||
'**/project/**.scala',
|
||||
'**/project/**.sbt'
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
function getCoursierCachePath(): string {
|
||||
if (os.type() === 'Linux') return join(os.homedir(), '.cache', 'coursier');
|
||||
if (os.type() === 'Darwin')
|
||||
return join(os.homedir(), 'Library', 'Caches', 'Coursier');
|
||||
return join(os.homedir(), 'AppData', 'Local', 'Coursier', 'Cache');
|
||||
}
|
||||
|
||||
function findPackageManager(id: string): PackageManager {
|
||||
const packageManager = supportedPackageManager.find(packageManager => packageManager.id === id);
|
||||
const packageManager = supportedPackageManager.find(
|
||||
packageManager => packageManager.id === id
|
||||
);
|
||||
if (packageManager === undefined) {
|
||||
throw new Error(`unknown package manager specified: ${id}`);
|
||||
}
|
||||
|
@ -72,13 +109,14 @@ export async function restore(id: string) {
|
|||
);
|
||||
}
|
||||
|
||||
const matchedKey = await cache.restoreCache(packageManager.path, primaryKey, [
|
||||
`${CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${id}`
|
||||
]);
|
||||
// No "restoreKeys" is set, to start with a clear cache after dependency update (see https://github.com/actions/setup-java/issues/269)
|
||||
const matchedKey = await cache.restoreCache(packageManager.path, primaryKey);
|
||||
if (matchedKey) {
|
||||
core.saveState(CACHE_MATCHED_KEY, matchedKey);
|
||||
core.setOutput('cache-hit', matchedKey === primaryKey);
|
||||
core.info(`Cache restored from key: ${matchedKey}`);
|
||||
} else {
|
||||
core.setOutput('cache-hit', false);
|
||||
core.info(`${packageManager.id} cache is not found`);
|
||||
}
|
||||
}
|
||||
|
@ -91,7 +129,7 @@ export async function save(id: string) {
|
|||
const packageManager = findPackageManager(id);
|
||||
const matchedKey = core.getState(CACHE_MATCHED_KEY);
|
||||
|
||||
// Inputs are re-evaluted before the post action, so we want the original key used for restore
|
||||
// Inputs are re-evaluated before the post action, so we want the original key used for restore
|
||||
const primaryKey = core.getState(STATE_CACHE_PRIMARY_KEY);
|
||||
|
||||
if (!primaryKey) {
|
||||
|
@ -99,7 +137,9 @@ export async function save(id: string) {
|
|||
return;
|
||||
} else if (matchedKey === primaryKey) {
|
||||
// no change in target directories
|
||||
core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`);
|
||||
core.info(
|
||||
`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`
|
||||
);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
|
@ -125,8 +165,14 @@ export async function save(id: string) {
|
|||
* @returns true if the given error seems related to the {@link https://github.com/actions/cache/issues/454|running Gradle Daemon issue}.
|
||||
* @see {@link https://github.com/actions/cache/issues/454#issuecomment-840493935|why --no-daemon is necessary}
|
||||
*/
|
||||
function isProbablyGradleDaemonProblem(packageManager: PackageManager, error: Error) {
|
||||
if (packageManager.id !== 'gradle' || process.env['RUNNER_OS'] !== 'Windows') {
|
||||
function isProbablyGradleDaemonProblem(
|
||||
packageManager: PackageManager,
|
||||
error: Error
|
||||
) {
|
||||
if (
|
||||
packageManager.id !== 'gradle' ||
|
||||
process.env['RUNNER_OS'] !== 'Windows'
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
const message = error.message || '';
|
||||
|
|
|
@ -1,14 +1,16 @@
|
|||
import * as core from '@actions/core';
|
||||
import * as gpg from './gpg';
|
||||
import * as constants from './constants';
|
||||
import { isJobStatusSuccess } from './util';
|
||||
import { save } from './cache';
|
||||
import {isJobStatusSuccess} from './util';
|
||||
import {save} from './cache';
|
||||
|
||||
async function removePrivateKeyFromKeychain() {
|
||||
if (core.getInput(constants.INPUT_GPG_PRIVATE_KEY, { required: false })) {
|
||||
if (core.getInput(constants.INPUT_GPG_PRIVATE_KEY, {required: false})) {
|
||||
core.info('Removing private key from keychain');
|
||||
try {
|
||||
const keyFingerprint = core.getState(constants.STATE_GPG_PRIVATE_KEY_FINGERPRINT);
|
||||
const keyFingerprint = core.getState(
|
||||
constants.STATE_GPG_PRIVATE_KEY_FINGERPRINT
|
||||
);
|
||||
await gpg.deleteKey(keyFingerprint);
|
||||
} catch (error) {
|
||||
core.setFailed(`Failed to remove private key due to: ${error.message}`);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
export const MACOS_JAVA_CONTENT_POSTFIX = 'Contents/Home';
|
||||
export const INPUT_JAVA_VERSION = 'java-version';
|
||||
export const INPUT_JAVA_VERSION_FILE = 'java-version-file';
|
||||
export const INPUT_ARCHITECTURE = 'architecture';
|
||||
export const INPUT_JAVA_PACKAGE = 'java-package';
|
||||
export const INPUT_DISTRIBUTION = 'distribution';
|
||||
|
@ -20,3 +21,11 @@ export const INPUT_CACHE = 'cache';
|
|||
export const INPUT_JOB_STATUS = 'job-status';
|
||||
|
||||
export const STATE_GPG_PRIVATE_KEY_FINGERPRINT = 'gpg-private-key-fingerprint';
|
||||
|
||||
export const M2_DIR = '.m2';
|
||||
export const MVN_SETTINGS_FILE = 'settings.xml';
|
||||
export const MVN_TOOLCHAINS_FILE = 'toolchains.xml';
|
||||
export const INPUT_MVN_TOOLCHAIN_ID = 'mvn-toolchain-id';
|
||||
export const INPUT_MVN_TOOLCHAIN_VENDOR = 'mvn-toolchain-vendor';
|
||||
|
||||
export const DISTRIBUTIONS_ONLY_MAJOR_VERSION = ['corretto'];
|
||||
|
|
|
@ -5,10 +5,18 @@ import fs from 'fs';
|
|||
import path from 'path';
|
||||
import semver from 'semver';
|
||||
|
||||
import { JavaBase } from '../base-installer';
|
||||
import { IAdoptAvailableVersions } from './models';
|
||||
import { JavaDownloadRelease, JavaInstallerOptions, JavaInstallerResults } from '../base-models';
|
||||
import { extractJdkFile, getDownloadArchiveExtension, isVersionSatisfies } from '../../util';
|
||||
import {JavaBase} from '../base-installer';
|
||||
import {IAdoptAvailableVersions} from './models';
|
||||
import {
|
||||
JavaDownloadRelease,
|
||||
JavaInstallerOptions,
|
||||
JavaInstallerResults
|
||||
} from '../base-models';
|
||||
import {
|
||||
extractJdkFile,
|
||||
getDownloadArchiveExtension,
|
||||
isVersionSatisfies
|
||||
} from '../../util';
|
||||
|
||||
export enum AdoptImplementation {
|
||||
Hotspot = 'Hotspot',
|
||||
|
@ -23,7 +31,9 @@ export class AdoptDistribution extends JavaBase {
|
|||
super(`Adopt-${jvmImpl}`, installerOptions);
|
||||
}
|
||||
|
||||
protected async findPackageForDownload(version: string): Promise<JavaDownloadRelease> {
|
||||
protected async findPackageForDownload(
|
||||
version: string
|
||||
): Promise<JavaDownloadRelease> {
|
||||
const availableVersionsRaw = await this.getAvailableVersions();
|
||||
const availableVersionsWithBinaries = availableVersionsRaw
|
||||
.filter(item => item.binaries.length > 0)
|
||||
|
@ -40,9 +50,12 @@ export class AdoptDistribution extends JavaBase {
|
|||
return -semver.compareBuild(a.version, b.version);
|
||||
});
|
||||
|
||||
const resolvedFullVersion = satisfiedVersions.length > 0 ? satisfiedVersions[0] : null;
|
||||
const resolvedFullVersion =
|
||||
satisfiedVersions.length > 0 ? satisfiedVersions[0] : null;
|
||||
if (!resolvedFullVersion) {
|
||||
const availableOptions = availableVersionsWithBinaries.map(item => item.version).join(', ');
|
||||
const availableOptions = availableVersionsWithBinaries
|
||||
.map(item => item.version)
|
||||
.join(', ');
|
||||
const availableOptionsMessage = availableOptions
|
||||
? `\nAvailable versions: ${availableOptions}`
|
||||
: '';
|
||||
|
@ -54,27 +67,31 @@ export class AdoptDistribution extends JavaBase {
|
|||
return resolvedFullVersion;
|
||||
}
|
||||
|
||||
protected async downloadTool(javaRelease: JavaDownloadRelease): Promise<JavaInstallerResults> {
|
||||
let javaPath: string;
|
||||
let extractedJavaPath: string;
|
||||
|
||||
protected async downloadTool(
|
||||
javaRelease: JavaDownloadRelease
|
||||
): Promise<JavaInstallerResults> {
|
||||
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();
|
||||
const extension = getDownloadArchiveExtension();
|
||||
|
||||
extractedJavaPath = await extractJdkFile(javaArchivePath, extension);
|
||||
const 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);
|
||||
const javaPath = await tc.cacheDir(
|
||||
archivePath,
|
||||
this.toolcacheFolderName,
|
||||
version,
|
||||
this.architecture
|
||||
);
|
||||
|
||||
return { version: javaRelease.version, path: javaPath };
|
||||
return {version: javaRelease.version, path: javaPath};
|
||||
}
|
||||
|
||||
protected get toolcacheFolderName(): string {
|
||||
|
@ -88,12 +105,14 @@ export class AdoptDistribution extends JavaBase {
|
|||
|
||||
private async getAvailableVersions(): Promise<IAdoptAvailableVersions[]> {
|
||||
const platform = this.getPlatformOption();
|
||||
const arch = this.architecture;
|
||||
const arch = this.distributionArchitecture();
|
||||
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');
|
||||
if (core.isDebug()) {
|
||||
console.time('Retrieving available versions for Adopt took'); // eslint-disable-line no-console
|
||||
}
|
||||
|
||||
const baseRequestArguments = [
|
||||
`project=jdk`,
|
||||
|
@ -117,7 +136,9 @@ export class AdoptDistribution extends JavaBase {
|
|||
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}'`);
|
||||
core.debug(
|
||||
`Gathering available versions from '${availableVersionsUrl}'`
|
||||
);
|
||||
}
|
||||
|
||||
const paginationPage = (
|
||||
|
@ -134,9 +155,11 @@ export class AdoptDistribution extends JavaBase {
|
|||
|
||||
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(', '));
|
||||
console.timeEnd('Retrieving available versions for Adopt took'); // eslint-disable-line no-console
|
||||
core.debug(`Available versions: [${availableVersions.length}]`);
|
||||
core.debug(
|
||||
availableVersions.map(item => item.version_data.semver).join(', ')
|
||||
);
|
||||
core.endGroup();
|
||||
}
|
||||
|
||||
|
|
|
@ -4,9 +4,14 @@ 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';
|
||||
import {getToolcachePath, isVersionSatisfies} from '../util';
|
||||
import {
|
||||
JavaDownloadRelease,
|
||||
JavaInstallerOptions,
|
||||
JavaInstallerResults
|
||||
} from './base-models';
|
||||
import {MACOS_JAVA_CONTENT_POSTFIX} from '../constants';
|
||||
import os from 'os';
|
||||
|
||||
export abstract class JavaBase {
|
||||
protected http: httpm.HttpClient;
|
||||
|
@ -16,22 +21,29 @@ export abstract class JavaBase {
|
|||
protected stable: boolean;
|
||||
protected checkLatest: boolean;
|
||||
|
||||
constructor(protected distribution: string, installerOptions: JavaInstallerOptions) {
|
||||
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(
|
||||
({version: this.version, stable: this.stable} = this.normalizeVersion(
|
||||
installerOptions.version
|
||||
));
|
||||
this.architecture = installerOptions.architecture;
|
||||
this.architecture = installerOptions.architecture || os.arch();
|
||||
this.packageType = installerOptions.packageType;
|
||||
this.checkLatest = installerOptions.checkLatest;
|
||||
}
|
||||
|
||||
protected abstract downloadTool(javaRelease: JavaDownloadRelease): Promise<JavaInstallerResults>;
|
||||
protected abstract findPackageForDownload(range: string): Promise<JavaDownloadRelease>;
|
||||
protected abstract downloadTool(
|
||||
javaRelease: JavaDownloadRelease
|
||||
): Promise<JavaInstallerResults>;
|
||||
protected abstract findPackageForDownload(
|
||||
range: string
|
||||
): Promise<JavaDownloadRelease>;
|
||||
|
||||
public async setupJava(): Promise<JavaInstallerResults> {
|
||||
let foundJava = this.findInToolcache();
|
||||
|
@ -51,7 +63,10 @@ export abstract class JavaBase {
|
|||
}
|
||||
|
||||
// JDK folder may contain postfix "Contents/Home" on macOS
|
||||
const macOSPostfixPath = path.join(foundJava.path, MACOS_JAVA_CONTENT_POSTFIX);
|
||||
const macOSPostfixPath = path.join(
|
||||
foundJava.path,
|
||||
MACOS_JAVA_CONTENT_POSTFIX
|
||||
);
|
||||
if (process.platform === 'darwin' && fs.existsSync(macOSPostfixPath)) {
|
||||
foundJava.path = macOSPostfixPath;
|
||||
}
|
||||
|
@ -95,7 +110,12 @@ export abstract class JavaBase {
|
|||
// 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) || '',
|
||||
path:
|
||||
getToolcachePath(
|
||||
this.toolcacheFolderName,
|
||||
item,
|
||||
this.architecture
|
||||
) || '',
|
||||
stable: !item.includes('-ea')
|
||||
};
|
||||
})
|
||||
|
@ -142,10 +162,35 @@ export abstract class JavaBase {
|
|||
}
|
||||
|
||||
protected setJavaDefault(version: string, toolPath: string) {
|
||||
const majorVersion = version.split('.')[0];
|
||||
core.exportVariable('JAVA_HOME', toolPath);
|
||||
core.addPath(path.join(toolPath, 'bin'));
|
||||
core.setOutput('distribution', this.distribution);
|
||||
core.setOutput('path', toolPath);
|
||||
core.setOutput('version', version);
|
||||
core.exportVariable(
|
||||
`JAVA_HOME_${majorVersion}_${this.architecture.toUpperCase()}`,
|
||||
toolPath
|
||||
);
|
||||
}
|
||||
|
||||
protected distributionArchitecture(): string {
|
||||
// default mappings of config architectures to distribution architectures
|
||||
// override if a distribution uses any different names; see liberica for an example
|
||||
|
||||
// node's os.arch() - which this defaults to - can return any of:
|
||||
// 'arm', 'arm64', 'ia32', 'mips', 'mipsel', 'ppc', 'ppc64', 's390', 's390x', and 'x64'
|
||||
// so we need to map these to java distribution architectures
|
||||
// 'amd64' is included here too b/c it's a common alias for 'x64' people might use explicitly
|
||||
switch (this.architecture) {
|
||||
case 'amd64':
|
||||
return 'x64';
|
||||
case 'ia32':
|
||||
return 'x86';
|
||||
case 'arm64':
|
||||
return 'aarch64';
|
||||
default:
|
||||
return this.architecture;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
186
src/distributions/corretto/installer.ts
Normal file
186
src/distributions/corretto/installer.ts
Normal file
|
@ -0,0 +1,186 @@
|
|||
import * as core from '@actions/core';
|
||||
import * as tc from '@actions/tool-cache';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import {
|
||||
extractJdkFile,
|
||||
getDownloadArchiveExtension,
|
||||
convertVersionToSemver
|
||||
} from '../../util';
|
||||
import {JavaBase} from '../base-installer';
|
||||
import {
|
||||
JavaDownloadRelease,
|
||||
JavaInstallerOptions,
|
||||
JavaInstallerResults
|
||||
} from '../base-models';
|
||||
import {
|
||||
ICorrettoAllAvailableVersions,
|
||||
ICorrettoAvailableVersions
|
||||
} from './models';
|
||||
|
||||
export class CorrettoDistribution extends JavaBase {
|
||||
constructor(installerOptions: JavaInstallerOptions) {
|
||||
super('Corretto', installerOptions);
|
||||
}
|
||||
|
||||
protected async downloadTool(
|
||||
javaRelease: JavaDownloadRelease
|
||||
): Promise<JavaInstallerResults> {
|
||||
core.info(
|
||||
`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`
|
||||
);
|
||||
const javaArchivePath = await tc.downloadTool(javaRelease.url);
|
||||
|
||||
core.info(`Extracting Java archive...`);
|
||||
|
||||
const extractedJavaPath = await extractJdkFile(
|
||||
javaArchivePath,
|
||||
getDownloadArchiveExtension()
|
||||
);
|
||||
|
||||
const archiveName = fs.readdirSync(extractedJavaPath)[0];
|
||||
const archivePath = path.join(extractedJavaPath, archiveName);
|
||||
const version = this.getToolcacheVersionName(javaRelease.version);
|
||||
|
||||
const javaPath = await tc.cacheDir(
|
||||
archivePath,
|
||||
this.toolcacheFolderName,
|
||||
version,
|
||||
this.architecture
|
||||
);
|
||||
|
||||
return {version: javaRelease.version, path: javaPath};
|
||||
}
|
||||
|
||||
protected async findPackageForDownload(
|
||||
version: string
|
||||
): Promise<JavaDownloadRelease> {
|
||||
if (!this.stable) {
|
||||
throw new Error('Early access versions are not supported');
|
||||
}
|
||||
if (version.includes('.')) {
|
||||
throw new Error('Only major versions are supported');
|
||||
}
|
||||
const availableVersions = await this.getAvailableVersions();
|
||||
const matchingVersions = availableVersions
|
||||
.filter(item => item.version == version)
|
||||
.map(item => {
|
||||
return {
|
||||
version: convertVersionToSemver(item.correttoVersion),
|
||||
url: item.downloadLink
|
||||
} as JavaDownloadRelease;
|
||||
});
|
||||
|
||||
const resolvedVersion =
|
||||
matchingVersions.length > 0 ? matchingVersions[0] : null;
|
||||
if (!resolvedVersion) {
|
||||
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 resolvedVersion;
|
||||
}
|
||||
|
||||
private async getAvailableVersions(): Promise<ICorrettoAvailableVersions[]> {
|
||||
const platform = this.getPlatformOption();
|
||||
const arch = this.distributionArchitecture();
|
||||
const imageType = this.packageType;
|
||||
|
||||
if (core.isDebug()) {
|
||||
console.time('Retrieving available versions for Coretto took'); // eslint-disable-line no-console
|
||||
}
|
||||
|
||||
const availableVersionsUrl =
|
||||
'https://corretto.github.io/corretto-downloads/latest_links/indexmap_with_checksum.json';
|
||||
const fetchCurrentVersions =
|
||||
await this.http.getJson<ICorrettoAllAvailableVersions>(
|
||||
availableVersionsUrl
|
||||
);
|
||||
const fetchedCurrentVersions = fetchCurrentVersions.result;
|
||||
if (!fetchedCurrentVersions) {
|
||||
throw Error(
|
||||
`Could not fetch latest corretto versions from ${availableVersionsUrl}`
|
||||
);
|
||||
}
|
||||
|
||||
const eligibleVersions =
|
||||
fetchedCurrentVersions?.[platform]?.[arch]?.[imageType];
|
||||
const availableVersions =
|
||||
this.getAvailableVersionsForPlatform(eligibleVersions);
|
||||
|
||||
if (core.isDebug()) {
|
||||
core.startGroup('Print information about available versions');
|
||||
console.timeEnd('Retrieving available versions for Coretto took'); // eslint-disable-line no-console
|
||||
core.debug(`Available versions: [${availableVersions.length}]`);
|
||||
core.debug(
|
||||
availableVersions
|
||||
.map(item => `${item.version}: ${item.correttoVersion}`)
|
||||
.join(', ')
|
||||
);
|
||||
core.endGroup();
|
||||
}
|
||||
|
||||
return availableVersions;
|
||||
}
|
||||
|
||||
private getAvailableVersionsForPlatform(
|
||||
eligibleVersions:
|
||||
| ICorrettoAllAvailableVersions['os']['arch']['imageType']
|
||||
| undefined
|
||||
): ICorrettoAvailableVersions[] {
|
||||
const availableVersions: ICorrettoAvailableVersions[] = [];
|
||||
|
||||
for (const version in eligibleVersions) {
|
||||
const availableVersion = eligibleVersions[version];
|
||||
for (const fileType in availableVersion) {
|
||||
const skipNonExtractableBinaries =
|
||||
fileType != getDownloadArchiveExtension();
|
||||
if (skipNonExtractableBinaries) {
|
||||
continue;
|
||||
}
|
||||
const availableVersionDetails = availableVersion[fileType];
|
||||
const correttoVersion = this.getCorrettoVersion(
|
||||
availableVersionDetails.resource
|
||||
);
|
||||
|
||||
availableVersions.push({
|
||||
checksum: availableVersionDetails.checksum,
|
||||
checksum_sha256: availableVersionDetails.checksum_sha256,
|
||||
fileType,
|
||||
resource: availableVersionDetails.resource,
|
||||
downloadLink: `https://corretto.aws${availableVersionDetails.resource}`,
|
||||
version: version,
|
||||
correttoVersion
|
||||
});
|
||||
}
|
||||
}
|
||||
return availableVersions;
|
||||
}
|
||||
|
||||
private getPlatformOption(): string {
|
||||
// Corretto has its own platform names so we need to map them
|
||||
switch (process.platform) {
|
||||
case 'darwin':
|
||||
return 'macos';
|
||||
case 'win32':
|
||||
return 'windows';
|
||||
default:
|
||||
return process.platform;
|
||||
}
|
||||
}
|
||||
|
||||
private getCorrettoVersion(resource: string): string {
|
||||
const regex = /(\d+.+)\//;
|
||||
const match = regex.exec(resource);
|
||||
if (match === null) {
|
||||
throw Error(`Could not parse corretto version from ${resource}`);
|
||||
}
|
||||
return match[1];
|
||||
}
|
||||
}
|
25
src/distributions/corretto/models.ts
Normal file
25
src/distributions/corretto/models.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
export interface ICorrettoAllAvailableVersions {
|
||||
[os: string]: {
|
||||
[arch: string]: {
|
||||
[distributionType: string]: {
|
||||
[version: string]: {
|
||||
[fileType: string]: {
|
||||
checksum: string;
|
||||
checksum_sha256: string;
|
||||
resource: string;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export interface ICorrettoAvailableVersions {
|
||||
version: string;
|
||||
fileType: string;
|
||||
checksum: string;
|
||||
checksum_sha256: string;
|
||||
resource: string;
|
||||
downloadLink: string;
|
||||
correttoVersion: string;
|
||||
}
|
|
@ -1,11 +1,14 @@
|
|||
import { JavaBase } from './base-installer';
|
||||
import { JavaInstallerOptions } from './base-models';
|
||||
import { LocalDistribution } from './local/installer';
|
||||
import { ZuluDistribution } from './zulu/installer';
|
||||
import { AdoptDistribution, AdoptImplementation } from './adopt/installer';
|
||||
import { TemurinDistribution, TemurinImplementation } from './temurin/installer';
|
||||
import { LibericaDistributions } from './liberica/installer';
|
||||
import { MicrosoftDistributions } from './microsoft/installer';
|
||||
import {JavaBase} from './base-installer';
|
||||
import {JavaInstallerOptions} from './base-models';
|
||||
import {LocalDistribution} from './local/installer';
|
||||
import {ZuluDistribution} from './zulu/installer';
|
||||
import {AdoptDistribution, AdoptImplementation} from './adopt/installer';
|
||||
import {TemurinDistribution, TemurinImplementation} from './temurin/installer';
|
||||
import {LibericaDistributions} from './liberica/installer';
|
||||
import {MicrosoftDistributions} from './microsoft/installer';
|
||||
import {SemeruDistribution} from './semeru/installer';
|
||||
import {CorrettoDistribution} from './corretto/installer';
|
||||
import {OracleDistribution} from './oracle/installer';
|
||||
|
||||
enum JavaDistribution {
|
||||
Adopt = 'adopt',
|
||||
|
@ -15,7 +18,10 @@ enum JavaDistribution {
|
|||
Zulu = 'zulu',
|
||||
Liberica = 'liberica',
|
||||
JdkFile = 'jdkfile',
|
||||
Microsoft = 'microsoft'
|
||||
Microsoft = 'microsoft',
|
||||
Semeru = 'semeru',
|
||||
Corretto = 'corretto',
|
||||
Oracle = 'oracle'
|
||||
}
|
||||
|
||||
export function getJavaDistribution(
|
||||
|
@ -28,17 +34,32 @@ export function getJavaDistribution(
|
|||
return new LocalDistribution(installerOptions, jdkFile);
|
||||
case JavaDistribution.Adopt:
|
||||
case JavaDistribution.AdoptHotspot:
|
||||
return new AdoptDistribution(installerOptions, AdoptImplementation.Hotspot);
|
||||
return new AdoptDistribution(
|
||||
installerOptions,
|
||||
AdoptImplementation.Hotspot
|
||||
);
|
||||
case JavaDistribution.AdoptOpenJ9:
|
||||
return new AdoptDistribution(installerOptions, AdoptImplementation.OpenJ9);
|
||||
return new AdoptDistribution(
|
||||
installerOptions,
|
||||
AdoptImplementation.OpenJ9
|
||||
);
|
||||
case JavaDistribution.Temurin:
|
||||
return new TemurinDistribution(installerOptions, TemurinImplementation.Hotspot);
|
||||
return new TemurinDistribution(
|
||||
installerOptions,
|
||||
TemurinImplementation.Hotspot
|
||||
);
|
||||
case JavaDistribution.Zulu:
|
||||
return new ZuluDistribution(installerOptions);
|
||||
case JavaDistribution.Liberica:
|
||||
return new LibericaDistributions(installerOptions);
|
||||
case JavaDistribution.Microsoft:
|
||||
return new MicrosoftDistributions(installerOptions);
|
||||
case JavaDistribution.Semeru:
|
||||
return new SemeruDistribution(installerOptions);
|
||||
case JavaDistribution.Corretto:
|
||||
return new CorrettoDistribution(installerOptions);
|
||||
case JavaDistribution.Oracle:
|
||||
return new OracleDistribution(installerOptions);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -1,23 +1,33 @@
|
|||
import { JavaBase } from '../base-installer';
|
||||
import { JavaDownloadRelease, JavaInstallerOptions, JavaInstallerResults } from '../base-models';
|
||||
import {JavaBase} from '../base-installer';
|
||||
import {
|
||||
JavaDownloadRelease,
|
||||
JavaInstallerOptions,
|
||||
JavaInstallerResults
|
||||
} from '../base-models';
|
||||
import semver from 'semver';
|
||||
import { extractJdkFile, getDownloadArchiveExtension, isVersionSatisfies } from '../../util';
|
||||
import {
|
||||
extractJdkFile,
|
||||
getDownloadArchiveExtension,
|
||||
isVersionSatisfies
|
||||
} from '../../util';
|
||||
import * as core from '@actions/core';
|
||||
import { ArchitectureOptions, LibericaVersion, OsVersions } from './models';
|
||||
import {ArchitectureOptions, LibericaVersion, OsVersions} from './models';
|
||||
import * as tc from '@actions/tool-cache';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
const supportedPlatform = `'linux', 'linux-musl', 'macos', 'solaris', 'windows'`;
|
||||
|
||||
const supportedArchitecture = `'x86', 'x64', 'armv7', 'aarch64', 'ppc64le'`;
|
||||
const supportedArchitectures = `'x86', 'x64', 'armv7', 'aarch64', 'ppc64le'`;
|
||||
|
||||
export class LibericaDistributions extends JavaBase {
|
||||
constructor(installerOptions: JavaInstallerOptions) {
|
||||
super('Liberica', installerOptions);
|
||||
}
|
||||
|
||||
protected async downloadTool(javaRelease: JavaDownloadRelease): Promise<JavaInstallerResults> {
|
||||
protected async downloadTool(
|
||||
javaRelease: JavaDownloadRelease
|
||||
): Promise<JavaInstallerResults> {
|
||||
core.info(
|
||||
`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`
|
||||
);
|
||||
|
@ -37,10 +47,12 @@ export class LibericaDistributions extends JavaBase {
|
|||
this.architecture
|
||||
);
|
||||
|
||||
return { version: javaRelease.version, path: javaPath };
|
||||
return {version: javaRelease.version, path: javaPath};
|
||||
}
|
||||
|
||||
protected async findPackageForDownload(range: string): Promise<JavaDownloadRelease> {
|
||||
protected async findPackageForDownload(
|
||||
range: string
|
||||
): Promise<JavaDownloadRelease> {
|
||||
const availableVersionsRaw = await this.getAvailableVersions();
|
||||
|
||||
const availableVersions = availableVersionsRaw.map(item => ({
|
||||
|
@ -53,7 +65,9 @@ export class LibericaDistributions extends JavaBase {
|
|||
.sort((a, b) => -semver.compareBuild(a.version, b.version))[0];
|
||||
|
||||
if (!satisfiedVersion) {
|
||||
const availableOptions = availableVersions.map(item => item.version).join(', ');
|
||||
const availableOptions = availableVersions
|
||||
.map(item => item.version)
|
||||
.join(', ');
|
||||
const availableOptionsMessage = availableOptions
|
||||
? `\nAvailable versions: ${availableOptions}`
|
||||
: '';
|
||||
|
@ -66,20 +80,21 @@ export class LibericaDistributions extends JavaBase {
|
|||
}
|
||||
|
||||
private async getAvailableVersions(): Promise<LibericaVersion[]> {
|
||||
console.time('liberica-retrieve-available-versions');
|
||||
if (core.isDebug()) {
|
||||
console.time('Retrieving available versions for Liberica took'); // eslint-disable-line no-console
|
||||
}
|
||||
const url = this.prepareAvailableVersionsUrl();
|
||||
|
||||
if (core.isDebug()) {
|
||||
core.debug(`Gathering available versions from '${url}'`);
|
||||
}
|
||||
core.debug(`Gathering available versions from '${url}'`);
|
||||
|
||||
const availableVersions = (await this.http.getJson<LibericaVersion[]>(url)).result ?? [];
|
||||
const availableVersions =
|
||||
(await this.http.getJson<LibericaVersion[]>(url)).result ?? [];
|
||||
|
||||
if (core.isDebug()) {
|
||||
core.startGroup('Print information about available versions');
|
||||
console.timeEnd('liberica-retrieve-available-versions');
|
||||
console.log(`Available versions: [${availableVersions.length}]`);
|
||||
console.log(availableVersions.map(item => item.version));
|
||||
console.timeEnd('Retrieving available versions for Liberica took'); // eslint-disable-line no-console
|
||||
core.debug(`Available versions: [${availableVersions.length}]`);
|
||||
core.debug(availableVersions.map(item => item.version).join(', '));
|
||||
core.endGroup();
|
||||
}
|
||||
|
||||
|
@ -93,7 +108,8 @@ export class LibericaDistributions extends JavaBase {
|
|||
...this.getArchitectureOptions(),
|
||||
'build-type': this.stable ? 'all' : 'ea',
|
||||
'installation-type': 'archive',
|
||||
fields: 'downloadUrl,version,featureVersion,interimVersion,updateVersion,buildVersion'
|
||||
fields:
|
||||
'downloadUrl,version,featureVersion,interimVersion,updateVersion,buildVersion'
|
||||
};
|
||||
|
||||
const searchParams = new URLSearchParams(urlOptions).toString();
|
||||
|
@ -110,25 +126,28 @@ export class LibericaDistributions extends JavaBase {
|
|||
}
|
||||
|
||||
private getArchitectureOptions(): ArchitectureOptions {
|
||||
switch (this.architecture) {
|
||||
const arch = this.distributionArchitecture();
|
||||
switch (arch) {
|
||||
case 'x86':
|
||||
return { bitness: '32', arch: 'x86' };
|
||||
return {bitness: '32', arch: 'x86'};
|
||||
case 'x64':
|
||||
return { bitness: '64', arch: 'x86' };
|
||||
return {bitness: '64', arch: 'x86'};
|
||||
case 'armv7':
|
||||
return { bitness: '32', arch: 'arm' };
|
||||
return {bitness: '32', arch: 'arm'};
|
||||
case 'aarch64':
|
||||
return { bitness: '64', arch: 'arm' };
|
||||
return {bitness: '64', arch: 'arm'};
|
||||
case 'ppc64le':
|
||||
return { bitness: '64', arch: 'ppc' };
|
||||
return {bitness: '64', arch: 'ppc'};
|
||||
default:
|
||||
throw new Error(
|
||||
`Architecture '${this.architecture}' is not supported. Supported architectures: ${supportedArchitecture}`
|
||||
`Architecture '${this.architecture}' is not supported. Supported architectures: ${supportedArchitectures}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private getPlatformOption(platform: NodeJS.Platform = process.platform): OsVersions {
|
||||
private getPlatformOption(
|
||||
platform: NodeJS.Platform = process.platform
|
||||
): OsVersions {
|
||||
switch (platform) {
|
||||
case 'darwin':
|
||||
return 'macos';
|
||||
|
@ -147,11 +166,24 @@ export class LibericaDistributions extends JavaBase {
|
|||
}
|
||||
|
||||
private convertVersionToSemver(version: LibericaVersion): string {
|
||||
let { buildVersion, featureVersion, interimVersion, updateVersion } = version;
|
||||
const mainVersion = [featureVersion, interimVersion, updateVersion].join('.');
|
||||
const {buildVersion, featureVersion, interimVersion, updateVersion} =
|
||||
version;
|
||||
const mainVersion = [featureVersion, interimVersion, updateVersion].join(
|
||||
'.'
|
||||
);
|
||||
if (buildVersion != 0) {
|
||||
return `${mainVersion}+${buildVersion}`;
|
||||
}
|
||||
return mainVersion;
|
||||
}
|
||||
|
||||
protected distributionArchitecture(): string {
|
||||
const arch = super.distributionArchitecture();
|
||||
switch (arch) {
|
||||
case 'arm':
|
||||
return 'armv7';
|
||||
default:
|
||||
return arch;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,12 @@
|
|||
export type Bitness = '32' | '64';
|
||||
export type ArchType = 'arm' | 'ppc' | 'sparc' | 'x86';
|
||||
|
||||
export type OsVersions = 'linux' | 'linux-musl' | 'macos' | 'solaris' | 'windows';
|
||||
export type OsVersions =
|
||||
| 'linux'
|
||||
| 'linux-musl'
|
||||
| 'macos'
|
||||
| 'solaris'
|
||||
| 'windows';
|
||||
|
||||
export interface ArchitectureOptions {
|
||||
bitness: Bitness;
|
||||
|
|
|
@ -3,15 +3,21 @@ 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';
|
||||
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) {
|
||||
constructor(
|
||||
installerOptions: JavaInstallerOptions,
|
||||
private jdkFile?: string
|
||||
) {
|
||||
super('jdkfile', installerOptions);
|
||||
}
|
||||
|
||||
|
@ -21,7 +27,9 @@ export class LocalDistribution extends JavaBase {
|
|||
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...`);
|
||||
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");
|
||||
}
|
||||
|
@ -39,38 +47,47 @@ export class LocalDistribution extends JavaBase {
|
|||
const archivePath = path.join(extractedJavaPath, archiveName);
|
||||
const javaVersion = this.version;
|
||||
|
||||
let javaPath = await tc.cacheDir(
|
||||
const 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
|
||||
};
|
||||
}
|
||||
|
||||
// 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 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 findPackageForDownload(
|
||||
version: string // eslint-disable-line @typescript-eslint/no-unused-vars
|
||||
): 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');
|
||||
protected async downloadTool(
|
||||
javaRelease: JavaDownloadRelease // eslint-disable-line @typescript-eslint/no-unused-vars
|
||||
): Promise<JavaInstallerResults> {
|
||||
throw new Error(
|
||||
'This method should not be implemented in local file provider'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,19 +1,25 @@
|
|||
import { JavaBase } from '../base-installer';
|
||||
import { JavaDownloadRelease, JavaInstallerOptions, JavaInstallerResults } from '../base-models';
|
||||
import semver from 'semver';
|
||||
import { extractJdkFile, getDownloadArchiveExtension, isVersionSatisfies } from '../../util';
|
||||
import {JavaBase} from '../base-installer';
|
||||
import {
|
||||
JavaDownloadRelease,
|
||||
JavaInstallerOptions,
|
||||
JavaInstallerResults
|
||||
} from '../base-models';
|
||||
import {extractJdkFile, getDownloadArchiveExtension} from '../../util';
|
||||
import * as core from '@actions/core';
|
||||
import { MicrosoftVersion, PlatformOptions } from './models';
|
||||
import * as tc from '@actions/tool-cache';
|
||||
import {OutgoingHttpHeaders} from 'http';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import {ITypedResponse} from '@actions/http-client/interfaces';
|
||||
|
||||
export class MicrosoftDistributions extends JavaBase {
|
||||
constructor(installerOptions: JavaInstallerOptions) {
|
||||
super('Microsoft', installerOptions);
|
||||
}
|
||||
|
||||
protected async downloadTool(javaRelease: JavaDownloadRelease): Promise<JavaInstallerResults> {
|
||||
protected async downloadTool(
|
||||
javaRelease: JavaDownloadRelease
|
||||
): Promise<JavaInstallerResults> {
|
||||
core.info(
|
||||
`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`
|
||||
);
|
||||
|
@ -33,11 +39,14 @@ export class MicrosoftDistributions extends JavaBase {
|
|||
this.architecture
|
||||
);
|
||||
|
||||
return { version: javaRelease.version, path: javaPath };
|
||||
return {version: javaRelease.version, path: javaPath};
|
||||
}
|
||||
|
||||
protected async findPackageForDownload(range: string): Promise<JavaDownloadRelease> {
|
||||
if (this.architecture !== 'x64' && this.architecture !== 'aarch64') {
|
||||
protected async findPackageForDownload(
|
||||
range: string
|
||||
): Promise<JavaDownloadRelease> {
|
||||
const arch = this.distributionArchitecture();
|
||||
if (arch !== 'x64' && arch !== 'aarch64') {
|
||||
throw new Error(`Unsupported architecture: ${this.architecture}`);
|
||||
}
|
||||
|
||||
|
@ -46,79 +55,82 @@ export class MicrosoftDistributions extends JavaBase {
|
|||
}
|
||||
|
||||
if (this.packageType !== 'jdk') {
|
||||
throw new Error('Microsoft Build of OpenJDK provides only the `jdk` package type');
|
||||
}
|
||||
|
||||
const availableVersionsRaw = await this.getAvailableVersions();
|
||||
|
||||
const opts = this.getPlatformOption();
|
||||
const availableVersions = availableVersionsRaw.map(item => ({
|
||||
url: `https://aka.ms/download-jdk/microsoft-jdk-${item.version.join('.')}-${opts.os}-${
|
||||
this.architecture
|
||||
}.${opts.archive}`,
|
||||
version: this.convertVersionToSemver(item)
|
||||
}));
|
||||
|
||||
const satisfiedVersion = availableVersions
|
||||
.filter(item => isVersionSatisfies(range, item.version))
|
||||
.sort((a, b) => -semver.compareBuild(a.version, b.version))[0];
|
||||
|
||||
if (!satisfiedVersion) {
|
||||
const availableOptions = availableVersions.map(item => item.version).join(', ');
|
||||
const availableOptionsMessage = availableOptions
|
||||
? `\nAvailable versions: ${availableOptions}`
|
||||
: '';
|
||||
throw new Error(
|
||||
`Could not find satisfied version for SemVer ${range}. ${availableOptionsMessage}`
|
||||
'Microsoft Build of OpenJDK provides only the `jdk` package type'
|
||||
);
|
||||
}
|
||||
|
||||
return satisfiedVersion;
|
||||
const manifest = await this.getAvailableVersions();
|
||||
|
||||
if (!manifest) {
|
||||
throw new Error('Could not load manifest for Microsoft Build of OpenJDK');
|
||||
}
|
||||
|
||||
const foundRelease = await tc.findFromManifest(range, true, manifest, arch);
|
||||
|
||||
if (!foundRelease) {
|
||||
throw new Error(
|
||||
`Could not find satisfied version for SemVer ${range}.\nAvailable versions: ${manifest
|
||||
.map(item => item.version)
|
||||
.join(', ')}`
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
url: foundRelease.files[0].download_url,
|
||||
version: foundRelease.version
|
||||
};
|
||||
}
|
||||
|
||||
private async getAvailableVersions(): Promise<MicrosoftVersion[]> {
|
||||
private async getAvailableVersions(): Promise<tc.IToolRelease[] | null> {
|
||||
// TODO get these dynamically!
|
||||
// We will need Microsoft to add an endpoint where we can query for versions.
|
||||
const jdkVersions = [
|
||||
{
|
||||
version: [17, 0, 1, 12, 1]
|
||||
},
|
||||
{
|
||||
version: [16, 0, 2, 7, 1]
|
||||
const token = core.getInput('token');
|
||||
const auth = !token ? undefined : `token ${token}`;
|
||||
const owner = 'actions';
|
||||
const repository = 'setup-java';
|
||||
const branch = 'main';
|
||||
const filePath =
|
||||
'src/distributions/microsoft/microsoft-openjdk-versions.json';
|
||||
|
||||
let releases: tc.IToolRelease[] | null = null;
|
||||
const fileUrl = `https://api.github.com/repos/${owner}/${repository}/contents/${filePath}?ref=${branch}`;
|
||||
|
||||
const headers: OutgoingHttpHeaders = {
|
||||
authorization: auth,
|
||||
accept: 'application/vnd.github.VERSION.raw'
|
||||
};
|
||||
|
||||
let response: ITypedResponse<tc.IToolRelease[]> | null = null;
|
||||
|
||||
if (core.isDebug()) {
|
||||
console.time('Retrieving available versions for Microsoft took'); // eslint-disable-line no-console
|
||||
}
|
||||
|
||||
try {
|
||||
response = await this.http.getJson<tc.IToolRelease[]>(fileUrl, headers);
|
||||
if (!response.result) {
|
||||
return null;
|
||||
}
|
||||
];
|
||||
|
||||
// M1 is only supported for Java 16 & 17
|
||||
if (process.platform !== 'darwin' || this.architecture !== 'aarch64') {
|
||||
jdkVersions.push({
|
||||
version: [11, 0, 13, 8, 1]
|
||||
});
|
||||
} catch (err) {
|
||||
core.debug(
|
||||
`Http request for microsoft-openjdk-versions.json failed with status code: ${response?.statusCode}`
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
return jdkVersions;
|
||||
}
|
||||
|
||||
private getPlatformOption(
|
||||
platform: NodeJS.Platform = process.platform /* for testing */
|
||||
): PlatformOptions {
|
||||
switch (platform) {
|
||||
case 'darwin':
|
||||
return { archive: 'tar.gz', os: 'macos' };
|
||||
case 'win32':
|
||||
return { archive: 'zip', os: 'windows' };
|
||||
case 'linux':
|
||||
return { archive: 'tar.gz', os: 'linux' };
|
||||
default:
|
||||
throw new Error(
|
||||
`Platform '${platform}' is not supported. Supported platforms: 'darwin', 'linux', 'win32'`
|
||||
);
|
||||
if (response.result) {
|
||||
releases = response.result;
|
||||
}
|
||||
}
|
||||
|
||||
private convertVersionToSemver(version: MicrosoftVersion): string {
|
||||
const major = version.version[0];
|
||||
const minor = version.version[1];
|
||||
const patch = version.version[2];
|
||||
return `${major}.${minor}.${patch}`;
|
||||
if (core.isDebug() && releases) {
|
||||
core.startGroup('Print information about available versions');
|
||||
console.timeEnd('Retrieving available versions for Microsoft took'); // eslint-disable-line no-console
|
||||
core.debug(`Available versions: [${releases.length}]`);
|
||||
core.debug(releases.map(item => item.version).join(', '));
|
||||
core.endGroup();
|
||||
}
|
||||
|
||||
return releases;
|
||||
}
|
||||
}
|
||||
|
|
477
src/distributions/microsoft/microsoft-openjdk-versions.json
Normal file
477
src/distributions/microsoft/microsoft-openjdk-versions.json
Normal file
|
@ -0,0 +1,477 @@
|
|||
[
|
||||
{
|
||||
"version": "17.0.7",
|
||||
"stable": true,
|
||||
"release_url": "https://aka.ms/download-jdk",
|
||||
"files": [
|
||||
{
|
||||
"filename": "microsoft-jdk-17.0.7-macos-x64.tar.gz",
|
||||
"arch": "x64",
|
||||
"platform": "darwin",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.7-macos-x64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-17.0.7-linux-x64.tar.gz",
|
||||
"arch": "x64",
|
||||
"platform": "linux",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.7-linux-x64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-17.0.7-windows-x64.zip",
|
||||
"arch": "x64",
|
||||
"platform": "win32",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.7-windows-x64.zip"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-17.0.7-macos-aarch64.tar.gz",
|
||||
"arch": "aarch64",
|
||||
"platform": "darwin",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.7-macos-aarch64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-17.0.7-linux-aarch64.tar.gz",
|
||||
"arch": "aarch64",
|
||||
"platform": "linux",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.7-linux-aarch64.tar.gz"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "17.0.6",
|
||||
"stable": true,
|
||||
"release_url": "https://aka.ms/download-jdk",
|
||||
"files": [
|
||||
{
|
||||
"filename": "microsoft-jdk-17.0.6-macos-x64.tar.gz",
|
||||
"arch": "x64",
|
||||
"platform": "darwin",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.6-macos-x64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-17.0.6-linux-x64.tar.gz",
|
||||
"arch": "x64",
|
||||
"platform": "linux",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.6-linux-x64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-17.0.6-windows-x64.zip",
|
||||
"arch": "x64",
|
||||
"platform": "win32",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.6-windows-x64.zip"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-17.0.6-macos-aarch64.tar.gz",
|
||||
"arch": "aarch64",
|
||||
"platform": "darwin",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.6-macos-aarch64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-17.0.6-linux-aarch64.tar.gz",
|
||||
"arch": "aarch64",
|
||||
"platform": "linux",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.6-linux-aarch64.tar.gz"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "17.0.5",
|
||||
"stable": true,
|
||||
"release_url": "https://aka.ms/download-jdk",
|
||||
"files": [
|
||||
{
|
||||
"filename": "microsoft-jdk-17.0.5-macos-x64.tar.gz",
|
||||
"arch": "x64",
|
||||
"platform": "darwin",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.5-macos-x64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-17.0.5-linux-x64.tar.gz",
|
||||
"arch": "x64",
|
||||
"platform": "linux",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.5-linux-x64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-17.0.5-windows-x64.zip",
|
||||
"arch": "x64",
|
||||
"platform": "win32",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.5-windows-x64.zip"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-17.0.5-macos-aarch64.tar.gz",
|
||||
"arch": "aarch64",
|
||||
"platform": "darwin",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.5-macos-aarch64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-17.0.5-linux-aarch64.tar.gz",
|
||||
"arch": "aarch64",
|
||||
"platform": "linux",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.5-linux-aarch64.tar.gz"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "17.0.4",
|
||||
"stable": true,
|
||||
"release_url": "https://aka.ms/download-jdk",
|
||||
"files": [
|
||||
{
|
||||
"filename": "microsoft-jdk-17.0.4-macos-x64.tar.gz",
|
||||
"arch": "x64",
|
||||
"platform": "darwin",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.4-macos-x64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-17.0.4-linux-x64.tar.gz",
|
||||
"arch": "x64",
|
||||
"platform": "linux",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.4-linux-x64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-17.0.4-windows-x64.zip",
|
||||
"arch": "x64",
|
||||
"platform": "win32",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.4-windows-x64.zip"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-17.0.4-macos-aarch64.tar.gz",
|
||||
"arch": "aarch64",
|
||||
"platform": "darwin",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.4-macos-aarch64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-17.0.4-linux-aarch64.tar.gz",
|
||||
"arch": "aarch64",
|
||||
"platform": "linux",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.4-linux-aarch64.tar.gz"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "17.0.3",
|
||||
"stable": true,
|
||||
"release_url": "https://aka.ms/download-jdk",
|
||||
"files": [
|
||||
{
|
||||
"filename": "microsoft-jdk-17.0.3-macos-x64.tar.gz",
|
||||
"arch": "x64",
|
||||
"platform": "darwin",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.3-macos-x64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-17.0.3-linux-x64.tar.gz",
|
||||
"arch": "x64",
|
||||
"platform": "linux",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.3-linux-x64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-17.0.3-windows-x64.zip",
|
||||
"arch": "x64",
|
||||
"platform": "win32",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.3-windows-x64.zip"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-17.0.3-macos-aarch64.tar.gz",
|
||||
"arch": "aarch64",
|
||||
"platform": "darwin",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.3-macos-aarch64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-17.0.3-linux-aarch64.tar.gz",
|
||||
"arch": "aarch64",
|
||||
"platform": "linux",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.3-linux-aarch64.tar.gz"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "17.0.1+12.1",
|
||||
"stable": true,
|
||||
"release_url": "https://aka.ms/download-jdk",
|
||||
"files": [
|
||||
{
|
||||
"filename": "microsoft-jdk-17.0.1.12.1-macos-x64.tar.gz",
|
||||
"arch": "x64",
|
||||
"platform": "darwin",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.1.12.1-macos-x64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-17.0.1.12.1-linux-x64.tar.gz",
|
||||
"arch": "x64",
|
||||
"platform": "linux",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.1.12.1-linux-x64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-17.0.1.12.1-windows-x64.zip",
|
||||
"arch": "x64",
|
||||
"platform": "win32",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.1.12.1-windows-x64.zip"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-17.0.1.12.1-macos-aarch64.tar.gz",
|
||||
"arch": "aarch64",
|
||||
"platform": "darwin",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.1.12.1-macos-aarch64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-17.0.1.12.1-linux-aarch64.tar.gz",
|
||||
"arch": "aarch64",
|
||||
"platform": "linux",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.1.12.1-linux-aarch64.tar.gz"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "16.0.2+7.1",
|
||||
"stable": true,
|
||||
"release_url": "https://aka.ms/download-jdk",
|
||||
"files": [
|
||||
{
|
||||
"filename": "microsoft-jdk-16.0.2.7.1-macos-x64.tar.gz",
|
||||
"arch": "x64",
|
||||
"platform": "darwin",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-16.0.2.7.1-macos-x64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-16.0.2.7.1-linux-x64.tar.gz",
|
||||
"arch": "x64",
|
||||
"platform": "linux",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-16.0.2.7.1-linux-x64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-16.0.2.7.1-windows-x64.zip",
|
||||
"arch": "x64",
|
||||
"platform": "win32",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-16.0.2.7.1-windows-x64.zip"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-16.0.2.7.1-macos-aarch64.tar.gz",
|
||||
"arch": "aarch64",
|
||||
"platform": "darwin",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-16.0.2.7.1-macos-aarch64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-16.0.2.7.1-linux-aarch64.tar.gz",
|
||||
"arch": "aarch64",
|
||||
"platform": "linux",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-16.0.2.7.1-linux-aarch64.tar.gz"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "11.0.19",
|
||||
"stable": true,
|
||||
"release_url": "https://aka.ms/download-jdk",
|
||||
"files": [
|
||||
{
|
||||
"filename": "microsoft-jdk-11.0.19-macos-x64.tar.gz",
|
||||
"arch": "x64",
|
||||
"platform": "darwin",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.19-macos-x64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-11.0.19-linux-x64.tar.gz",
|
||||
"arch": "x64",
|
||||
"platform": "linux",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.19-linux-x64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-11.0.19-windows-x64.zip",
|
||||
"arch": "x64",
|
||||
"platform": "win32",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.19-windows-x64.zip"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-11.0.19-macos-aarch64.tar.gz",
|
||||
"arch": "aarch64",
|
||||
"platform": "darwin",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.19-macos-aarch64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-11.0.19-linux-aarch64.tar.gz",
|
||||
"arch": "aarch64",
|
||||
"platform": "linux",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.19-linux-aarch64.tar.gz"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "11.0.18",
|
||||
"stable": true,
|
||||
"release_url": "https://aka.ms/download-jdk",
|
||||
"files": [
|
||||
{
|
||||
"filename": "microsoft-jdk-11.0.18-macos-x64.tar.gz",
|
||||
"arch": "x64",
|
||||
"platform": "darwin",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.18-macos-x64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-11.0.18-linux-x64.tar.gz",
|
||||
"arch": "x64",
|
||||
"platform": "linux",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.18-linux-x64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-11.0.18-windows-x64.zip",
|
||||
"arch": "x64",
|
||||
"platform": "win32",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.18-windows-x64.zip"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-11.0.18-macos-aarch64.tar.gz",
|
||||
"arch": "aarch64",
|
||||
"platform": "darwin",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.18-macos-aarch64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-11.0.18-linux-aarch64.tar.gz",
|
||||
"arch": "aarch64",
|
||||
"platform": "linux",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.18-linux-aarch64.tar.gz"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "11.0.17",
|
||||
"stable": true,
|
||||
"release_url": "https://aka.ms/download-jdk",
|
||||
"files": [
|
||||
{
|
||||
"filename": "microsoft-jdk-11.0.17-macos-x64.tar.gz",
|
||||
"arch": "x64",
|
||||
"platform": "darwin",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.17-macos-x64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-11.0.17-linux-x64.tar.gz",
|
||||
"arch": "x64",
|
||||
"platform": "linux",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.17-linux-x64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-11.0.17-windows-x64.zip",
|
||||
"arch": "x64",
|
||||
"platform": "win32",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.17-windows-x64.zip"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-11.0.17-macos-aarch64.tar.gz",
|
||||
"arch": "aarch64",
|
||||
"platform": "darwin",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.17-macos-aarch64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-11.0.17-linux-aarch64.tar.gz",
|
||||
"arch": "aarch64",
|
||||
"platform": "linux",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.17-linux-aarch64.tar.gz"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "11.0.16",
|
||||
"stable": true,
|
||||
"release_url": "https://aka.ms/download-jdk",
|
||||
"files": [
|
||||
{
|
||||
"filename": "microsoft-jdk-11.0.16-macos-x64.tar.gz",
|
||||
"arch": "x64",
|
||||
"platform": "darwin",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.16-macos-x64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-11.0.16-linux-x64.tar.gz",
|
||||
"arch": "x64",
|
||||
"platform": "linux",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.16-linux-x64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-11.0.16-windows-x64.zip",
|
||||
"arch": "x64",
|
||||
"platform": "win32",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.16-windows-x64.zip"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-11.0.16-macos-aarch64.tar.gz",
|
||||
"arch": "aarch64",
|
||||
"platform": "darwin",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.16-macos-aarch64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-11.0.16-linux-aarch64.tar.gz",
|
||||
"arch": "aarch64",
|
||||
"platform": "linux",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.16-linux-aarch64.tar.gz"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "11.0.15",
|
||||
"stable": true,
|
||||
"release_url": "https://aka.ms/download-jdk",
|
||||
"files": [
|
||||
{
|
||||
"filename": "microsoft-jdk-11.0.15-macos-x64.tar.gz",
|
||||
"arch": "x64",
|
||||
"platform": "darwin",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.15-macos-x64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-11.0.15-linux-x64.tar.gz",
|
||||
"arch": "x64",
|
||||
"platform": "linux",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.15-linux-x64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-11.0.15-windows-x64.zip",
|
||||
"arch": "x64",
|
||||
"platform": "win32",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.15-windows-x64.zip"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-11.0.15-macos-aarch64.tar.gz",
|
||||
"arch": "aarch64",
|
||||
"platform": "darwin",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.15-macos-aarch64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-11.0.15-linux-aarch64.tar.gz",
|
||||
"arch": "aarch64",
|
||||
"platform": "linux",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.15-linux-aarch64.tar.gz"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "11.0.13+8.1",
|
||||
"stable": true,
|
||||
"release_url": "https://aka.ms/download-jdk",
|
||||
"files": [
|
||||
{
|
||||
"filename": "microsoft-jdk-11.0.13.8.1-macos-x64.tar.gz",
|
||||
"arch": "x64",
|
||||
"platform": "darwin",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.13.8.1-macos-x64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-11.0.13.8.1-linux-x64.tar.gz",
|
||||
"arch": "x64",
|
||||
"platform": "linux",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.13.8.1-linux-x64.tar.gz"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-11.0.13.8.1-windows-x64.zip",
|
||||
"arch": "x64",
|
||||
"platform": "win32",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.13.8.1-windows-x64.zip"
|
||||
},
|
||||
{
|
||||
"filename": "microsoft-jdk-11.0.13.8.1-linux-aarch64.tar.gz",
|
||||
"arch": "aarch64",
|
||||
"platform": "linux",
|
||||
"download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.13.8.1-linux-aarch64.tar.gz"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
|
@ -1,12 +1,3 @@
|
|||
/* eslint @typescript-eslint/no-unused-vars: "off" -- There is a bug with this rule, it's not working properly with types */
|
||||
type OsVersions = 'linux' | 'macos' | 'windows';
|
||||
type ArchiveType = 'tar.gz' | 'zip';
|
||||
|
||||
export interface PlatformOptions {
|
||||
archive: ArchiveType;
|
||||
os: OsVersions;
|
||||
}
|
||||
|
||||
export interface MicrosoftVersion {
|
||||
downloadUrl?: string;
|
||||
version: Array<number>;
|
||||
}
|
||||
|
|
126
src/distributions/oracle/installer.ts
Normal file
126
src/distributions/oracle/installer.ts
Normal file
|
@ -0,0 +1,126 @@
|
|||
import * as core from '@actions/core';
|
||||
import * as tc from '@actions/tool-cache';
|
||||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
import {JavaBase} from '../base-installer';
|
||||
import {
|
||||
JavaDownloadRelease,
|
||||
JavaInstallerOptions,
|
||||
JavaInstallerResults
|
||||
} from '../base-models';
|
||||
import {extractJdkFile, getDownloadArchiveExtension} from '../../util';
|
||||
import {HttpCodes} from '@actions/http-client';
|
||||
|
||||
const ORACLE_DL_BASE = 'https://download.oracle.com/java';
|
||||
|
||||
export class OracleDistribution extends JavaBase {
|
||||
constructor(installerOptions: JavaInstallerOptions) {
|
||||
super('Oracle', installerOptions);
|
||||
}
|
||||
|
||||
protected async downloadTool(
|
||||
javaRelease: JavaDownloadRelease
|
||||
): Promise<JavaInstallerResults> {
|
||||
core.info(
|
||||
`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`
|
||||
);
|
||||
const javaArchivePath = await tc.downloadTool(javaRelease.url);
|
||||
|
||||
core.info(`Extracting Java archive...`);
|
||||
const extension = getDownloadArchiveExtension();
|
||||
|
||||
const extractedJavaPath = await extractJdkFile(javaArchivePath, extension);
|
||||
|
||||
const archiveName = fs.readdirSync(extractedJavaPath)[0];
|
||||
const archivePath = path.join(extractedJavaPath, archiveName);
|
||||
const version = this.getToolcacheVersionName(javaRelease.version);
|
||||
|
||||
const javaPath = await tc.cacheDir(
|
||||
archivePath,
|
||||
this.toolcacheFolderName,
|
||||
version,
|
||||
this.architecture
|
||||
);
|
||||
|
||||
return {version: javaRelease.version, path: javaPath};
|
||||
}
|
||||
|
||||
protected async findPackageForDownload(
|
||||
range: string
|
||||
): Promise<JavaDownloadRelease> {
|
||||
const arch = this.distributionArchitecture();
|
||||
if (arch !== 'x64' && arch !== 'aarch64') {
|
||||
throw new Error(`Unsupported architecture: ${this.architecture}`);
|
||||
}
|
||||
|
||||
if (!this.stable) {
|
||||
throw new Error('Early access versions are not supported');
|
||||
}
|
||||
|
||||
if (this.packageType !== 'jdk') {
|
||||
throw new Error('Oracle JDK provides only the `jdk` package type');
|
||||
}
|
||||
|
||||
const platform = this.getPlatform();
|
||||
const extension = getDownloadArchiveExtension();
|
||||
|
||||
const isOnlyMajorProvided = !range.includes('.');
|
||||
const major = isOnlyMajorProvided ? range : range.split('.')[0];
|
||||
|
||||
const possibleUrls: string[] = [];
|
||||
|
||||
/**
|
||||
* NOTE
|
||||
* If only major version was provided we will check it under /latest first
|
||||
* in order to retrieve the latest possible version if possible,
|
||||
* otherwise we will fall back to /archive where we are guaranteed to
|
||||
* find any version if it exists
|
||||
*/
|
||||
if (isOnlyMajorProvided) {
|
||||
possibleUrls.push(
|
||||
`${ORACLE_DL_BASE}/${major}/latest/jdk-${major}_${platform}-${arch}_bin.${extension}`
|
||||
);
|
||||
}
|
||||
|
||||
possibleUrls.push(
|
||||
`${ORACLE_DL_BASE}/${major}/archive/jdk-${range}_${platform}-${arch}_bin.${extension}`
|
||||
);
|
||||
|
||||
if (parseInt(major) < 17) {
|
||||
throw new Error('Oracle JDK is only supported for JDK 17 and later');
|
||||
}
|
||||
|
||||
for (const url of possibleUrls) {
|
||||
const response = await this.http.head(url);
|
||||
|
||||
if (response.message.statusCode === HttpCodes.OK) {
|
||||
return {url, version: range};
|
||||
}
|
||||
|
||||
if (response.message.statusCode !== HttpCodes.NotFound) {
|
||||
throw new Error(
|
||||
`Http request for Oracle JDK failed with status code: ${response.message.statusCode}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error(`Could not find Oracle JDK for SemVer ${range}`);
|
||||
}
|
||||
|
||||
public getPlatform(platform: NodeJS.Platform = process.platform): OsVersions {
|
||||
switch (platform) {
|
||||
case 'darwin':
|
||||
return 'macos';
|
||||
case 'win32':
|
||||
return 'windows';
|
||||
case 'linux':
|
||||
return 'linux';
|
||||
default:
|
||||
throw new Error(
|
||||
`Platform '${platform}' is not supported. Supported platforms: 'linux', 'macos', 'windows'`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
1
src/distributions/oracle/models.ts
Normal file
1
src/distributions/oracle/models.ts
Normal file
|
@ -0,0 +1 @@
|
|||
export type OsVersions = 'linux' | 'macos' | 'windows';
|
201
src/distributions/semeru/installer.ts
Normal file
201
src/distributions/semeru/installer.ts
Normal file
|
@ -0,0 +1,201 @@
|
|||
import {JavaBase} from '../base-installer';
|
||||
import {
|
||||
JavaDownloadRelease,
|
||||
JavaInstallerOptions,
|
||||
JavaInstallerResults
|
||||
} from '../base-models';
|
||||
import semver from 'semver';
|
||||
import {
|
||||
extractJdkFile,
|
||||
getDownloadArchiveExtension,
|
||||
isVersionSatisfies
|
||||
} from '../../util';
|
||||
import * as core from '@actions/core';
|
||||
import * as tc from '@actions/tool-cache';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import {ISemeruAvailableVersions} from './models';
|
||||
|
||||
const supportedArchitectures = [
|
||||
'x64',
|
||||
'x86',
|
||||
'ppc64le',
|
||||
'ppc64',
|
||||
's390x',
|
||||
'aarch64'
|
||||
];
|
||||
|
||||
export class SemeruDistribution extends JavaBase {
|
||||
constructor(installerOptions: JavaInstallerOptions) {
|
||||
super('IBM_Semeru', installerOptions);
|
||||
}
|
||||
|
||||
protected async findPackageForDownload(
|
||||
version: string
|
||||
): Promise<JavaDownloadRelease> {
|
||||
if (!supportedArchitectures.includes(this.architecture)) {
|
||||
throw new Error(
|
||||
`Unsupported architecture for IBM Semeru: ${
|
||||
this.architecture
|
||||
}, the following are supported: ${supportedArchitectures.join(', ')}`
|
||||
);
|
||||
}
|
||||
|
||||
if (!this.stable) {
|
||||
throw new Error(
|
||||
'IBM Semeru does not provide builds for early access versions'
|
||||
);
|
||||
}
|
||||
|
||||
if (this.packageType !== 'jdk' && this.packageType !== 'jre') {
|
||||
throw new Error('IBM Semeru only provide `jdk` and `jre` package types');
|
||||
}
|
||||
|
||||
const availableVersionsRaw = await this.getAvailableVersions();
|
||||
const availableVersionsWithBinaries = availableVersionsRaw
|
||||
.filter(item => item.binaries.length > 0)
|
||||
.map(item => {
|
||||
// normalize 17.0.0-beta+33.0.202107301459 to 17.0.0+33.0.202107301459 for earlier access versions
|
||||
const formattedVersion = this.stable
|
||||
? item.version_data.semver
|
||||
: item.version_data.semver.replace('-beta+', '+');
|
||||
return {
|
||||
version: formattedVersion,
|
||||
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> {
|
||||
core.info(
|
||||
`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`
|
||||
);
|
||||
const javaArchivePath = await tc.downloadTool(javaRelease.url);
|
||||
|
||||
core.info(`Extracting Java archive...`);
|
||||
const extension = getDownloadArchiveExtension();
|
||||
|
||||
const extractedJavaPath: string = await extractJdkFile(
|
||||
javaArchivePath,
|
||||
extension
|
||||
);
|
||||
|
||||
const archiveName = fs.readdirSync(extractedJavaPath)[0];
|
||||
const archivePath = path.join(extractedJavaPath, archiveName);
|
||||
const version = this.getToolcacheVersionName(javaRelease.version);
|
||||
|
||||
const javaPath: string = await tc.cacheDir(
|
||||
archivePath,
|
||||
this.toolcacheFolderName,
|
||||
version,
|
||||
this.architecture
|
||||
);
|
||||
|
||||
return {version: javaRelease.version, path: javaPath};
|
||||
}
|
||||
|
||||
protected get toolcacheFolderName(): string {
|
||||
return super.toolcacheFolderName;
|
||||
}
|
||||
|
||||
public async getAvailableVersions(): Promise<ISemeruAvailableVersions[]> {
|
||||
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';
|
||||
|
||||
if (core.isDebug()) {
|
||||
console.time('Retrieving available versions for Semeru took'); // eslint-disable-line no-console
|
||||
}
|
||||
|
||||
const baseRequestArguments = [
|
||||
`project=jdk`,
|
||||
'vendor=ibm',
|
||||
`heap_size=normal`,
|
||||
'sort_method=DEFAULT',
|
||||
'sort_order=DESC',
|
||||
`os=${platform}`,
|
||||
`architecture=${arch}`,
|
||||
`image_type=${imageType}`,
|
||||
`release_type=${releaseType}`,
|
||||
`jvm_impl=openj9`
|
||||
].join('&');
|
||||
|
||||
// need to iterate through all pages to retrieve the list of all versions
|
||||
// Adoptium API doesn't provide way to retrieve the count of pages to iterate so infinity loop
|
||||
let page_index = 0;
|
||||
const availableVersions: ISemeruAvailableVersions[] = [];
|
||||
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<ISemeruAvailableVersions[]>(
|
||||
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('Retrieving available versions for Semeru took'); // eslint-disable-line no-console
|
||||
core.debug(`Available versions: [${availableVersions.length}]`);
|
||||
core.debug(
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
36
src/distributions/semeru/models.ts
Normal file
36
src/distributions/semeru/models.ts
Normal file
|
@ -0,0 +1,36 @@
|
|||
export interface ISemeruAvailableVersions {
|
||||
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;
|
||||
};
|
||||
}
|
|
@ -5,10 +5,18 @@ import fs from 'fs';
|
|||
import path from 'path';
|
||||
import semver from 'semver';
|
||||
|
||||
import { JavaBase } from '../base-installer';
|
||||
import { ITemurinAvailableVersions } from './models';
|
||||
import { JavaDownloadRelease, JavaInstallerOptions, JavaInstallerResults } from '../base-models';
|
||||
import { extractJdkFile, getDownloadArchiveExtension, isVersionSatisfies } from '../../util';
|
||||
import {JavaBase} from '../base-installer';
|
||||
import {ITemurinAvailableVersions} from './models';
|
||||
import {
|
||||
JavaDownloadRelease,
|
||||
JavaInstallerOptions,
|
||||
JavaInstallerResults
|
||||
} from '../base-models';
|
||||
import {
|
||||
extractJdkFile,
|
||||
getDownloadArchiveExtension,
|
||||
isVersionSatisfies
|
||||
} from '../../util';
|
||||
|
||||
export enum TemurinImplementation {
|
||||
Hotspot = 'Hotspot'
|
||||
|
@ -22,7 +30,9 @@ export class TemurinDistribution extends JavaBase {
|
|||
super(`Temurin-${jvmImpl}`, installerOptions);
|
||||
}
|
||||
|
||||
protected async findPackageForDownload(version: string): Promise<JavaDownloadRelease> {
|
||||
protected async findPackageForDownload(
|
||||
version: string
|
||||
): Promise<JavaDownloadRelease> {
|
||||
const availableVersionsRaw = await this.getAvailableVersions();
|
||||
const availableVersionsWithBinaries = availableVersionsRaw
|
||||
.filter(item => item.binaries.length > 0)
|
||||
|
@ -43,9 +53,12 @@ export class TemurinDistribution extends JavaBase {
|
|||
return -semver.compareBuild(a.version, b.version);
|
||||
});
|
||||
|
||||
const resolvedFullVersion = satisfiedVersions.length > 0 ? satisfiedVersions[0] : null;
|
||||
const resolvedFullVersion =
|
||||
satisfiedVersions.length > 0 ? satisfiedVersions[0] : null;
|
||||
if (!resolvedFullVersion) {
|
||||
const availableOptions = availableVersionsWithBinaries.map(item => item.version).join(', ');
|
||||
const availableOptions = availableVersionsWithBinaries
|
||||
.map(item => item.version)
|
||||
.join(', ');
|
||||
const availableOptionsMessage = availableOptions
|
||||
? `\nAvailable versions: ${availableOptions}`
|
||||
: '';
|
||||
|
@ -57,27 +70,31 @@ export class TemurinDistribution extends JavaBase {
|
|||
return resolvedFullVersion;
|
||||
}
|
||||
|
||||
protected async downloadTool(javaRelease: JavaDownloadRelease): Promise<JavaInstallerResults> {
|
||||
let javaPath: string;
|
||||
let extractedJavaPath: string;
|
||||
|
||||
protected async downloadTool(
|
||||
javaRelease: JavaDownloadRelease
|
||||
): Promise<JavaInstallerResults> {
|
||||
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();
|
||||
const extension = getDownloadArchiveExtension();
|
||||
|
||||
extractedJavaPath = await extractJdkFile(javaArchivePath, extension);
|
||||
const 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);
|
||||
const javaPath = await tc.cacheDir(
|
||||
archivePath,
|
||||
this.toolcacheFolderName,
|
||||
version,
|
||||
this.architecture
|
||||
);
|
||||
|
||||
return { version: javaRelease.version, path: javaPath };
|
||||
return {version: javaRelease.version, path: javaPath};
|
||||
}
|
||||
|
||||
protected get toolcacheFolderName(): string {
|
||||
|
@ -86,12 +103,14 @@ export class TemurinDistribution extends JavaBase {
|
|||
|
||||
private async getAvailableVersions(): Promise<ITemurinAvailableVersions[]> {
|
||||
const platform = this.getPlatformOption();
|
||||
const arch = this.architecture;
|
||||
const arch = this.distributionArchitecture();
|
||||
const imageType = this.packageType;
|
||||
const versionRange = encodeURI('[1.0,100.0]'); // retrieve all available versions
|
||||
const releaseType = this.stable ? 'ga' : 'ea';
|
||||
|
||||
console.time('temurin-retrieve-available-versions');
|
||||
if (core.isDebug()) {
|
||||
console.time('Retrieving available versions for Temurin took'); // eslint-disable-line no-console
|
||||
}
|
||||
|
||||
const baseRequestArguments = [
|
||||
`project=jdk`,
|
||||
|
@ -115,11 +134,15 @@ export class TemurinDistribution extends JavaBase {
|
|||
const availableVersionsUrl = `https://api.adoptium.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}'`);
|
||||
core.debug(
|
||||
`Gathering available versions from '${availableVersionsUrl}'`
|
||||
);
|
||||
}
|
||||
|
||||
const paginationPage = (
|
||||
await this.http.getJson<ITemurinAvailableVersions[]>(availableVersionsUrl)
|
||||
await this.http.getJson<ITemurinAvailableVersions[]>(
|
||||
availableVersionsUrl
|
||||
)
|
||||
).result;
|
||||
if (paginationPage === null || paginationPage.length === 0) {
|
||||
// break infinity loop because we have reached end of pagination
|
||||
|
@ -132,9 +155,11 @@ export class TemurinDistribution extends JavaBase {
|
|||
|
||||
if (core.isDebug()) {
|
||||
core.startGroup('Print information about available versions');
|
||||
console.timeEnd('temurin-retrieve-available-versions');
|
||||
console.log(`Available versions: [${availableVersions.length}]`);
|
||||
console.log(availableVersions.map(item => item.version_data.semver).join(', '));
|
||||
console.timeEnd('Retrieving available versions for Temurin took'); // eslint-disable-line no-console
|
||||
core.debug(`Available versions: [${availableVersions.length}]`);
|
||||
core.debug(
|
||||
availableVersions.map(item => item.version_data.semver).join(', ')
|
||||
);
|
||||
core.endGroup();
|
||||
}
|
||||
|
||||
|
|
|
@ -5,23 +5,34 @@ 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';
|
||||
import {JavaBase} from '../base-installer';
|
||||
import {IZuluVersions} from './models';
|
||||
import {
|
||||
extractJdkFile,
|
||||
getDownloadArchiveExtension,
|
||||
convertVersionToSemver,
|
||||
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> {
|
||||
protected async findPackageForDownload(
|
||||
version: string
|
||||
): Promise<JavaDownloadRelease> {
|
||||
const availableVersionsRaw = await this.getAvailableVersions();
|
||||
const availableVersions = availableVersionsRaw.map(item => {
|
||||
return {
|
||||
version: this.convertVersionToSemver(item.jdk_version),
|
||||
version: convertVersionToSemver(item.jdk_version),
|
||||
url: item.url,
|
||||
zuluVersion: this.convertVersionToSemver(item.zulu_version)
|
||||
zuluVersion: convertVersionToSemver(item.zulu_version)
|
||||
};
|
||||
});
|
||||
|
||||
|
@ -42,9 +53,12 @@ export class ZuluDistribution extends JavaBase {
|
|||
} as JavaDownloadRelease;
|
||||
});
|
||||
|
||||
const resolvedFullVersion = satisfiedVersions.length > 0 ? satisfiedVersions[0] : null;
|
||||
const resolvedFullVersion =
|
||||
satisfiedVersions.length > 0 ? satisfiedVersions[0] : null;
|
||||
if (!resolvedFullVersion) {
|
||||
const availableOptions = availableVersions.map(item => item.version).join(', ');
|
||||
const availableOptions = availableVersions
|
||||
.map(item => item.version)
|
||||
.join(', ');
|
||||
const availableOptionsMessage = availableOptions
|
||||
? `\nAvailable versions: ${availableOptions}`
|
||||
: '';
|
||||
|
@ -56,18 +70,18 @@ export class ZuluDistribution extends JavaBase {
|
|||
return resolvedFullVersion;
|
||||
}
|
||||
|
||||
protected async downloadTool(javaRelease: JavaDownloadRelease): Promise<JavaInstallerResults> {
|
||||
let extractedJavaPath: string;
|
||||
|
||||
protected async downloadTool(
|
||||
javaRelease: JavaDownloadRelease
|
||||
): Promise<JavaInstallerResults> {
|
||||
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();
|
||||
const extension = getDownloadArchiveExtension();
|
||||
|
||||
extractedJavaPath = await extractJdkFile(javaArchivePath, extension);
|
||||
const extractedJavaPath = await extractJdkFile(javaArchivePath, extension);
|
||||
|
||||
const archiveName = fs.readdirSync(extractedJavaPath)[0];
|
||||
const archivePath = path.join(extractedJavaPath, archiveName);
|
||||
|
@ -79,18 +93,21 @@ export class ZuluDistribution extends JavaBase {
|
|||
this.architecture
|
||||
);
|
||||
|
||||
return { version: javaRelease.version, path: javaPath };
|
||||
return {version: javaRelease.version, path: javaPath};
|
||||
}
|
||||
|
||||
private async getAvailableVersions(): Promise<IZuluVersions[]> {
|
||||
const { arch, hw_bitness, abi } = this.getArchitectureOptions();
|
||||
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');
|
||||
if (core.isDebug()) {
|
||||
console.time('Retrieving available versions for Zulu took'); // eslint-disable-line no-console
|
||||
}
|
||||
|
||||
const requestArguments = [
|
||||
`os=${platform}`,
|
||||
`ext=${extension}`,
|
||||
|
@ -106,18 +123,20 @@ export class ZuluDistribution extends JavaBase {
|
|||
.join('&');
|
||||
|
||||
const availableVersionsUrl = `https://api.azul.com/zulu/download/community/v1.0/bundles/?${requestArguments}`;
|
||||
if (core.isDebug()) {
|
||||
core.debug(`Gathering available versions from '${availableVersionsUrl}'`);
|
||||
}
|
||||
|
||||
core.debug(`Gathering available versions from '${availableVersionsUrl}'`);
|
||||
|
||||
const availableVersions =
|
||||
(await this.http.getJson<Array<IZuluVersions>>(availableVersionsUrl)).result ?? [];
|
||||
(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(', '));
|
||||
console.timeEnd('Retrieving available versions for Zulu took'); // eslint-disable-line no-console
|
||||
core.debug(`Available versions: [${availableVersions.length}]`);
|
||||
core.debug(
|
||||
availableVersions.map(item => item.jdk_version.join('.')).join(', ')
|
||||
);
|
||||
core.endGroup();
|
||||
}
|
||||
|
||||
|
@ -129,12 +148,17 @@ export class ZuluDistribution extends JavaBase {
|
|||
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: '' };
|
||||
const arch = this.distributionArchitecture();
|
||||
switch (arch) {
|
||||
case 'x64':
|
||||
return {arch: 'x86', hw_bitness: '64', abi: ''};
|
||||
case 'x86':
|
||||
return {arch: 'x86', hw_bitness: '32', abi: ''};
|
||||
case 'aarch64':
|
||||
case 'arm64':
|
||||
return {arch: 'arm', hw_bitness: '64', abi: ''};
|
||||
default:
|
||||
return {arch: arch, hw_bitness: '', abi: ''};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -149,15 +173,4 @@ export class ZuluDistribution extends JavaBase {
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
|
20
src/gpg.ts
20
src/gpg.ts
|
@ -3,7 +3,7 @@ import * as path from 'path';
|
|||
import * as io from '@actions/io';
|
||||
import * as exec from '@actions/exec';
|
||||
import * as util from './util';
|
||||
import { ExecOptions } from '@actions/exec/lib/interfaces';
|
||||
import {ExecOptions} from '@actions/exec/lib/interfaces';
|
||||
|
||||
export const PRIVATE_KEY_FILE = path.join(util.getTempDir(), 'private-key.asc');
|
||||
|
||||
|
@ -28,7 +28,13 @@ export async function importKey(privateKey: string) {
|
|||
|
||||
await exec.exec(
|
||||
'gpg',
|
||||
['--batch', '--import-options', 'import-show', '--import', PRIVATE_KEY_FILE],
|
||||
[
|
||||
'--batch',
|
||||
'--import-options',
|
||||
'import-show',
|
||||
'--import',
|
||||
PRIVATE_KEY_FILE
|
||||
],
|
||||
options
|
||||
);
|
||||
|
||||
|
@ -39,7 +45,11 @@ export async function importKey(privateKey: string) {
|
|||
}
|
||||
|
||||
export async function deleteKey(keyFingerprint: string) {
|
||||
await exec.exec('gpg', ['--batch', '--yes', '--delete-secret-and-public-key', keyFingerprint], {
|
||||
silent: true
|
||||
});
|
||||
await exec.exec(
|
||||
'gpg',
|
||||
['--batch', '--yes', '--delete-secret-and-public-key', keyFingerprint],
|
||||
{
|
||||
silent: true
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,48 +1,78 @@
|
|||
import fs from 'fs';
|
||||
import * as core from '@actions/core';
|
||||
import * as auth from './auth';
|
||||
import { getBooleanInput } from './util';
|
||||
import {
|
||||
getBooleanInput,
|
||||
isCacheFeatureAvailable,
|
||||
getVersionFromFileContent
|
||||
} from './util';
|
||||
import * as toolchains from './toolchains';
|
||||
import * as constants from './constants';
|
||||
import { restore } from './cache';
|
||||
import {restore} from './cache';
|
||||
import * as path from 'path';
|
||||
import { getJavaDistribution } from './distributions/distribution-factory';
|
||||
import { JavaInstallerOptions } from './distributions/base-models';
|
||||
import {getJavaDistribution} from './distributions/distribution-factory';
|
||||
import {JavaInstallerOptions} from './distributions/base-models';
|
||||
|
||||
async function run() {
|
||||
try {
|
||||
const version = core.getInput(constants.INPUT_JAVA_VERSION, { required: true });
|
||||
const distributionName = core.getInput(constants.INPUT_DISTRIBUTION, { required: true });
|
||||
const versions = core.getMultilineInput(constants.INPUT_JAVA_VERSION);
|
||||
const distributionName = core.getInput(constants.INPUT_DISTRIBUTION, {
|
||||
required: true
|
||||
});
|
||||
const versionFile = core.getInput(constants.INPUT_JAVA_VERSION_FILE);
|
||||
const architecture = core.getInput(constants.INPUT_ARCHITECTURE);
|
||||
const packageType = core.getInput(constants.INPUT_JAVA_PACKAGE);
|
||||
const jdkFile = core.getInput(constants.INPUT_JDK_FILE);
|
||||
const cache = core.getInput(constants.INPUT_CACHE);
|
||||
const checkLatest = getBooleanInput(constants.INPUT_CHECK_LATEST, false);
|
||||
let toolchainIds = core.getMultilineInput(constants.INPUT_MVN_TOOLCHAIN_ID);
|
||||
|
||||
const installerOptions: JavaInstallerOptions = {
|
||||
architecture,
|
||||
packageType,
|
||||
version,
|
||||
checkLatest
|
||||
};
|
||||
core.startGroup('Installed distributions');
|
||||
|
||||
const distribution = getJavaDistribution(distributionName, installerOptions, jdkFile);
|
||||
if (!distribution) {
|
||||
throw new Error(`No supported distribution was found for input ${distributionName}`);
|
||||
if (versions.length !== toolchainIds.length) {
|
||||
toolchainIds = [];
|
||||
}
|
||||
|
||||
const result = await distribution.setupJava();
|
||||
if (!versions.length && !versionFile) {
|
||||
throw new Error('java-version or java-version-file input expected');
|
||||
}
|
||||
|
||||
core.info('');
|
||||
core.info('Java configuration:');
|
||||
core.info(` Distribution: ${distributionName}`);
|
||||
core.info(` Version: ${result.version}`);
|
||||
core.info(` Path: ${result.path}`);
|
||||
core.info('');
|
||||
const installerInputsOptions: installerInputsOptions = {
|
||||
architecture,
|
||||
packageType,
|
||||
checkLatest,
|
||||
distributionName,
|
||||
jdkFile,
|
||||
toolchainIds
|
||||
};
|
||||
|
||||
if (!versions.length) {
|
||||
core.debug(
|
||||
'java-version input is empty, looking for java-version-file input'
|
||||
);
|
||||
const content = fs.readFileSync(versionFile).toString().trim();
|
||||
|
||||
const version = getVersionFromFileContent(content, distributionName);
|
||||
core.debug(`Parsed version from file '${version}'`);
|
||||
|
||||
if (!version) {
|
||||
throw new Error(
|
||||
`No supported version was found in file ${versionFile}`
|
||||
);
|
||||
}
|
||||
|
||||
await installVersion(version, installerInputsOptions);
|
||||
}
|
||||
|
||||
for (const [index, version] of versions.entries()) {
|
||||
await installVersion(version, installerInputsOptions, index);
|
||||
}
|
||||
core.endGroup();
|
||||
const matchersPath = path.join(__dirname, '..', '..', '.github');
|
||||
core.info(`##[add-matcher]${path.join(matchersPath, 'java.json')}`);
|
||||
|
||||
await auth.configureAuthentication();
|
||||
if (cache) {
|
||||
if (cache && isCacheFeatureAvailable()) {
|
||||
await restore(cache);
|
||||
}
|
||||
} catch (error) {
|
||||
|
@ -51,3 +81,60 @@ async function run() {
|
|||
}
|
||||
|
||||
run();
|
||||
|
||||
async function installVersion(
|
||||
version: string,
|
||||
options: installerInputsOptions,
|
||||
toolchainId = 0
|
||||
) {
|
||||
const {
|
||||
distributionName,
|
||||
jdkFile,
|
||||
architecture,
|
||||
packageType,
|
||||
checkLatest,
|
||||
toolchainIds
|
||||
} = options;
|
||||
|
||||
const installerOptions: JavaInstallerOptions = {
|
||||
architecture,
|
||||
packageType,
|
||||
checkLatest,
|
||||
version
|
||||
};
|
||||
|
||||
const distribution = getJavaDistribution(
|
||||
distributionName,
|
||||
installerOptions,
|
||||
jdkFile
|
||||
);
|
||||
if (!distribution) {
|
||||
throw new Error(
|
||||
`No supported distribution was found for input ${distributionName}`
|
||||
);
|
||||
}
|
||||
|
||||
const result = await distribution.setupJava();
|
||||
await toolchains.configureToolchains(
|
||||
version,
|
||||
distributionName,
|
||||
result.path,
|
||||
toolchainIds[toolchainId]
|
||||
);
|
||||
|
||||
core.info('');
|
||||
core.info('Java configuration:');
|
||||
core.info(` Distribution: ${distributionName}`);
|
||||
core.info(` Version: ${result.version}`);
|
||||
core.info(` Path: ${result.path}`);
|
||||
core.info('');
|
||||
}
|
||||
|
||||
interface installerInputsOptions {
|
||||
architecture: string;
|
||||
packageType: string;
|
||||
checkLatest: boolean;
|
||||
distributionName: string;
|
||||
jdkFile: string;
|
||||
toolchainIds: Array<string>;
|
||||
}
|
||||
|
|
169
src/toolchains.ts
Normal file
169
src/toolchains.ts
Normal file
|
@ -0,0 +1,169 @@
|
|||
import * as fs from 'fs';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import * as core from '@actions/core';
|
||||
import * as io from '@actions/io';
|
||||
import * as constants from './constants';
|
||||
|
||||
import {getBooleanInput} from './util';
|
||||
import {create as xmlCreate} from 'xmlbuilder2';
|
||||
|
||||
interface JdkInfo {
|
||||
version: string;
|
||||
vendor: string;
|
||||
id: string;
|
||||
jdkHome: string;
|
||||
}
|
||||
|
||||
export async function configureToolchains(
|
||||
version: string,
|
||||
distributionName: string,
|
||||
jdkHome: string,
|
||||
toolchainId?: string
|
||||
) {
|
||||
const vendor =
|
||||
core.getInput(constants.INPUT_MVN_TOOLCHAIN_VENDOR) || distributionName;
|
||||
const id = toolchainId || `${vendor}_${version}`;
|
||||
const settingsDirectory =
|
||||
core.getInput(constants.INPUT_SETTINGS_PATH) ||
|
||||
path.join(os.homedir(), constants.M2_DIR);
|
||||
const overwriteSettings = getBooleanInput(
|
||||
constants.INPUT_OVERWRITE_SETTINGS,
|
||||
true
|
||||
);
|
||||
|
||||
await createToolchainsSettings({
|
||||
jdkInfo: {
|
||||
version,
|
||||
vendor,
|
||||
id,
|
||||
jdkHome
|
||||
},
|
||||
settingsDirectory,
|
||||
overwriteSettings
|
||||
});
|
||||
}
|
||||
|
||||
export async function createToolchainsSettings({
|
||||
jdkInfo,
|
||||
settingsDirectory,
|
||||
overwriteSettings
|
||||
}: {
|
||||
jdkInfo: JdkInfo;
|
||||
settingsDirectory: string;
|
||||
overwriteSettings: boolean;
|
||||
}) {
|
||||
core.info(
|
||||
`Creating ${constants.MVN_TOOLCHAINS_FILE} for JDK version ${jdkInfo.version} from ${jdkInfo.vendor}`
|
||||
);
|
||||
// when an alternate m2 location is specified use only that location (no .m2 directory)
|
||||
// otherwise use the home/.m2/ path
|
||||
await io.mkdirP(settingsDirectory);
|
||||
const originalToolchains = await readExistingToolchainsFile(
|
||||
settingsDirectory
|
||||
);
|
||||
const updatedToolchains = generateToolchainDefinition(
|
||||
originalToolchains,
|
||||
jdkInfo.version,
|
||||
jdkInfo.vendor,
|
||||
jdkInfo.id,
|
||||
jdkInfo.jdkHome
|
||||
);
|
||||
await writeToolchainsFileToDisk(
|
||||
settingsDirectory,
|
||||
updatedToolchains,
|
||||
overwriteSettings
|
||||
);
|
||||
}
|
||||
|
||||
// only exported for testing purposes
|
||||
export function generateToolchainDefinition(
|
||||
original: string,
|
||||
version: string,
|
||||
vendor: string,
|
||||
id: string,
|
||||
jdkHome: string
|
||||
) {
|
||||
let xmlObj;
|
||||
if (original?.length) {
|
||||
xmlObj = xmlCreate(original)
|
||||
.root()
|
||||
.ele({
|
||||
toolchain: {
|
||||
type: 'jdk',
|
||||
provides: {
|
||||
version: `${version}`,
|
||||
vendor: `${vendor}`,
|
||||
id: `${id}`
|
||||
},
|
||||
configuration: {
|
||||
jdkHome: `${jdkHome}`
|
||||
}
|
||||
}
|
||||
});
|
||||
} else
|
||||
xmlObj = xmlCreate({
|
||||
toolchains: {
|
||||
'@xmlns': 'https://maven.apache.org/TOOLCHAINS/1.1.0',
|
||||
'@xmlns:xsi': 'https://www.w3.org/2001/XMLSchema-instance',
|
||||
'@xsi:schemaLocation':
|
||||
'https://maven.apache.org/TOOLCHAINS/1.1.0 https://maven.apache.org/xsd/toolchains-1.1.0.xsd',
|
||||
toolchain: [
|
||||
{
|
||||
type: 'jdk',
|
||||
provides: {
|
||||
version: `${version}`,
|
||||
vendor: `${vendor}`,
|
||||
id: `${id}`
|
||||
},
|
||||
configuration: {
|
||||
jdkHome: `${jdkHome}`
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
|
||||
return xmlObj.end({
|
||||
format: 'xml',
|
||||
wellFormed: false,
|
||||
headless: false,
|
||||
prettyPrint: true,
|
||||
width: 80
|
||||
});
|
||||
}
|
||||
|
||||
async function readExistingToolchainsFile(directory: string) {
|
||||
const location = path.join(directory, constants.MVN_TOOLCHAINS_FILE);
|
||||
if (fs.existsSync(location)) {
|
||||
return fs.readFileSync(location, {
|
||||
encoding: 'utf-8',
|
||||
flag: 'r'
|
||||
});
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
async function writeToolchainsFileToDisk(
|
||||
directory: string,
|
||||
settings: string,
|
||||
overwriteSettings: boolean
|
||||
) {
|
||||
const location = path.join(directory, constants.MVN_TOOLCHAINS_FILE);
|
||||
const settingsExists = fs.existsSync(location);
|
||||
if (settingsExists && overwriteSettings) {
|
||||
core.info(`Overwriting existing file ${location}`);
|
||||
} else if (!settingsExists) {
|
||||
core.info(`Writing to ${location}`);
|
||||
} else {
|
||||
core.info(
|
||||
`Skipping generation of ${location} because file already exists and overwriting is not enabled`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
return fs.writeFileSync(location, settings, {
|
||||
encoding: 'utf-8',
|
||||
flag: 'w'
|
||||
});
|
||||
}
|
96
src/util.ts
96
src/util.ts
|
@ -2,19 +2,22 @@ import os from 'os';
|
|||
import path from 'path';
|
||||
import * as fs from 'fs';
|
||||
import * as semver from 'semver';
|
||||
import * as cache from '@actions/cache';
|
||||
import * as core from '@actions/core';
|
||||
|
||||
import * as tc from '@actions/tool-cache';
|
||||
import { INPUT_JOB_STATUS } from './constants';
|
||||
import {INPUT_JOB_STATUS, DISTRIBUTIONS_ONLY_MAJOR_VERSION} from './constants';
|
||||
|
||||
export function getTempDir() {
|
||||
let tempDirectory = process.env['RUNNER_TEMP'] || os.tmpdir();
|
||||
const tempDirectory = process.env['RUNNER_TEMP'] || os.tmpdir();
|
||||
|
||||
return tempDirectory;
|
||||
}
|
||||
|
||||
export function getBooleanInput(inputName: string, defaultValue: boolean = false) {
|
||||
return (core.getInput(inputName) || String(defaultValue)).toUpperCase() === 'TRUE';
|
||||
export function getBooleanInput(inputName: string, defaultValue = false) {
|
||||
return (
|
||||
(core.getInput(inputName) || String(defaultValue)).toUpperCase() === 'TRUE'
|
||||
);
|
||||
}
|
||||
|
||||
export function getVersionFromToolcachePath(toolPath: string) {
|
||||
|
@ -27,7 +30,9 @@ export function getVersionFromToolcachePath(toolPath: string) {
|
|||
|
||||
export async function extractJdkFile(toolPath: string, extension?: string) {
|
||||
if (!extension) {
|
||||
extension = toolPath.endsWith('.tar.gz') ? 'tar.gz' : path.extname(toolPath);
|
||||
extension = toolPath.endsWith('.tar.gz')
|
||||
? 'tar.gz'
|
||||
: path.extname(toolPath);
|
||||
if (extension.startsWith('.')) {
|
||||
extension = extension.substring(1);
|
||||
}
|
||||
|
@ -62,7 +67,11 @@ export function isVersionSatisfies(range: string, version: string): boolean {
|
|||
return semver.satisfies(version, range);
|
||||
}
|
||||
|
||||
export function getToolcachePath(toolName: string, version: string, architecture: string) {
|
||||
export function getToolcachePath(
|
||||
toolName: string,
|
||||
version: string,
|
||||
architecture: string
|
||||
) {
|
||||
const toolcacheRoot = process.env['RUNNER_TOOL_CACHE'] ?? '';
|
||||
const fullPath = path.join(toolcacheRoot, toolName, version, architecture);
|
||||
if (fs.existsSync(fullPath)) {
|
||||
|
@ -77,3 +86,78 @@ export function isJobStatusSuccess() {
|
|||
|
||||
return jobStatus === 'success';
|
||||
}
|
||||
|
||||
export function isGhes(): boolean {
|
||||
const ghUrl = new URL(
|
||||
process.env['GITHUB_SERVER_URL'] || 'https://github.com'
|
||||
);
|
||||
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
|
||||
}
|
||||
|
||||
export function isCacheFeatureAvailable(): boolean {
|
||||
if (cache.isFeatureAvailable()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isGhes()) {
|
||||
core.warning(
|
||||
'Caching is only supported on GHES version >= 3.5. If you are on a version >= 3.5, please check with your GHES admin if the Actions cache service is enabled or not.'
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
core.warning(
|
||||
'The runner was not able to contact the cache service. Caching will be skipped'
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
export function getVersionFromFileContent(
|
||||
content: string,
|
||||
distributionName: string
|
||||
): string | null {
|
||||
const javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
|
||||
const fileContent = content.match(javaVersionRegExp)?.groups?.version
|
||||
? (content.match(javaVersionRegExp)?.groups?.version as string)
|
||||
: '';
|
||||
if (!fileContent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
core.debug(`Version from file '${fileContent}'`);
|
||||
|
||||
const tentativeVersion = avoidOldNotation(fileContent);
|
||||
const rawVersion = tentativeVersion.split('-')[0];
|
||||
|
||||
let version = semver.validRange(rawVersion)
|
||||
? tentativeVersion
|
||||
: semver.coerce(tentativeVersion);
|
||||
|
||||
core.debug(`Range version from file is '${version}'`);
|
||||
|
||||
if (!version) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (DISTRIBUTIONS_ONLY_MAJOR_VERSION.includes(distributionName)) {
|
||||
const coerceVersion = semver.coerce(version) ?? version;
|
||||
version = semver.major(coerceVersion).toString();
|
||||
}
|
||||
|
||||
return version.toString();
|
||||
}
|
||||
|
||||
// By convention, action expects version 8 in the format `8.*` instead of `1.8`
|
||||
function avoidOldNotation(content: string): string {
|
||||
return content.startsWith('1.') ? content.substring(2) : content;
|
||||
}
|
||||
|
||||
export function convertVersionToSemver(version: number[] | string) {
|
||||
// Some distributions may use semver-like notation (12.10.2.1, 12.10.2.1.1)
|
||||
const versionArray = Array.isArray(version) ? version : version.split('.');
|
||||
const mainVersion = versionArray.slice(0, 3).join('.');
|
||||
if (versionArray.length > 3) {
|
||||
return `${mainVersion}+${versionArray.slice(3).join('.')}`;
|
||||
}
|
||||
return mainVersion;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue