Skip to content

Commit

Permalink
fix(versioning): only increase version components once even if there …
Browse files Browse the repository at this point in the history
…are multiple commits

Signed-off-by: Ar Rakin <rakinar2@onesoftnet.eu.org>
  • Loading branch information
virtual-designer committed Aug 30, 2024
1 parent dd9e0d7 commit 0ab9cad
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 12 deletions.
34 changes: 28 additions & 6 deletions build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35654,6 +35654,9 @@ class VersionManager {
"refactor",
"perf",
"test",
"ci",
"build",
"revert",
];
this.commits = [];
}
Expand Down Expand Up @@ -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);
Expand All @@ -35703,38 +35707,56 @@ 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;
}
suffix = versionSuffix[1].split(".");
}
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;
}
Expand Down
50 changes: 44 additions & 6 deletions src/VersionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class VersionManager {
"refactor",
"perf",
"test",
"ci",
"build",
"revert",
];

private commits: Commit[] = [];
Expand Down Expand Up @@ -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);

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down

0 comments on commit 0ab9cad

Please sign in to comment.