Merge branch 'implement-v2-installers' into implement-v2-tests

This commit is contained in:
Maxim Lobanov 2021-03-10 19:55:48 +03:00
commit 793a1df84f
9 changed files with 3167 additions and 85 deletions

3034
dist/cleanup/index.js vendored

File diff suppressed because it is too large Load diff

118
dist/setup/index.js vendored
View file

@ -519,9 +519,16 @@ module.exports = maxSatisfying
/***/ }), /***/ }),
/* 15 */, /* 15 */,
/* 16 */ /* 16 */
/***/ (function(module) { /***/ (function(module, __unusedexports, __webpack_require__) {
const SemVer = __webpack_require__(65)
const compareBuild = (a, b, loose) => {
const versionA = new SemVer(a, loose)
const versionB = new SemVer(b, loose)
return versionA.compare(versionB) || versionA.compareBuild(versionB)
}
module.exports = compareBuild
module.exports = require("tls");
/***/ }), /***/ }),
/* 17 */, /* 17 */,
@ -3966,7 +3973,7 @@ class JavaBase {
core.info(`Resolved Java ${foundJava.version} from tool-cache`); core.info(`Resolved Java ${foundJava.version} from tool-cache`);
} }
else { else {
core.info(`Java ${this.version.raw} was not found in tool-cache. Trying to download...`); core.info(`Java ${this.version} was not found in tool-cache. Trying to download...`);
const javaRelease = yield this.findPackageForDownload(this.version); const javaRelease = yield this.findPackageForDownload(this.version);
foundJava = yield this.downloadTool(javaRelease); foundJava = yield this.downloadTool(javaRelease);
core.info(`Java ${foundJava.version} was downloaded`); core.info(`Java ${foundJava.version} was downloaded`);
@ -3979,8 +3986,7 @@ class JavaBase {
get toolcacheFolderName() { get toolcacheFolderName() {
return `Java_${this.distribution}_${this.packageType}`; return `Java_${this.distribution}_${this.packageType}`;
} }
getToolcacheVersionName(resolvedVersion) { getToolcacheVersionName(version) {
let version = resolvedVersion;
if (!this.stable) { if (!this.stable) {
const cleanVersion = semver_1.default.clean(version); const cleanVersion = semver_1.default.clean(version);
return `${cleanVersion}-ea`; return `${cleanVersion}-ea`;
@ -3994,12 +4000,12 @@ class JavaBase {
.findAllVersions(this.toolcacheFolderName, this.architecture) .findAllVersions(this.toolcacheFolderName, this.architecture)
.filter(item => item.endsWith('-ea') === !this.stable); .filter(item => item.endsWith('-ea') === !this.stable);
const satisfiedVersions = availableVersions const satisfiedVersions = availableVersions
.filter(item => semver_1.default.satisfies(item.replace(/-ea$/, ''), this.version)) .filter(item => util_1.isVersionSatisfies(this.version, item.replace(/-ea$/, '')))
.sort(semver_1.default.rcompare); .sort(semver_1.default.rcompare);
if (!satisfiedVersions || satisfiedVersions.length === 0) { if (!satisfiedVersions || satisfiedVersions.length === 0) {
return null; return null;
} }
const javaPath = tc.find(this.toolcacheFolderName, satisfiedVersions[0], this.architecture); const javaPath = util_1.getToolcachePath(this.toolcacheFolderName, satisfiedVersions[0], this.architecture);
if (!javaPath) { if (!javaPath) {
return null; return null;
} }
@ -4008,28 +4014,32 @@ class JavaBase {
path: javaPath path: javaPath
}; };
} }
setJavaDefault(version, toolPath) {
core.exportVariable('JAVA_HOME', toolPath);
core.addPath(path_1.default.join(toolPath, 'bin'));
core.setOutput('distribution', this.distribution);
core.setOutput('path', toolPath);
core.setOutput('version', version);
}
// this function validates and parse java version to its normal semver notation
normalizeVersion(version) { normalizeVersion(version) {
let stable = true; let stable = true;
if (version.endsWith('-ea')) { if (version.endsWith('-ea')) {
version = version.replace(/-ea$/, ''); version = version.replace(/-ea$/, '');
stable = false; stable = false;
} }
else if (version.includes('-ea.')) {
// transform '11.0.3-ea.2' -> '11.0.3+2'
version = version.replace('-ea.', '+');
stable = false;
}
if (!semver_1.default.validRange(version)) { if (!semver_1.default.validRange(version)) {
throw new Error(`The string '${version}' is not valid SemVer notation for a Java version. Please check README file for code snippets and more detailed information`); throw new Error(`The string '${version}' is not valid SemVer notation for a Java version. Please check README file for code snippets and more detailed information`);
} }
return { return {
version: new semver_1.default.Range(version), version,
stable stable
}; };
} }
setJavaDefault(version, toolPath) {
core.exportVariable('JAVA_HOME', toolPath);
core.addPath(path_1.default.join(toolPath, 'bin'));
core.setOutput('distribution', this.distribution);
core.setOutput('path', toolPath);
core.setOutput('version', version);
}
} }
exports.JavaBase = JavaBase; exports.JavaBase = JavaBase;
@ -7822,7 +7832,7 @@ util_1.applyMixin(ElementImpl_1.ElementImpl, SlotableImpl_1.SlotableImpl);
/* 120 */ /* 120 */
/***/ (function(module, __unusedexports, __webpack_require__) { /***/ (function(module, __unusedexports, __webpack_require__) {
const compareBuild = __webpack_require__(465) const compareBuild = __webpack_require__(16)
const sort = (list, loose) => list.sort((a, b) => compareBuild(a, b, loose)) const sort = (list, loose) => list.sort((a, b) => compareBuild(a, b, loose))
module.exports = sort module.exports = sort
@ -9013,7 +9023,7 @@ function _unique(values) {
var net = __webpack_require__(631); var net = __webpack_require__(631);
var tls = __webpack_require__(16); var tls = __webpack_require__(818);
var http = __webpack_require__(605); var http = __webpack_require__(605);
var https = __webpack_require__(34); var https = __webpack_require__(34);
var events = __webpack_require__(614); var events = __webpack_require__(614);
@ -9352,7 +9362,7 @@ class LocalDistribution extends base_installer_1.JavaBase {
core.info(`Resolved Java ${foundJava.version} from tool-cache`); core.info(`Resolved Java ${foundJava.version} from tool-cache`);
} }
else { else {
core.info(`Java ${this.version.raw} 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) { if (!this.jdkFile) {
throw new Error("'jdkFile' is not specified"); throw new Error("'jdkFile' is not specified");
} }
@ -9365,7 +9375,7 @@ class LocalDistribution extends base_installer_1.JavaBase {
const extractedJavaPath = yield util_1.extractJdkFile(jdkFilePath); const extractedJavaPath = yield util_1.extractJdkFile(jdkFilePath);
const archiveName = fs_1.default.readdirSync(extractedJavaPath)[0]; const archiveName = fs_1.default.readdirSync(extractedJavaPath)[0];
const archivePath = path_1.default.join(extractedJavaPath, archiveName); const archivePath = path_1.default.join(extractedJavaPath, archiveName);
const javaVersion = this.version.raw; const javaVersion = this.version;
let javaPath = yield tc.cacheDir(archivePath, this.toolcacheFolderName, this.getToolcacheVersionName(javaVersion), this.architecture); let javaPath = yield 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 // for different Java distributions, postfix can exist or not so need to check both cases
if (process.platform === 'darwin' && if (process.platform === 'darwin' &&
@ -12925,9 +12935,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod }; return (mod && mod.__esModule) ? mod : { "default": mod };
}; };
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.getDownloadArchiveExtension = exports.extractJdkFile = exports.getVersionFromToolcachePath = exports.getTempDir = void 0; exports.getToolcachePath = exports.isVersionSatisfies = exports.getDownloadArchiveExtension = exports.extractJdkFile = exports.getVersionFromToolcachePath = exports.getTempDir = void 0;
const os_1 = __importDefault(__webpack_require__(87)); const os_1 = __importDefault(__webpack_require__(87));
const path_1 = __importDefault(__webpack_require__(622)); const path_1 = __importDefault(__webpack_require__(622));
const fs = __importStar(__webpack_require__(747));
const semver = __importStar(__webpack_require__(876));
const tc = __importStar(__webpack_require__(139)); const tc = __importStar(__webpack_require__(139));
function getTempDir() { function getTempDir() {
let tempDirectory = process.env['RUNNER_TEMP'] || os_1.default.tmpdir(); let tempDirectory = process.env['RUNNER_TEMP'] || os_1.default.tmpdir();
@ -12965,6 +12977,30 @@ function getDownloadArchiveExtension() {
return process.platform === 'win32' ? 'zip' : 'tar.gz'; return process.platform === 'win32' ? 'zip' : 'tar.gz';
} }
exports.getDownloadArchiveExtension = getDownloadArchiveExtension; exports.getDownloadArchiveExtension = getDownloadArchiveExtension;
function isVersionSatisfies(range, version) {
var _a;
if (semver.valid(range)) {
// if full version with build digit is provided as a range (such as '1.2.3+4')
// we should check for exact equal via compareBuild
// since semver.satisfies doesn't handle 4th digit
const semRange = semver.parse(range);
if (semRange && ((_a = semRange.build) === null || _a === void 0 ? void 0 : _a.length) > 0) {
return semver.compareBuild(range, version) === 0;
}
}
return semver.satisfies(version, range);
}
exports.isVersionSatisfies = isVersionSatisfies;
function getToolcachePath(toolName, version, architecture) {
var _a;
const toolcacheRoot = (_a = process.env['RUNNER_TOOL_CACHE']) !== null && _a !== void 0 ? _a : '';
const fullPath = path_1.default.join(toolcacheRoot, toolName, version, architecture);
if (fs.existsSync(fullPath)) {
return fullPath;
}
return null;
}
exports.getToolcachePath = getToolcachePath;
/***/ }), /***/ }),
@ -13294,7 +13330,7 @@ function write(directory, settings) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const location = path.join(directory, exports.SETTINGS_FILE); const location = path.join(directory, exports.SETTINGS_FILE);
if (fs.existsSync(location)) { if (fs.existsSync(location)) {
core.warning(`Overwriting existing file ${location}`); core.info(`Overwriting existing file ${location}`);
} }
else { else {
core.info(`Writing ${location}`); core.info(`Writing ${location}`);
@ -13765,7 +13801,7 @@ class AdoptiumDistribution extends base_installer_1.JavaBase {
}; };
}); });
const satisfiedVersions = availableVersionsWithBinaries const satisfiedVersions = availableVersionsWithBinaries
.filter(item => semver_1.default.satisfies(item.version, version)) .filter(item => util_1.isVersionSatisfies(version, item.version))
.sort((a, b) => { .sort((a, b) => {
return -semver_1.default.compareBuild(a.version, b.version); return -semver_1.default.compareBuild(a.version, b.version);
}); });
@ -13775,7 +13811,7 @@ class AdoptiumDistribution extends base_installer_1.JavaBase {
const availableOptionsMessage = availableOptions const availableOptionsMessage = availableOptions
? `\nAvailable versions: ${availableOptions}` ? `\nAvailable versions: ${availableOptions}`
: ''; : '';
throw new Error(`Could not find satisfied version for SemVer '${version.raw}'. ${availableOptionsMessage}`); throw new Error(`Could not find satisfied version for SemVer '${version}'. ${availableOptionsMessage}`);
} }
return resolvedFullVersion; return resolvedFullVersion;
}); });
@ -13804,8 +13840,7 @@ class AdoptiumDistribution extends base_installer_1.JavaBase {
const platform = this.getPlatformOption(); const platform = this.getPlatformOption();
const arch = this.architecture; const arch = this.architecture;
const imageType = this.packageType; const imageType = this.packageType;
const versionRange = '[1.0,100.0]'; // retrieve all available versions const versionRange = encodeURI('[1.0,100.0]'); // retrieve all available versions
const encodedVersionRange = encodeURI(versionRange);
const releaseType = this.stable ? 'ga' : 'ea'; const releaseType = this.stable ? 'ga' : 'ea';
console.time('adopt-retrieve-available-versions'); console.time('adopt-retrieve-available-versions');
const baseRequestArguments = [ const baseRequestArguments = [
@ -13826,7 +13861,7 @@ class AdoptiumDistribution extends base_installer_1.JavaBase {
const availableVersions = []; const availableVersions = [];
while (true) { while (true) {
const requestArguments = `${baseRequestArguments}&page_size=20&page=${page_index}`; const requestArguments = `${baseRequestArguments}&page_size=20&page=${page_index}`;
const availableVersionsUrl = `https://api.adoptopenjdk.net/v3/assets/version/${encodedVersionRange}?${requestArguments}`; const availableVersionsUrl = `https://api.adoptopenjdk.net/v3/assets/version/${versionRange}?${requestArguments}`;
if (core.isDebug() && page_index === 0) { if (core.isDebug() && page_index === 0) {
// url is identical except page_index so print it once for debug // 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}'`);
@ -14083,7 +14118,7 @@ class ZuluDistribution extends base_installer_1.JavaBase {
}; };
}); });
const satisfiedVersions = availableVersions const satisfiedVersions = availableVersions
.filter(item => semver_1.default.satisfies(item.version, version)) .filter(item => util_1.isVersionSatisfies(version, item.version))
.sort((a, b) => { .sort((a, b) => {
// Azul provides two versions: jdk_version and azul_version // Azul provides two versions: jdk_version and azul_version
// we should sort by both fields by descending // we should sort by both fields by descending
@ -14102,7 +14137,7 @@ class ZuluDistribution extends base_installer_1.JavaBase {
const availableOptionsMessage = availableOptions const availableOptionsMessage = availableOptions
? `\nAvailable versions: ${availableOptions}` ? `\nAvailable versions: ${availableOptions}`
: ''; : '';
throw new Error(`Could not find satisfied version for semver ${version.raw}. ${availableOptionsMessage}`); throw new Error(`Could not find satisfied version for semver ${version}. ${availableOptionsMessage}`);
} }
return resolvedFullVersion; return resolvedFullVersion;
}); });
@ -19280,19 +19315,7 @@ exports.traversal_filter = traversal_filter;
//# sourceMappingURL=TraversalAlgorithm.js.map //# sourceMappingURL=TraversalAlgorithm.js.map
/***/ }), /***/ }),
/* 465 */ /* 465 */,
/***/ (function(module, __unusedexports, __webpack_require__) {
const SemVer = __webpack_require__(65)
const compareBuild = (a, b, loose) => {
const versionA = new SemVer(a, loose)
const versionB = new SemVer(b, loose)
return versionA.compare(versionB) || versionA.compareBuild(versionB)
}
module.exports = compareBuild
/***/ }),
/* 466 */, /* 466 */,
/* 467 */, /* 467 */,
/* 468 */ /* 468 */
@ -27409,7 +27432,7 @@ exports.utf8Decode = utf8Decode;
/* 593 */ /* 593 */
/***/ (function(module, __unusedexports, __webpack_require__) { /***/ (function(module, __unusedexports, __webpack_require__) {
const compareBuild = __webpack_require__(465) const compareBuild = __webpack_require__(16)
const rsort = (list, loose) => list.sort((a, b) => compareBuild(b, a, loose)) const rsort = (list, loose) => list.sort((a, b) => compareBuild(b, a, loose))
module.exports = rsort module.exports = rsort
@ -38425,7 +38448,12 @@ exports.asciiSerializationOfAnOrigin = asciiSerializationOfAnOrigin;
/* 815 */, /* 815 */,
/* 816 */, /* 816 */,
/* 817 */, /* 817 */,
/* 818 */, /* 818 */
/***/ (function(module) {
module.exports = require("tls");
/***/ }),
/* 819 */, /* 819 */,
/* 820 */ /* 820 */
/***/ (function(__unusedmodule, exports, __webpack_require__) { /***/ (function(__unusedmodule, exports, __webpack_require__) {
@ -40883,7 +40911,7 @@ module.exports = {
compare: __webpack_require__(874), compare: __webpack_require__(874),
rcompare: __webpack_require__(630), rcompare: __webpack_require__(630),
compareLoose: __webpack_require__(283), compareLoose: __webpack_require__(283),
compareBuild: __webpack_require__(465), compareBuild: __webpack_require__(16),
sort: __webpack_require__(120), sort: __webpack_require__(120),
rsort: __webpack_require__(593), rsort: __webpack_require__(593),
gt: __webpack_require__(486), gt: __webpack_require__(486),

BIN
dist/setup/unzip vendored

Binary file not shown.

View file

@ -101,7 +101,7 @@ export function generate(
async function write(directory: string, settings: string) { async function write(directory: string, settings: string) {
const location = path.join(directory, SETTINGS_FILE); const location = path.join(directory, SETTINGS_FILE);
if (fs.existsSync(location)) { if (fs.existsSync(location)) {
core.warning(`Overwriting existing file ${location}`); core.info(`Overwriting existing file ${location}`);
} else { } else {
core.info(`Writing ${location}`); core.info(`Writing ${location}`);
} }

View file

@ -9,14 +9,14 @@ import { JavaBase } from '../base-installer';
import { IAdoptiumAvailableVersions } from './models'; import { IAdoptiumAvailableVersions } from './models';
import { JavaInstallerOptions, JavaDownloadRelease, JavaInstallerResults } from '../base-models'; import { JavaInstallerOptions, JavaDownloadRelease, JavaInstallerResults } from '../base-models';
import { MACOS_JAVA_CONTENT_POSTFIX } from '../../constants'; import { MACOS_JAVA_CONTENT_POSTFIX } from '../../constants';
import { extractJdkFile, getDownloadArchiveExtension } from '../../util'; import { extractJdkFile, getDownloadArchiveExtension, isVersionSatisfies } from '../../util';
export class AdoptiumDistribution extends JavaBase { export class AdoptiumDistribution extends JavaBase {
constructor(installerOptions: JavaInstallerOptions) { constructor(installerOptions: JavaInstallerOptions) {
super('Adoptium', installerOptions); super('Adoptium', installerOptions);
} }
protected async findPackageForDownload(version: semver.Range): Promise<JavaDownloadRelease> { protected async findPackageForDownload(version: string): Promise<JavaDownloadRelease> {
const availableVersionsRaw = await this.getAvailableVersions(); const availableVersionsRaw = await this.getAvailableVersions();
const availableVersionsWithBinaries = availableVersionsRaw const availableVersionsWithBinaries = availableVersionsRaw
.filter(item => item.binaries.length > 0) .filter(item => item.binaries.length > 0)
@ -28,7 +28,7 @@ export class AdoptiumDistribution extends JavaBase {
}); });
const satisfiedVersions = availableVersionsWithBinaries const satisfiedVersions = availableVersionsWithBinaries
.filter(item => semver.satisfies(item.version, version)) .filter(item => isVersionSatisfies(version, item.version))
.sort((a, b) => { .sort((a, b) => {
return -semver.compareBuild(a.version, b.version); return -semver.compareBuild(a.version, b.version);
}); });
@ -40,7 +40,7 @@ export class AdoptiumDistribution extends JavaBase {
? `\nAvailable versions: ${availableOptions}` ? `\nAvailable versions: ${availableOptions}`
: ''; : '';
throw new Error( throw new Error(
`Could not find satisfied version for SemVer '${version.raw}'. ${availableOptionsMessage}` `Could not find satisfied version for SemVer '${version}'. ${availableOptionsMessage}`
); );
} }
@ -78,8 +78,7 @@ export class AdoptiumDistribution extends JavaBase {
const platform = this.getPlatformOption(); const platform = this.getPlatformOption();
const arch = this.architecture; const arch = this.architecture;
const imageType = this.packageType; const imageType = this.packageType;
const versionRange = '[1.0,100.0]'; // retrieve all available versions const versionRange = encodeURI('[1.0,100.0]'); // retrieve all available versions
const encodedVersionRange = encodeURI(versionRange);
const releaseType = this.stable ? 'ga' : 'ea'; const releaseType = this.stable ? 'ga' : 'ea';
console.time('adopt-retrieve-available-versions'); console.time('adopt-retrieve-available-versions');
@ -103,7 +102,7 @@ export class AdoptiumDistribution extends JavaBase {
const availableVersions: IAdoptiumAvailableVersions[] = []; const availableVersions: IAdoptiumAvailableVersions[] = [];
while (true) { while (true) {
const requestArguments = `${baseRequestArguments}&page_size=20&page=${page_index}`; const requestArguments = `${baseRequestArguments}&page_size=20&page=${page_index}`;
const availableVersionsUrl = `https://api.adoptopenjdk.net/v3/assets/version/${encodedVersionRange}?${requestArguments}`; const availableVersionsUrl = `https://api.adoptopenjdk.net/v3/assets/version/${versionRange}?${requestArguments}`;
if (core.isDebug() && page_index === 0) { if (core.isDebug() && page_index === 0) {
// url is identical except page_index so print it once for debug // 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}'`);

View file

@ -3,12 +3,12 @@ import * as core from '@actions/core';
import semver from 'semver'; import semver from 'semver';
import path from 'path'; import path from 'path';
import * as httpm from '@actions/http-client'; import * as httpm from '@actions/http-client';
import { getVersionFromToolcachePath } from '../util'; import { getToolcachePath, getVersionFromToolcachePath, isVersionSatisfies } from '../util';
import { JavaDownloadRelease, JavaInstallerOptions, JavaInstallerResults } from './base-models'; import { JavaDownloadRelease, JavaInstallerOptions, JavaInstallerResults } from './base-models';
export abstract class JavaBase { export abstract class JavaBase {
protected http: httpm.HttpClient; protected http: httpm.HttpClient;
protected version: semver.Range; protected version: string;
protected architecture: string; protected architecture: string;
protected packageType: string; protected packageType: string;
protected stable: boolean; protected stable: boolean;
@ -27,14 +27,14 @@ export abstract class JavaBase {
} }
protected abstract downloadTool(javaRelease: JavaDownloadRelease): Promise<JavaInstallerResults>; protected abstract downloadTool(javaRelease: JavaDownloadRelease): Promise<JavaInstallerResults>;
protected abstract findPackageForDownload(range: semver.Range): Promise<JavaDownloadRelease>; protected abstract findPackageForDownload(range: string): Promise<JavaDownloadRelease>;
public async setupJava(): Promise<JavaInstallerResults> { public async setupJava(): Promise<JavaInstallerResults> {
let foundJava = this.findInToolcache(); let foundJava = this.findInToolcache();
if (foundJava) { if (foundJava) {
core.info(`Resolved Java ${foundJava.version} from tool-cache`); core.info(`Resolved Java ${foundJava.version} from tool-cache`);
} else { } else {
core.info(`Java ${this.version.raw} was not found in tool-cache. Trying to download...`); core.info(`Java ${this.version} was not found in tool-cache. Trying to download...`);
const javaRelease = await this.findPackageForDownload(this.version); const javaRelease = await this.findPackageForDownload(this.version);
foundJava = await this.downloadTool(javaRelease); foundJava = await this.downloadTool(javaRelease);
core.info(`Java ${foundJava.version} was downloaded`); core.info(`Java ${foundJava.version} was downloaded`);
@ -50,8 +50,7 @@ export abstract class JavaBase {
return `Java_${this.distribution}_${this.packageType}`; return `Java_${this.distribution}_${this.packageType}`;
} }
protected getToolcacheVersionName(resolvedVersion: string): string { protected getToolcacheVersionName(version: string): string {
let version = resolvedVersion;
if (!this.stable) { if (!this.stable) {
const cleanVersion = semver.clean(version); const cleanVersion = semver.clean(version);
return `${cleanVersion}-ea`; return `${cleanVersion}-ea`;
@ -67,13 +66,17 @@ export abstract class JavaBase {
.filter(item => item.endsWith('-ea') === !this.stable); .filter(item => item.endsWith('-ea') === !this.stable);
const satisfiedVersions = availableVersions const satisfiedVersions = availableVersions
.filter(item => semver.satisfies(item.replace(/-ea$/, ''), this.version)) .filter(item => isVersionSatisfies(this.version, item.replace(/-ea$/, '')))
.sort(semver.rcompare); .sort(semver.rcompare);
if (!satisfiedVersions || satisfiedVersions.length === 0) { if (!satisfiedVersions || satisfiedVersions.length === 0) {
return null; return null;
} }
const javaPath = tc.find(this.toolcacheFolderName, satisfiedVersions[0], this.architecture); const javaPath = getToolcachePath(
this.toolcacheFolderName,
satisfiedVersions[0],
this.architecture
);
if (!javaPath) { if (!javaPath) {
return null; return null;
} }
@ -84,21 +87,16 @@ export abstract class JavaBase {
}; };
} }
protected setJavaDefault(version: string, toolPath: string) {
core.exportVariable('JAVA_HOME', toolPath);
core.addPath(path.join(toolPath, 'bin'));
core.setOutput('distribution', this.distribution);
core.setOutput('path', toolPath);
core.setOutput('version', version);
}
// this function validates and parse java version to its normal semver notation
protected normalizeVersion(version: string) { protected normalizeVersion(version: string) {
let stable = true; let stable = true;
if (version.endsWith('-ea')) { if (version.endsWith('-ea')) {
version = version.replace(/-ea$/, ''); version = version.replace(/-ea$/, '');
stable = false; stable = false;
} else if (version.includes('-ea.')) {
// transform '11.0.3-ea.2' -> '11.0.3+2'
version = version.replace('-ea.', '+');
stable = false;
} }
if (!semver.validRange(version)) { if (!semver.validRange(version)) {
@ -108,8 +106,16 @@ export abstract class JavaBase {
} }
return { return {
version: new semver.Range(version), version,
stable stable
}; };
} }
protected setJavaDefault(version: string, toolPath: string) {
core.exportVariable('JAVA_HOME', toolPath);
core.addPath(path.join(toolPath, 'bin'));
core.setOutput('distribution', this.distribution);
core.setOutput('path', toolPath);
core.setOutput('version', version);
}
} }

View file

@ -21,9 +21,7 @@ export class LocalDistribution extends JavaBase {
if (foundJava) { if (foundJava) {
core.info(`Resolved Java ${foundJava.version} from tool-cache`); core.info(`Resolved Java ${foundJava.version} from tool-cache`);
} else { } else {
core.info( core.info(`Java ${this.version} was not found in tool-cache. Trying to unpack JDK file...`);
`Java ${this.version.raw} was not found in tool-cache. Trying to unpack JDK file...`
);
if (!this.jdkFile) { if (!this.jdkFile) {
throw new Error("'jdkFile' is not specified"); throw new Error("'jdkFile' is not specified");
} }
@ -39,7 +37,7 @@ export class LocalDistribution extends JavaBase {
const extractedJavaPath = await extractJdkFile(jdkFilePath); const extractedJavaPath = await extractJdkFile(jdkFilePath);
const archiveName = fs.readdirSync(extractedJavaPath)[0]; const archiveName = fs.readdirSync(extractedJavaPath)[0];
const archivePath = path.join(extractedJavaPath, archiveName); const archivePath = path.join(extractedJavaPath, archiveName);
const javaVersion = this.version.raw; const javaVersion = this.version;
let javaPath = await tc.cacheDir( let javaPath = await tc.cacheDir(
archivePath, archivePath,
@ -68,7 +66,7 @@ export class LocalDistribution extends JavaBase {
return foundJava; return foundJava;
} }
protected async findPackageForDownload(version: semver.Range): Promise<JavaDownloadRelease> { protected async findPackageForDownload(version: string): Promise<JavaDownloadRelease> {
throw new Error('This method should not be implemented in local file provider'); throw new Error('This method should not be implemented in local file provider');
} }

View file

@ -7,7 +7,7 @@ import semver from 'semver';
import { JavaBase } from '../base-installer'; import { JavaBase } from '../base-installer';
import { IZuluVersions } from './models'; import { IZuluVersions } from './models';
import { extractJdkFile, getDownloadArchiveExtension } from '../../util'; import { extractJdkFile, getDownloadArchiveExtension, isVersionSatisfies } from '../../util';
import { JavaDownloadRelease, JavaInstallerOptions, JavaInstallerResults } from '../base-models'; import { JavaDownloadRelease, JavaInstallerOptions, JavaInstallerResults } from '../base-models';
export class ZuluDistribution extends JavaBase { export class ZuluDistribution extends JavaBase {
@ -15,7 +15,7 @@ export class ZuluDistribution extends JavaBase {
super('Zulu', installerOptions); super('Zulu', installerOptions);
} }
protected async findPackageForDownload(version: semver.Range): Promise<JavaDownloadRelease> { protected async findPackageForDownload(version: string): Promise<JavaDownloadRelease> {
const availableVersionsRaw = await this.getAvailableVersions(); const availableVersionsRaw = await this.getAvailableVersions();
const availableVersions = availableVersionsRaw.map(item => { const availableVersions = availableVersionsRaw.map(item => {
return { return {
@ -26,7 +26,7 @@ export class ZuluDistribution extends JavaBase {
}); });
const satisfiedVersions = availableVersions const satisfiedVersions = availableVersions
.filter(item => semver.satisfies(item.version, version)) .filter(item => isVersionSatisfies(version, item.version))
.sort((a, b) => { .sort((a, b) => {
// Azul provides two versions: jdk_version and azul_version // Azul provides two versions: jdk_version and azul_version
// we should sort by both fields by descending // we should sort by both fields by descending
@ -49,7 +49,7 @@ export class ZuluDistribution extends JavaBase {
? `\nAvailable versions: ${availableOptions}` ? `\nAvailable versions: ${availableOptions}`
: ''; : '';
throw new Error( throw new Error(
`Could not find satisfied version for semver ${version.raw}. ${availableOptionsMessage}` `Could not find satisfied version for semver ${version}. ${availableOptionsMessage}`
); );
} }

View file

@ -1,8 +1,9 @@
import os from 'os'; import os from 'os';
import path from 'path'; import path from 'path';
import * as fs from 'fs';
import * as semver from 'semver';
import * as tc from '@actions/tool-cache'; import * as tc from '@actions/tool-cache';
export function getTempDir() { export function getTempDir() {
let tempDirectory = process.env['RUNNER_TEMP'] || os.tmpdir(); let tempDirectory = process.env['RUNNER_TEMP'] || os.tmpdir();
@ -39,3 +40,27 @@ export async function extractJdkFile(toolPath: string, extension?: string) {
export function getDownloadArchiveExtension() { export function getDownloadArchiveExtension() {
return process.platform === 'win32' ? 'zip' : 'tar.gz'; return process.platform === 'win32' ? 'zip' : 'tar.gz';
} }
export function isVersionSatisfies(range: string, version: string): boolean {
if (semver.valid(range)) {
// if full version with build digit is provided as a range (such as '1.2.3+4')
// we should check for exact equal via compareBuild
// since semver.satisfies doesn't handle 4th digit
const semRange = semver.parse(range);
if (semRange && semRange.build?.length > 0) {
return semver.compareBuild(range, version) === 0;
}
}
return semver.satisfies(version, range);
}
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)) {
return fullPath;
}
return null;
}