Skip to content

Commit 464c7ce

Browse files
authored
Merge pull request #2553 from AlexGoris-KasparSolutions/conventional-commits
Docs: Describe configuration for using Conventional commits
2 parents f908a57 + 045b9fe commit 464c7ce

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

docs/input/docs/more-info/version-increments.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,20 @@ One thing to be aware of: If the current version is an alpha-version
8484
(eg from 0.2.0 to 0.3.0 instead of 1.0.0). Once the current version is greater
8585
than 1.0.0, bumping the major version works as expected.
8686

87+
#### Conventional commit messages
88+
89+
If you want to use the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/)
90+
standard, you can leverage this feature as follows:
91+
92+
```yaml
93+
mode: MainLine # Only add this if you want every version to be created automatically on your main branch.
94+
major-version-bump-message: "(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\\([\\w\\s]*\\))?(!:|:.*\\n\\n.*\\n\\n.*BREAKING.*).*"
95+
minor-version-bump-message: "(feat)(\\([\\w\\s]*\\))?:"
96+
patch-version-bump-message: "(build|chore|ci|docs|fix|perf|refactor|revert|style|test)(\\([\\w\\s]*\\))?:(.*\\n\\n.*\\n\\n.*BREAKING.*){0}"
97+
```
98+
99+
This will ensure that your version gets bumped according to the commits you've created.
100+
87101
### GitVersion.yml
88102

89103
The first is by setting the `next-version` property in the GitVersion.yml file.

src/GitVersion.Core.Tests/IntegrationTests/VersionBumpingScenarios.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,50 @@ public void CanUseCommitMessagesToBumpVersion()
4848
fixture.AssertFullSemver("2.0.0+2");
4949
}
5050

51+
[Test]
52+
public void CanUseConventionalCommitsToBumpVersion()
53+
{
54+
var configuration = new Config
55+
{
56+
VersioningMode = GitVersion.VersionCalculation.VersioningMode.Mainline,
57+
58+
// For future debugging of this regex: https://regex101.com/r/UfzIwS/1
59+
MajorVersionBumpMessage = "(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\\([\\w\\s]*\\))?(!:|:.*\\n\\n.*\\n\\n.*BREAKING.*).*",
60+
61+
// For future debugging of this regex: https://regex101.com/r/9ccNam/1
62+
MinorVersionBumpMessage = "(feat)(\\([\\w\\s]*\\))?:",
63+
64+
// For future debugging of this regex: https://regex101.com/r/ALKccf/1
65+
PatchVersionBumpMessage = "(build|chore|ci|docs|fix|perf|refactor|revert|style|test)(\\([\\w\\s]*\\))?:(.*\\n\\n.*\\n\\n.*BREAKING.*){0}"
66+
};
67+
using var fixture = new EmptyRepositoryFixture();
68+
fixture.Repository.MakeACommit();
69+
fixture.MakeATaggedCommit("1.0.0");
70+
71+
fixture.Repository.MakeACommit("feat(Api): Added some new endpoints");
72+
fixture.AssertFullSemver("1.1.0", configuration);
73+
74+
// This tests if adding an exclamation mark after the type (breaking change) bumps the major version
75+
fixture.Repository.MakeACommit("feat(Api)!: Changed existing API models");
76+
fixture.AssertFullSemver("2.0.0", configuration);
77+
78+
// This tests if writing BREAKING CHANGE in the footer bumps the major version
79+
fixture.Repository.MakeACommit("feat: Changed existing API models\n\nSome more descriptive text\n\nBREAKING CHANGE");
80+
fixture.AssertFullSemver("3.0.0", configuration);
81+
82+
fixture.Repository.MakeACommit("chore: Cleaned up various things");
83+
fixture.AssertFullSemver("3.0.1", configuration);
84+
85+
fixture.Repository.MakeACommit("chore: Cleaned up more various things");
86+
fixture.AssertFullSemver("3.0.2", configuration);
87+
88+
fixture.Repository.MakeACommit("feat: Added some new functionality");
89+
fixture.AssertFullSemver("3.1.0", configuration);
90+
91+
fixture.Repository.MakeACommit("feat: Added even more new functionality");
92+
fixture.AssertFullSemver("3.2.0", configuration);
93+
}
94+
5195
[Test]
5296
public void CanUseCommitMessagesToBumpVersionBaseVersionTagIsAppliedToSameCommit()
5397
{

0 commit comments

Comments
 (0)