Skip to content

Commit

Permalink
fix: first part of version number sorting (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
ReenigneArcher authored Jan 2, 2025
1 parent 5cf1637 commit 7b6584c
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,20 @@ runs:
// sort by tag/version number (e.g. v1.2.3 or v1.2.3.4)
preReleases.sort((a, b) => {
const aParts = a.tag_name.split('.').map(Number);
const bParts = b.tag_name.split('.').map(Number);
const aParts = a.tag_name.match(/\d+/g).map(Number);
const bParts = b.tag_name.match(/\d+/g).map(Number);
for (let i = 0; i < Math.max(aParts.length, bParts.length); i++) {
if (aParts[i] === undefined) return -1;
if (bParts[i] === undefined) return 1;
if (aParts[i] < bParts[i]) return -1;
if (aParts[i] > bParts[i]) return 1;
if (aParts[i] === undefined) return -1;
if (bParts[i] === undefined) return 1;
if (aParts[i] < bParts[i]) return -1;
if (aParts[i] > bParts[i]) return 1;
}
return 0;
});
// Output sorted pre-releases
console.log('Sorted Pre-release tags:', preReleases.map(release => release.tag_name));
// delete all but the last n pre-releases
for (let i = 0; i < preReleases.length - KEEP_LATEST; i++) {
const release = preReleases[i];
Expand Down

0 comments on commit 7b6584c

Please sign in to comment.