Skip to content

Commit 9051c81

Browse files
brunoborgesCopilot
andcommitted
Address Copilot review feedback for Kona distribution
- Sort matching releases by semver descending so range versions (e.g. >=17) resolve to the newest matching Kona JDK instead of the lowest - Rename downloaded archive on Windows before extraction (renameWinArchive) to avoid extraction failures - Import semver for version sorting Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent e8aa5c4 commit 9051c81

2 files changed

Lines changed: 22 additions & 9 deletions

File tree

‎dist/setup/index.js‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79652,6 +79652,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
7965279652
exports.KonaDistribution = void 0;
7965379653
const core = __importStar(__nccwpck_require__(37484));
7965479654
const tc = __importStar(__nccwpck_require__(33472));
79655+
const semver_1 = __importDefault(__nccwpck_require__(62088));
7965579656
const fs_1 = __importDefault(__nccwpck_require__(79896));
7965679657
const path_1 = __importDefault(__nccwpck_require__(16928));
7965779658
const base_installer_1 = __nccwpck_require__(79935);
@@ -79666,11 +79667,14 @@ class KonaDistribution extends base_installer_1.JavaBase {
7966679667
const javaArchivePath = yield tc.downloadTool(javaRelease.url);
7966779668
core.info(`Extracting Java archive...`);
7966879669
const extension = (0, util_1.getDownloadArchiveExtension)();
79669-
const extractedJavaPath = yield (0, util_1.extractJdkFile)(javaArchivePath, extension);
79670+
const archivePath = process.platform === 'win32'
79671+
? (0, util_1.renameWinArchive)(javaArchivePath)
79672+
: javaArchivePath;
79673+
const extractedJavaPath = yield (0, util_1.extractJdkFile)(archivePath, extension);
7967079674
const archiveName = fs_1.default.readdirSync(extractedJavaPath)[0];
79671-
const archivePath = path_1.default.join(extractedJavaPath, archiveName);
79675+
const jdkDirectory = path_1.default.join(extractedJavaPath, archiveName);
7967279676
const version = this.getToolcacheVersionName(javaRelease.version);
79673-
const javaPath = yield tc.cacheDir(archivePath, this.toolcacheFolderName, version, this.architecture);
79677+
const javaPath = yield tc.cacheDir(jdkDirectory, this.toolcacheFolderName, version, this.architecture);
7967479678
return { version: javaRelease.version, path: javaPath };
7967579679
});
7967679680
}
@@ -79692,7 +79696,8 @@ class KonaDistribution extends base_installer_1.JavaBase {
7969279696
version: item.version,
7969379697
url: item.downloadUrl
7969479698
};
79695-
});
79699+
})
79700+
.sort((a, b) => -semver_1.default.compareBuild(a.version, b.version));
7969679701
if (!releases.length) {
7969779702
throw new Error(`No Kona release for the specified version "${version}" on OS "${this.getOs()}" and arch "${this.getArch()}".`);
7969879703
}
@@ -79711,6 +79716,7 @@ class KonaDistribution extends base_installer_1.JavaBase {
7971179716
const availableReleases = this.chooseReleases(this.getOs(), this.getArch(), releaseInfo);
7971279717
if (core.isDebug()) {
7971379718
core.startGroup('Print information about available releases');
79719+
console.timeEnd('Retrieving available releases for Kona took'); // eslint-disable-line no-console
7971479720
core.debug(availableReleases.map(item => item.version).join(', '));
7971579721
core.endGroup();
7971679722
}

‎src/distributions/kona/installer.ts‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as core from '@actions/core';
22
import * as tc from '@actions/tool-cache';
3+
import semver from 'semver';
34

45
import fs from 'fs';
56
import path from 'path';
@@ -14,7 +15,8 @@ import {
1415
import {
1516
extractJdkFile,
1617
getDownloadArchiveExtension,
17-
isVersionSatisfies
18+
isVersionSatisfies,
19+
renameWinArchive
1820
} from '../../util';
1921

2022
export class KonaDistribution extends JavaBase {
@@ -33,14 +35,18 @@ export class KonaDistribution extends JavaBase {
3335
core.info(`Extracting Java archive...`);
3436

3537
const extension = getDownloadArchiveExtension();
36-
const extractedJavaPath = await extractJdkFile(javaArchivePath, extension);
38+
const archivePath =
39+
process.platform === 'win32'
40+
? renameWinArchive(javaArchivePath)
41+
: javaArchivePath;
42+
const extractedJavaPath = await extractJdkFile(archivePath, extension);
3743

3844
const archiveName = fs.readdirSync(extractedJavaPath)[0];
39-
const archivePath = path.join(extractedJavaPath, archiveName);
45+
const jdkDirectory = path.join(extractedJavaPath, archiveName);
4046
const version = this.getToolcacheVersionName(javaRelease.version);
4147

4248
const javaPath = await tc.cacheDir(
43-
archivePath,
49+
jdkDirectory,
4450
this.toolcacheFolderName,
4551
version,
4652
this.architecture
@@ -70,7 +76,8 @@ export class KonaDistribution extends JavaBase {
7076
version: item.version,
7177
url: item.downloadUrl
7278
} as JavaDownloadRelease;
73-
});
79+
})
80+
.sort((a, b) => -semver.compareBuild(a.version, b.version));
7481

7582
if (!releases.length) {
7683
throw new Error(

0 commit comments

Comments
 (0)