mirror of
https://github.com/PaulHatch/semantic-version.git
synced 2025-12-27 04:58:17 +00:00
Fix for bump each commit not respecting prerelease mode
This commit is contained in:
parent
61963e734d
commit
cfbfddabdd
5 changed files with 143 additions and 28 deletions
44
dist/index.js
vendored
44
dist/index.js
vendored
|
|
@ -698,6 +698,7 @@ const VersionType_1 = __nccwpck_require__(895);
|
||||||
class BumpAlwaysVersionClassifier extends DefaultVersionClassifier_1.DefaultVersionClassifier {
|
class BumpAlwaysVersionClassifier extends DefaultVersionClassifier_1.DefaultVersionClassifier {
|
||||||
constructor(config) {
|
constructor(config) {
|
||||||
super(config);
|
super(config);
|
||||||
|
this.enablePrereleaseMode = config.enablePrereleaseMode;
|
||||||
this.patchPattern = !config.bumpEachCommitPatchPattern ?
|
this.patchPattern = !config.bumpEachCommitPatchPattern ?
|
||||||
_ => true :
|
_ => true :
|
||||||
this.parsePattern(config.bumpEachCommitPatchPattern, "", config.searchCommitBody);
|
this.parsePattern(config.bumpEachCommitPatchPattern, "", config.searchCommitBody);
|
||||||
|
|
@ -715,30 +716,55 @@ class BumpAlwaysVersionClassifier extends DefaultVersionClassifier_1.DefaultVers
|
||||||
}
|
}
|
||||||
for (let commit of commitSet.commits.reverse()) {
|
for (let commit of commitSet.commits.reverse()) {
|
||||||
if (this.majorPattern(commit)) {
|
if (this.majorPattern(commit)) {
|
||||||
major += 1;
|
|
||||||
minor = 0;
|
|
||||||
patch = 0;
|
|
||||||
type = VersionType_1.VersionType.Major;
|
type = VersionType_1.VersionType.Major;
|
||||||
increment = 0;
|
|
||||||
}
|
}
|
||||||
else if (this.minorPattern(commit)) {
|
else if (this.minorPattern(commit)) {
|
||||||
minor += 1;
|
|
||||||
patch = 0;
|
|
||||||
type = VersionType_1.VersionType.Minor;
|
type = VersionType_1.VersionType.Minor;
|
||||||
increment = 0;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (this.patchPattern(commit) ||
|
if (this.patchPattern(commit) ||
|
||||||
(major === 0 && minor === 0 && patch === 0 && commitSet.commits.length > 0)) {
|
(major === 0 && minor === 0 && patch === 0 && commitSet.commits.length > 0)) {
|
||||||
patch += 1;
|
|
||||||
type = VersionType_1.VersionType.Patch;
|
type = VersionType_1.VersionType.Patch;
|
||||||
increment = 0;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
type = VersionType_1.VersionType.None;
|
type = VersionType_1.VersionType.None;
|
||||||
increment++;
|
increment++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (this.enablePrereleaseMode && major === 0) {
|
||||||
|
switch (type) {
|
||||||
|
case VersionType_1.VersionType.Major:
|
||||||
|
case VersionType_1.VersionType.Minor:
|
||||||
|
minor += 1;
|
||||||
|
patch = 0;
|
||||||
|
increment = 0;
|
||||||
|
break;
|
||||||
|
case VersionType_1.VersionType.Patch:
|
||||||
|
patch += 1;
|
||||||
|
increment = 0;
|
||||||
|
break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
switch (type) {
|
||||||
|
case VersionType_1.VersionType.Major:
|
||||||
|
major += 1;
|
||||||
|
minor = 0;
|
||||||
|
patch = 0;
|
||||||
|
increment = 0;
|
||||||
|
break;
|
||||||
|
case VersionType_1.VersionType.Minor:
|
||||||
|
minor += 1;
|
||||||
|
patch = 0;
|
||||||
|
break;
|
||||||
|
case VersionType_1.VersionType.Patch:
|
||||||
|
patch += 1;
|
||||||
|
increment = 0;
|
||||||
|
break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return new VersionClassification_1.VersionClassification(type, increment, true, major, minor, patch);
|
return new VersionClassification_1.VersionClassification(type, increment, true, major, minor, patch);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
|
|
@ -16,6 +16,7 @@ const VersionType_1 = require("./VersionType");
|
||||||
class BumpAlwaysVersionClassifier extends DefaultVersionClassifier_1.DefaultVersionClassifier {
|
class BumpAlwaysVersionClassifier extends DefaultVersionClassifier_1.DefaultVersionClassifier {
|
||||||
constructor(config) {
|
constructor(config) {
|
||||||
super(config);
|
super(config);
|
||||||
|
this.enablePrereleaseMode = config.enablePrereleaseMode;
|
||||||
this.patchPattern = !config.bumpEachCommitPatchPattern ?
|
this.patchPattern = !config.bumpEachCommitPatchPattern ?
|
||||||
_ => true :
|
_ => true :
|
||||||
this.parsePattern(config.bumpEachCommitPatchPattern, "", config.searchCommitBody);
|
this.parsePattern(config.bumpEachCommitPatchPattern, "", config.searchCommitBody);
|
||||||
|
|
@ -33,30 +34,55 @@ class BumpAlwaysVersionClassifier extends DefaultVersionClassifier_1.DefaultVers
|
||||||
}
|
}
|
||||||
for (let commit of commitSet.commits.reverse()) {
|
for (let commit of commitSet.commits.reverse()) {
|
||||||
if (this.majorPattern(commit)) {
|
if (this.majorPattern(commit)) {
|
||||||
major += 1;
|
|
||||||
minor = 0;
|
|
||||||
patch = 0;
|
|
||||||
type = VersionType_1.VersionType.Major;
|
type = VersionType_1.VersionType.Major;
|
||||||
increment = 0;
|
|
||||||
}
|
}
|
||||||
else if (this.minorPattern(commit)) {
|
else if (this.minorPattern(commit)) {
|
||||||
minor += 1;
|
|
||||||
patch = 0;
|
|
||||||
type = VersionType_1.VersionType.Minor;
|
type = VersionType_1.VersionType.Minor;
|
||||||
increment = 0;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (this.patchPattern(commit) ||
|
if (this.patchPattern(commit) ||
|
||||||
(major === 0 && minor === 0 && patch === 0 && commitSet.commits.length > 0)) {
|
(major === 0 && minor === 0 && patch === 0 && commitSet.commits.length > 0)) {
|
||||||
patch += 1;
|
|
||||||
type = VersionType_1.VersionType.Patch;
|
type = VersionType_1.VersionType.Patch;
|
||||||
increment = 0;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
type = VersionType_1.VersionType.None;
|
type = VersionType_1.VersionType.None;
|
||||||
increment++;
|
increment++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (this.enablePrereleaseMode && major === 0) {
|
||||||
|
switch (type) {
|
||||||
|
case VersionType_1.VersionType.Major:
|
||||||
|
case VersionType_1.VersionType.Minor:
|
||||||
|
minor += 1;
|
||||||
|
patch = 0;
|
||||||
|
increment = 0;
|
||||||
|
break;
|
||||||
|
case VersionType_1.VersionType.Patch:
|
||||||
|
patch += 1;
|
||||||
|
increment = 0;
|
||||||
|
break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
switch (type) {
|
||||||
|
case VersionType_1.VersionType.Major:
|
||||||
|
major += 1;
|
||||||
|
minor = 0;
|
||||||
|
patch = 0;
|
||||||
|
increment = 0;
|
||||||
|
break;
|
||||||
|
case VersionType_1.VersionType.Minor:
|
||||||
|
minor += 1;
|
||||||
|
patch = 0;
|
||||||
|
break;
|
||||||
|
case VersionType_1.VersionType.Patch:
|
||||||
|
patch += 1;
|
||||||
|
increment = 0;
|
||||||
|
break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return new VersionClassification_1.VersionClassification(type, increment, true, major, minor, patch);
|
return new VersionClassification_1.VersionClassification(type, increment, true, major, minor, patch);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1015,6 +1015,40 @@ test('Tagged commit is flagged as release', async () => {
|
||||||
}, timeout);
|
}, timeout);
|
||||||
|
|
||||||
|
|
||||||
|
test('Pre-release mode with bump each commit does not update major version if major version is 0', async () => {
|
||||||
|
const repo = createTestRepo({ tagPrefix: '', versionFormat: "${major}.${minor}.${patch}", enablePrereleaseMode: true, bumpEachCommit: true });
|
||||||
|
|
||||||
|
repo.makeCommit('Initial Commit');
|
||||||
|
expect((await repo.runAction()).formattedVersion).toBe('0.0.1');
|
||||||
|
repo.makeCommit('Second Commit (MINOR)');
|
||||||
|
expect((await repo.runAction()).formattedVersion).toBe('0.1.0');
|
||||||
|
repo.makeCommit('Third Commit (MAJOR)');
|
||||||
|
expect((await repo.runAction()).formattedVersion).toBe('0.2.0');
|
||||||
|
repo.exec('git tag 0.1.0');
|
||||||
|
repo.makeCommit('Fourth Commit (MAJOR)');
|
||||||
|
expect((await repo.runAction()).formattedVersion).toBe('0.2.0');
|
||||||
|
}, timeout);
|
||||||
|
|
||||||
|
test('Pre-release mode with bump each commit does not update major version if major version is 0, respecting patch pattern', async () => {
|
||||||
|
const repo = createTestRepo({
|
||||||
|
tagPrefix: '',
|
||||||
|
versionFormat: "${major}.${minor}.${patch}.${increment}",
|
||||||
|
enablePrereleaseMode: true,
|
||||||
|
bumpEachCommit: true,
|
||||||
|
bumpEachCommitPatchPattern: '(PATCH)',
|
||||||
|
});
|
||||||
|
|
||||||
|
repo.makeCommit('Initial Commit');
|
||||||
|
expect((await repo.runAction()).formattedVersion).toBe('0.0.1.0');
|
||||||
|
repo.makeCommit('Second Commit');
|
||||||
|
expect((await repo.runAction()).formattedVersion).toBe('0.0.1.1');
|
||||||
|
repo.makeCommit('Third Commit');
|
||||||
|
expect((await repo.runAction()).formattedVersion).toBe('0.0.1.2');
|
||||||
|
repo.makeCommit('Fourth Commit (MAJOR)');
|
||||||
|
expect((await repo.runAction()).formattedVersion).toBe('0.1.0.0');
|
||||||
|
}, timeout);
|
||||||
|
|
||||||
|
|
||||||
test('Highest tag is chosen when multiple tags are present', async () => {
|
test('Highest tag is chosen when multiple tags are present', async () => {
|
||||||
const repo = createTestRepo();
|
const repo = createTestRepo();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,12 @@ import { VersionType } from "./VersionType";
|
||||||
export class BumpAlwaysVersionClassifier extends DefaultVersionClassifier {
|
export class BumpAlwaysVersionClassifier extends DefaultVersionClassifier {
|
||||||
|
|
||||||
protected patchPattern: (commit: CommitInfo) => boolean;
|
protected patchPattern: (commit: CommitInfo) => boolean;
|
||||||
|
protected enablePrereleaseMode: boolean;
|
||||||
|
|
||||||
constructor(config: ActionConfig) {
|
constructor(config: ActionConfig) {
|
||||||
super(config);
|
super(config);
|
||||||
|
|
||||||
|
this.enablePrereleaseMode = config.enablePrereleaseMode;
|
||||||
this.patchPattern = !config.bumpEachCommitPatchPattern ?
|
this.patchPattern = !config.bumpEachCommitPatchPattern ?
|
||||||
_ => true :
|
_ => true :
|
||||||
this.parsePattern(config.bumpEachCommitPatchPattern, "", config.searchCommitBody);
|
this.parsePattern(config.bumpEachCommitPatchPattern, "", config.searchCommitBody);
|
||||||
|
|
@ -33,28 +35,55 @@ export class BumpAlwaysVersionClassifier extends DefaultVersionClassifier {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let commit of commitSet.commits.reverse()) {
|
for (let commit of commitSet.commits.reverse()) {
|
||||||
|
|
||||||
if (this.majorPattern(commit)) {
|
if (this.majorPattern(commit)) {
|
||||||
major += 1;
|
|
||||||
minor = 0;
|
|
||||||
patch = 0;
|
|
||||||
type = VersionType.Major;
|
type = VersionType.Major;
|
||||||
increment = 0;
|
|
||||||
} else if (this.minorPattern(commit)) {
|
} else if (this.minorPattern(commit)) {
|
||||||
minor += 1;
|
|
||||||
patch = 0;
|
|
||||||
type = VersionType.Minor;
|
type = VersionType.Minor;
|
||||||
increment = 0;
|
|
||||||
} else {
|
} else {
|
||||||
if (this.patchPattern(commit) ||
|
if (this.patchPattern(commit) ||
|
||||||
(major === 0 && minor === 0 && patch === 0 && commitSet.commits.length > 0)) {
|
(major === 0 && minor === 0 && patch === 0 && commitSet.commits.length > 0)) {
|
||||||
patch += 1;
|
|
||||||
type = VersionType.Patch;
|
type = VersionType.Patch;
|
||||||
increment = 0;
|
|
||||||
} else {
|
} else {
|
||||||
type = VersionType.None;
|
type = VersionType.None;
|
||||||
increment++;
|
increment++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.enablePrereleaseMode && major === 0) {
|
||||||
|
switch (type) {
|
||||||
|
case VersionType.Major:
|
||||||
|
case VersionType.Minor:
|
||||||
|
minor += 1;
|
||||||
|
patch = 0;
|
||||||
|
increment = 0;
|
||||||
|
break;
|
||||||
|
case VersionType.Patch:
|
||||||
|
patch += 1;
|
||||||
|
increment = 0;
|
||||||
|
break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
switch (type) {
|
||||||
|
case VersionType.Major:
|
||||||
|
major += 1;
|
||||||
|
minor = 0;
|
||||||
|
patch = 0;
|
||||||
|
increment = 0;
|
||||||
|
break;
|
||||||
|
case VersionType.Minor:
|
||||||
|
minor += 1;
|
||||||
|
patch = 0;
|
||||||
|
break;
|
||||||
|
case VersionType.Patch:
|
||||||
|
patch += 1;
|
||||||
|
increment = 0;
|
||||||
|
break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new VersionClassification(type, increment, true, major, minor, patch);
|
return new VersionClassification(type, increment, true, major, minor, patch);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue