diff --git a/__tests__/distributors/zulu-installer.test.ts b/__tests__/distributors/zulu-installer.test.ts index 701be2e1..f8b8a72c 100644 --- a/__tests__/distributors/zulu-installer.test.ts +++ b/__tests__/distributors/zulu-installer.test.ts @@ -227,22 +227,3 @@ describe('findPackageForDownload', () => { ).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); - }); -}); diff --git a/__tests__/util.test.ts b/__tests__/util.test.ts index 51de35af..bb7560dc 100644 --- a/__tests__/util.test.ts +++ b/__tests__/util.test.ts @@ -1,6 +1,10 @@ import * as cache from '@actions/cache'; 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/core'); @@ -63,3 +67,16 @@ describe('isCacheFeatureAvailable', () => { 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); + }); +}); diff --git a/dist/cleanup/index.js b/dist/cleanup/index.js index 62202e5a..d5ad1965 100644 --- a/dist/cleanup/index.js +++ b/dist/cleanup/index.js @@ -68786,7 +68786,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; 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 path_1 = __importDefault(__nccwpck_require__(1017)); const fs = __importStar(__nccwpck_require__(7147)); @@ -68913,6 +68913,16 @@ exports.getVersionFromFileContent = getVersionFromFileContent; function avoidOldNotation(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; /***/ }), diff --git a/dist/setup/index.js b/dist/setup/index.js index 3f6eccc1..e0a44244 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -104209,7 +104209,7 @@ class CorrettoDistribution extends base_installer_1.JavaBase { .filter(item => item.version == version) .map(item => { return { - version: item.correttoVersion, + version: util_1.convertVersionToSemver(item.correttoVersion), url: item.downloadLink }; }); @@ -105310,9 +105310,9 @@ class ZuluDistribution extends base_installer_1.JavaBase { const availableVersionsRaw = yield this.getAvailableVersions(); const availableVersions = availableVersionsRaw.map(item => { return { - version: this.convertVersionToSemver(item.jdk_version), + version: util_1.convertVersionToSemver(item.jdk_version), url: item.url, - zuluVersion: this.convertVersionToSemver(item.zulu_version) + zuluVersion: util_1.convertVersionToSemver(item.zulu_version) }; }); const satisfiedVersions = availableVersions @@ -105419,15 +105419,6 @@ class ZuluDistribution extends base_installer_1.JavaBase { return process.platform; } } - // Azul API returns jdk_version as array of digits like [11, 0, 2, 1] - convertVersionToSemver(version_array) { - 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; - } } exports.ZuluDistribution = ZuluDistribution; @@ -105843,7 +105834,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; 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 path_1 = __importDefault(__nccwpck_require__(1017)); const fs = __importStar(__nccwpck_require__(7147)); @@ -105970,6 +105961,16 @@ exports.getVersionFromFileContent = getVersionFromFileContent; function avoidOldNotation(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; /***/ }), diff --git a/src/distributions/corretto/installer.ts b/src/distributions/corretto/installer.ts index 38384cb7..1e6329cb 100644 --- a/src/distributions/corretto/installer.ts +++ b/src/distributions/corretto/installer.ts @@ -2,7 +2,11 @@ import * as core from '@actions/core'; import * as tc from '@actions/tool-cache'; import fs from 'fs'; import path from 'path'; -import {extractJdkFile, getDownloadArchiveExtension} from '../../util'; +import { + extractJdkFile, + getDownloadArchiveExtension, + convertVersionToSemver +} from '../../util'; import {JavaBase} from '../base-installer'; import { JavaDownloadRelease, @@ -62,7 +66,7 @@ export class CorrettoDistribution extends JavaBase { .filter(item => item.version == version) .map(item => { return { - version: item.correttoVersion, + version: convertVersionToSemver(item.correttoVersion), url: item.downloadLink } as JavaDownloadRelease; }); diff --git a/src/distributions/zulu/installer.ts b/src/distributions/zulu/installer.ts index dec9dbfe..c996bb8e 100644 --- a/src/distributions/zulu/installer.ts +++ b/src/distributions/zulu/installer.ts @@ -10,6 +10,7 @@ import {IZuluVersions} from './models'; import { extractJdkFile, getDownloadArchiveExtension, + convertVersionToSemver, isVersionSatisfies } from '../../util'; import { @@ -29,9 +30,9 @@ export class ZuluDistribution extends JavaBase { 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) }; }); @@ -172,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; - } } diff --git a/src/util.ts b/src/util.ts index acd9e6ea..fe1078d9 100644 --- a/src/util.ts +++ b/src/util.ts @@ -151,3 +151,13 @@ export function getVersionFromFileContent( 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; +}