mirror of
https://github.com/actions/setup-java.git
synced 2025-05-21 18:01:46 +00:00
Simplify solution and unit-tests
This commit is contained in:
parent
36571034fa
commit
3fb9de05e9
@ -241,22 +241,3 @@ describe('getAvailableVersions', () => {
|
|||||||
spyGetDownloadArchiveExtension.mockReturnValue(mockedExtension);
|
spyGetDownloadArchiveExtension.mockReturnValue(mockedExtension);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('convertVersionToSemver', () => {
|
|
||||||
it.each([
|
|
||||||
['12', '12'],
|
|
||||||
['12.0', '12.0'],
|
|
||||||
['12.0.2', '12.0.2'],
|
|
||||||
['12.0.2.1', '12.0.2+1'],
|
|
||||||
['12.0.2.1.0', '12.0.2+1.0']
|
|
||||||
])('%s -> %s', (input: string, expected: string) => {
|
|
||||||
const distribution = new CorrettoDistribution({
|
|
||||||
version: '12',
|
|
||||||
architecture: 'x86',
|
|
||||||
packageType: 'jdk',
|
|
||||||
checkLatest: false
|
|
||||||
});
|
|
||||||
const actual = distribution['convertVersionToSemver'](input);
|
|
||||||
expect(actual).toBe(expected);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
@ -227,22 +227,3 @@ describe('findPackageForDownload', () => {
|
|||||||
).rejects.toThrow(/Could not find satisfied version for semver */);
|
).rejects.toThrow(/Could not find satisfied version for semver */);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('convertVersionToSemver', () => {
|
|
||||||
it.each([
|
|
||||||
[[12], '12'],
|
|
||||||
[[12, 0], '12.0'],
|
|
||||||
[[12, 0, 2], '12.0.2'],
|
|
||||||
[[12, 0, 2, 1], '12.0.2+1'],
|
|
||||||
[[12, 0, 2, 1, 3], '12.0.2+1']
|
|
||||||
])('%s -> %s', (input: number[], expected: string) => {
|
|
||||||
const distribution = new ZuluDistribution({
|
|
||||||
version: '18',
|
|
||||||
architecture: 'x86',
|
|
||||||
packageType: 'jdk',
|
|
||||||
checkLatest: false
|
|
||||||
});
|
|
||||||
const actual = distribution['convertVersionToSemver'](input);
|
|
||||||
expect(actual).toBe(expected);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
import * as cache from '@actions/cache';
|
import * as cache from '@actions/cache';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import {isVersionSatisfies, isCacheFeatureAvailable} from '../src/util';
|
import {
|
||||||
|
convertVersionToSemver,
|
||||||
|
isVersionSatisfies,
|
||||||
|
isCacheFeatureAvailable
|
||||||
|
} from '../src/util';
|
||||||
|
|
||||||
jest.mock('@actions/cache');
|
jest.mock('@actions/cache');
|
||||||
jest.mock('@actions/core');
|
jest.mock('@actions/core');
|
||||||
@ -63,3 +67,16 @@ describe('isCacheFeatureAvailable', () => {
|
|||||||
expect(isCacheFeatureAvailable()).toBe(true);
|
expect(isCacheFeatureAvailable()).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('convertVersionToSemver', () => {
|
||||||
|
it.each([
|
||||||
|
['12', '12'],
|
||||||
|
['12.0', '12.0'],
|
||||||
|
['12.0.2', '12.0.2'],
|
||||||
|
['12.0.2.1', '12.0.2+1'],
|
||||||
|
['12.0.2.1.0', '12.0.2+1.0']
|
||||||
|
])('%s -> %s', (input: string, expected: string) => {
|
||||||
|
const actual = convertVersionToSemver(input);
|
||||||
|
expect(actual).toBe(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
12
dist/cleanup/index.js
vendored
12
dist/cleanup/index.js
vendored
@ -68785,7 +68785,7 @@ 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.getVersionFromFileContent = exports.isCacheFeatureAvailable = exports.isGhes = exports.isJobStatusSuccess = exports.getToolcachePath = exports.isVersionSatisfies = exports.getDownloadArchiveExtension = exports.extractJdkFile = exports.getVersionFromToolcachePath = exports.getBooleanInput = exports.getTempDir = void 0;
|
exports.convertVersionToSemver = exports.getVersionFromFileContent = exports.isCacheFeatureAvailable = exports.isGhes = exports.isJobStatusSuccess = exports.getToolcachePath = exports.isVersionSatisfies = exports.getDownloadArchiveExtension = exports.extractJdkFile = exports.getVersionFromToolcachePath = exports.getBooleanInput = exports.getTempDir = void 0;
|
||||||
const os_1 = __importDefault(__nccwpck_require__(2037));
|
const os_1 = __importDefault(__nccwpck_require__(2037));
|
||||||
const path_1 = __importDefault(__nccwpck_require__(1017));
|
const path_1 = __importDefault(__nccwpck_require__(1017));
|
||||||
const fs = __importStar(__nccwpck_require__(7147));
|
const fs = __importStar(__nccwpck_require__(7147));
|
||||||
@ -68912,6 +68912,16 @@ exports.getVersionFromFileContent = getVersionFromFileContent;
|
|||||||
function avoidOldNotation(content) {
|
function avoidOldNotation(content) {
|
||||||
return content.startsWith('1.') ? content.substring(2) : content;
|
return content.startsWith('1.') ? content.substring(2) : content;
|
||||||
}
|
}
|
||||||
|
function convertVersionToSemver(version) {
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
exports.convertVersionToSemver = convertVersionToSemver;
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
8628
dist/setup/index.js
vendored
8628
dist/setup/index.js
vendored
File diff suppressed because it is too large
Load Diff
@ -2,7 +2,11 @@ import * as core from '@actions/core';
|
|||||||
import * as tc from '@actions/tool-cache';
|
import * as tc from '@actions/tool-cache';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import {extractJdkFile, getDownloadArchiveExtension} from '../../util';
|
import {
|
||||||
|
extractJdkFile,
|
||||||
|
getDownloadArchiveExtension,
|
||||||
|
convertVersionToSemver
|
||||||
|
} from '../../util';
|
||||||
import {JavaBase} from '../base-installer';
|
import {JavaBase} from '../base-installer';
|
||||||
import {
|
import {
|
||||||
JavaDownloadRelease,
|
JavaDownloadRelease,
|
||||||
@ -62,7 +66,7 @@ export class CorrettoDistribution extends JavaBase {
|
|||||||
.filter(item => item.version == version)
|
.filter(item => item.version == version)
|
||||||
.map(item => {
|
.map(item => {
|
||||||
return {
|
return {
|
||||||
version: this.convertVersionToSemver(item.correttoVersion),
|
version: convertVersionToSemver(item.correttoVersion),
|
||||||
url: item.downloadLink
|
url: item.downloadLink
|
||||||
} as JavaDownloadRelease;
|
} as JavaDownloadRelease;
|
||||||
});
|
});
|
||||||
@ -179,15 +183,4 @@ export class CorrettoDistribution extends JavaBase {
|
|||||||
}
|
}
|
||||||
return match[1];
|
return match[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
private convertVersionToSemver(version: string) {
|
|
||||||
// corretto uses semver-like notation e.g. 17.0.6.10.1
|
|
||||||
const versionArray = version.split('.');
|
|
||||||
const mainVersion = versionArray.slice(0, 3).join('.');
|
|
||||||
if (versionArray.length > 3) {
|
|
||||||
return `${mainVersion}+${versionArray.slice(3).join('.')}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return mainVersion;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import {IZuluVersions} from './models';
|
|||||||
import {
|
import {
|
||||||
extractJdkFile,
|
extractJdkFile,
|
||||||
getDownloadArchiveExtension,
|
getDownloadArchiveExtension,
|
||||||
|
convertVersionToSemver,
|
||||||
isVersionSatisfies
|
isVersionSatisfies
|
||||||
} from '../../util';
|
} from '../../util';
|
||||||
import {
|
import {
|
||||||
@ -29,9 +30,9 @@ export class ZuluDistribution extends JavaBase {
|
|||||||
const availableVersionsRaw = await this.getAvailableVersions();
|
const availableVersionsRaw = await this.getAvailableVersions();
|
||||||
const availableVersions = availableVersionsRaw.map(item => {
|
const availableVersions = availableVersionsRaw.map(item => {
|
||||||
return {
|
return {
|
||||||
version: this.convertVersionToSemver(item.jdk_version),
|
version: convertVersionToSemver(item.jdk_version),
|
||||||
url: item.url,
|
url: item.url,
|
||||||
zuluVersion: this.convertVersionToSemver(item.zulu_version)
|
zuluVersion: convertVersionToSemver(item.zulu_version)
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -172,15 +173,4 @@ export class ZuluDistribution extends JavaBase {
|
|||||||
return process.platform;
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
10
src/util.ts
10
src/util.ts
@ -151,3 +151,13 @@ export function getVersionFromFileContent(
|
|||||||
function avoidOldNotation(content: string): string {
|
function avoidOldNotation(content: string): string {
|
||||||
return content.startsWith('1.') ? content.substring(2) : content;
|
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…
Reference in New Issue
Block a user