Skip to content

Commit 9bf23f5

Browse files
authored
fix: semver sort the releases latest first before picking the first non-draft of the relevant channel (#6838)
semver sort the releases latest first before picking the first non-draft of the relevant channel
1 parent 6c76b79 commit 9bf23f5

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

packages/hadron-build/commands/upload.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const path = require('path');
1010
const os = require('os');
1111
const { promises: fs } = require('fs');
1212
const { deepStrictEqual } = require('assert');
13+
const semver = require('semver');
1314
const { Octokit } = require('@octokit/rest');
1415
const { GithubRepo } = require('@mongodb-js/devtools-github-repo');
1516
const { diffString } = require('json-diff');
@@ -253,7 +254,7 @@ async function getLatestRelease(channel = 'stable') {
253254
auth: process.env.GITHUB_TOKEN,
254255
});
255256

256-
const page = 1;
257+
let page = 1;
257258

258259
// eslint-disable-next-line no-constant-condition
259260
while (true) {
@@ -279,14 +280,24 @@ async function getLatestRelease(channel = 'stable') {
279280
return null;
280281
}
281282

282-
const latestRelease = releases.find((release) => {
283-
return (
284-
!release.draft &&
285-
(channel === 'beta'
286-
? isBeta(release.tag_name)
287-
: isStable(release.tag_name))
288-
);
289-
});
283+
const latestRelease = releases
284+
.sort((a, b) => {
285+
if (semver.lt(a.tag_name, b.tag_name)) {
286+
return 1;
287+
}
288+
if (semver.gt(a.tag_name, b.tag_name)) {
289+
return -1;
290+
}
291+
return 0;
292+
})
293+
.find((release) => {
294+
return (
295+
!release.draft &&
296+
(channel === 'beta'
297+
? isBeta(release.tag_name)
298+
: isStable(release.tag_name))
299+
);
300+
});
290301

291302
if (latestRelease) {
292303
return latestRelease;

0 commit comments

Comments
 (0)