ci: Fix version comparison bug
Auto-publishing had a version comparison bug, causing it to attempt to republish old versions instead using next avaiable version number.
This commit is contained in:
parent
fbac14cd08
commit
994853bf8e
2 changed files with 22 additions and 4 deletions
|
|
@ -94,6 +94,14 @@ function getCurrentVersion(packagePath) {
|
|||
return packageJson.version;
|
||||
}
|
||||
|
||||
function compareVersions(a, b) {
|
||||
const [aMajor, aMinor, aPatch] = a.split('.').map(Number);
|
||||
const [bMajor, bMinor, bPatch] = b.split('.').map(Number);
|
||||
if (aMajor !== bMajor) return aMajor - bMajor;
|
||||
if (aMinor !== bMinor) return aMinor - bMinor;
|
||||
return aPatch - bPatch;
|
||||
}
|
||||
|
||||
function bumpVersion(currentVersion, latestNpmVersion) {
|
||||
const [major, minor, patch] = currentVersion.split('.').map(Number);
|
||||
|
||||
|
|
@ -102,12 +110,13 @@ function bumpVersion(currentVersion, latestNpmVersion) {
|
|||
}
|
||||
|
||||
const [npmMajor, npmMinor, npmPatch] = latestNpmVersion.split('.').map(Number);
|
||||
const cmp = compareVersions(currentVersion, latestNpmVersion);
|
||||
|
||||
if (currentVersion > latestNpmVersion) {
|
||||
if (cmp > 0) {
|
||||
return `${major}.${minor}.${patch + 1}`;
|
||||
}
|
||||
|
||||
if (latestNpmVersion > currentVersion) {
|
||||
if (cmp < 0) {
|
||||
return `${npmMajor}.${npmMinor}.${npmPatch + 1}`;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -78,6 +78,14 @@ function getCurrentVersion(packagePath) {
|
|||
return packageJson.version;
|
||||
}
|
||||
|
||||
function compareVersions(a, b) {
|
||||
const [aMajor, aMinor, aPatch] = a.split('.').map(Number);
|
||||
const [bMajor, bMinor, bPatch] = b.split('.').map(Number);
|
||||
if (aMajor !== bMajor) return aMajor - bMajor;
|
||||
if (aMinor !== bMinor) return aMinor - bMinor;
|
||||
return aPatch - bPatch;
|
||||
}
|
||||
|
||||
function bumpVersion(currentVersion, latestNpmVersion) {
|
||||
const [major, minor, patch] = currentVersion.split('.').map(Number);
|
||||
|
||||
|
|
@ -86,12 +94,13 @@ function bumpVersion(currentVersion, latestNpmVersion) {
|
|||
}
|
||||
|
||||
const [npmMajor, npmMinor, npmPatch] = latestNpmVersion.split('.').map(Number);
|
||||
const cmp = compareVersions(currentVersion, latestNpmVersion);
|
||||
|
||||
if (currentVersion > latestNpmVersion) {
|
||||
if (cmp > 0) {
|
||||
return `${major}.${minor}.${patch + 1}`;
|
||||
}
|
||||
|
||||
if (latestNpmVersion > currentVersion) {
|
||||
if (cmp < 0) {
|
||||
return `${npmMajor}.${npmMinor}.${npmPatch + 1}`;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue