From 0ab9cadf3cd2f2cd1c4b88ba40a6169dc5b27717 Mon Sep 17 00:00:00 2001 From: Ar Rakin Date: Fri, 30 Aug 2024 15:10:51 +0600 Subject: [PATCH] fix(versioning): only increase version components once even if there are multiple commits Signed-off-by: Ar Rakin --- build/index.js | 34 +++++++++++++++++++++++------ src/VersionManager.ts | 50 +++++++++++++++++++++++++++++++++++++------ 2 files changed, 72 insertions(+), 12 deletions(-) diff --git a/build/index.js b/build/index.js index e8a2994..065633c 100644 --- a/build/index.js +++ b/build/index.js @@ -35654,6 +35654,9 @@ class VersionManager { "refactor", "perf", "test", + "ci", + "build", + "revert", ]; this.commits = []; } @@ -35689,6 +35692,7 @@ class VersionManager { let [type] = head.split(":"); let increased = false; let major = false; + let majorIncreased = false, minorIncreased = false, patchIncreased = false, prereleaseIncreased = false; const forcePrerelease = /\[(v\:)?(alpha|beta|rc|prerelease)\]/gi.test(commit.message); if (type.endsWith("!") || body.includes("BREAKING CHANGE:")) { type = type.slice(0, -1); @@ -35703,30 +35707,45 @@ class VersionManager { const buildMetadata = commit.message.match(/\nBuild-metadata: (.*)/i); const versionSuffix = commit.message.match(/\nVersion-suffix: (.*)/i); if (major) { - parsed.inc(forcePrerelease ? "premajor" : "major"); + if (!majorIncreased) { + parsed.inc(forcePrerelease ? "premajor" : "major"); + majorIncreased = true; + } classifiedCommits.breakingChanges.push(Object.assign(Object.assign({}, commit), { prerelease: forcePrerelease, type })); increased = true; } else { if (type === "feat") { - parsed.inc(forcePrerelease ? "preminor" : "minor"); + if (!minorIncreased && !majorIncreased) { + parsed.inc(forcePrerelease ? "preminor" : "minor"); + minorIncreased = true; + } classifiedCommits.features.push(Object.assign(Object.assign({}, commit), { prerelease: forcePrerelease, type })); increased = true; } if (type === "fix") { - parsed.inc(forcePrerelease ? "prepatch" : "patch"); + if (!patchIncreased && !minorIncreased && !majorIncreased) { + parsed.inc(forcePrerelease ? "prepatch" : "patch"); + patchIncreased = true; + } classifiedCommits.fixes.push(Object.assign(Object.assign({}, commit), { prerelease: forcePrerelease, type })); increased = true; } } if (forcePrerelease && !increased) { - parsed.inc("prerelease"); + if (!prereleaseIncreased) { + parsed.inc("prerelease"); + prereleaseIncreased = true; + } classifiedCommits.others.push(Object.assign(Object.assign({}, commit), { prerelease: true, type })); increased = true; } if (versionSuffix) { if (!increased) { - parsed.inc("prerelease"); + if (!prereleaseIncreased) { + parsed.inc("prerelease"); + prereleaseIncreased = true; + } classifiedCommits.others.push(Object.assign(Object.assign({}, commit), { prerelease: true, type })); increased = true; } @@ -35734,7 +35753,10 @@ class VersionManager { } if (buildMetadata) { if (!increased) { - parsed.inc("prerelease"); + if (!prereleaseIncreased) { + parsed.inc("prerelease"); + prereleaseIncreased = true; + } classifiedCommits.others.push(Object.assign(Object.assign({}, commit), { prerelease: true, type })); increased = true; } diff --git a/src/VersionManager.ts b/src/VersionManager.ts index 37bf1a5..346ee27 100644 --- a/src/VersionManager.ts +++ b/src/VersionManager.ts @@ -21,6 +21,9 @@ class VersionManager { "refactor", "perf", "test", + "ci", + "build", + "revert", ]; private commits: Commit[] = []; @@ -66,6 +69,11 @@ class VersionManager { let [type] = head.split(":"); let increased = false; let major = false; + let majorIncreased = false, + minorIncreased = false, + patchIncreased = false, + prereleaseIncreased = false; + const forcePrerelease = /\[(v\:)?(alpha|beta|rc|prerelease)\]/gi.test(commit.message); @@ -90,53 +98,78 @@ class VersionManager { ); if (major) { - parsed.inc(forcePrerelease ? "premajor" : "major"); + if (!majorIncreased) { + parsed.inc(forcePrerelease ? "premajor" : "major"); + majorIncreased = true; + } + classifiedCommits.breakingChanges.push({ ...commit, prerelease: forcePrerelease, type, }); + increased = true; } else { if (type === "feat") { - parsed.inc(forcePrerelease ? "preminor" : "minor"); + if (!minorIncreased && !majorIncreased) { + parsed.inc(forcePrerelease ? "preminor" : "minor"); + minorIncreased = true; + } + classifiedCommits.features.push({ ...commit, prerelease: forcePrerelease, type, }); + increased = true; } if (type === "fix") { - parsed.inc(forcePrerelease ? "prepatch" : "patch"); + if (!patchIncreased && !minorIncreased && !majorIncreased) { + parsed.inc(forcePrerelease ? "prepatch" : "patch"); + patchIncreased = true; + } + classifiedCommits.fixes.push({ ...commit, prerelease: forcePrerelease, type, }); + increased = true; } } if (forcePrerelease && !increased) { - parsed.inc("prerelease"); + if (!prereleaseIncreased) { + parsed.inc("prerelease"); + prereleaseIncreased = true; + } + classifiedCommits.others.push({ ...commit, prerelease: true, type, }); + increased = true; } if (versionSuffix) { if (!increased) { - parsed.inc("prerelease"); + if (!prereleaseIncreased) { + parsed.inc("prerelease"); + prereleaseIncreased = true; + } + classifiedCommits.others.push({ ...commit, prerelease: true, type, }); + increased = true; } @@ -145,12 +178,17 @@ class VersionManager { if (buildMetadata) { if (!increased) { - parsed.inc("prerelease"); + if (!prereleaseIncreased) { + parsed.inc("prerelease"); + prereleaseIncreased = true; + } + classifiedCommits.others.push({ ...commit, prerelease: true, type, }); + increased = true; }