Skip to content

Commit

Permalink
Corretto toolcache folder name fix (actions#480)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanZosimov authored and fniephaus committed Jun 20, 2023
1 parent 194ba74 commit e84709e
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 49 deletions.
19 changes: 0 additions & 19 deletions __tests__/distributors/zulu-installer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
19 changes: 18 additions & 1 deletion __tests__/util.test.ts
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -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);
});
});
12 changes: 11 additions & 1 deletion dist/cleanup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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;


/***/ }),
Expand Down
27 changes: 14 additions & 13 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
});
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;


/***/ }),
Expand Down
8 changes: 6 additions & 2 deletions src/distributions/corretto/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
});
Expand Down
16 changes: 3 additions & 13 deletions src/distributions/zulu/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {IZuluVersions} from './models';
import {
extractJdkFile,
getDownloadArchiveExtension,
convertVersionToSemver,
isVersionSatisfies
} from '../../util';
import {
Expand All @@ -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)
};
});

Expand Down Expand Up @@ -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;
}
}
10 changes: 10 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit e84709e

Please sign in to comment.