Skip to content

Implement SemVer strict parsing #3131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion docs/input/docs/reference/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ branches:

Strategy which will look for tagged merge commits directly off the current
branch. For example `develop` → `release/1.0.0` → merge into `main` and tag
`1.0.0`. The tag is *not* on develop, but develop should be version `1.0.0` now.
`1.0.0`. The tag is _not_ on develop, but develop should be version `1.0.0` now.

### tracks-release-branches

Expand Down Expand Up @@ -551,6 +551,19 @@ is set, it would be added to the `PreReleaseNumber` to get a final
`pre-release-weight` will be used in the calculation. Related Issues [1145]
and [1366].

### semver-format

Specifies the semver format that is used when parsing the string.
Can be `Strict` - using the [regex](https://regex101.com/r/Ly7O1x/3/)
or `Loose` the old way of parsing. The default if not specified is `Strict`
Example of invalid `Strict`, but valid `Loose`

```
1.2-alpha4
01.02.03-rc03
1.2.3.4
```

[1145]: https://github.com/GitTools/GitVersion/issues/1145
[1366]: https://github.com/GitTools/GitVersion/issues/1366
[2506]: https://github.com/GitTools/GitVersion/pull/2506#issuecomment-754754037
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersion.Core.Tests/Core/GitVersionExecutorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public void ConfigChangeInvalidatesCache()
versionVariables.AssemblySemVer.ShouldBe("4.10.3.0");

var configPath = PathHelper.Combine(fixture.RepositoryPath, ConfigFileLocator.DefaultFileName);
this.fileSystem.WriteAllText(configPath, "next-version: 5.0");
this.fileSystem.WriteAllText(configPath, "next-version: 5.0.0");

gitVersionCalculator = GetGitVersionCalculator(gitVersionOptions, fs: this.fileSystem);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public TestEffectiveConfiguration(
isRelease,
commitDateFormat,
updateBuildNumber,
SemanticVersionFormat.Strict,
0,
0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public void BranchVersionHavePrecedenceOverTagVersionIfVersionGreaterThanTag()
fixture.Checkout("develop");
fixture.MakeATaggedCommit("0.1.0-alpha.1"); // simulate merge from feature branch

fixture.Repository.CreateBranch("release/1.0");
fixture.Checkout("release/1.0");
fixture.Repository.CreateBranch("release/1.0.0");
fixture.Checkout("release/1.0.0");

fixture.AssertFullSemver("1.0.0-beta.1+0");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public void ShouldPickUpVersionFromDevelopAfterReleaseBranchCreated()
fixture.MakeACommit();
fixture.BranchTo("develop");
fixture.MakeACommit();
fixture.BranchTo("release/1.0");
fixture.BranchTo("release/1.0.0");
fixture.MakeACommit();
fixture.Checkout("develop");
fixture.MakeACommit();
Expand All @@ -282,12 +282,12 @@ public void ShouldPickUpVersionFromDevelopAfterReleaseBranchMergedBack()
fixture.MakeACommit();
fixture.BranchTo("develop");
fixture.MakeACommit();
fixture.BranchTo("release/1.0");
fixture.BranchTo("release/1.0.0");
fixture.MakeACommit();

// merge release into develop
fixture.Checkout("develop");
fixture.MergeNoFF("release/1.0");
fixture.MergeNoFF("release/1.0.0");
fixture.AssertFullSemver("1.1.0-alpha.2");

// create a feature branch from develop and verify the version
Expand Down Expand Up @@ -317,7 +317,7 @@ public void ShouldPickUpVersionFromMainAfterReleaseBranchCreated()
using var fixture = new EmptyRepositoryFixture();
// Create release branch
fixture.MakeACommit();
fixture.BranchTo("release/1.0");
fixture.BranchTo("release/1.0.0");
fixture.MakeACommit();
fixture.Checkout(MainBranch);
fixture.MakeACommit();
Expand Down Expand Up @@ -348,12 +348,12 @@ public void ShouldPickUpVersionFromMainAfterReleaseBranchMergedBack()
using var fixture = new EmptyRepositoryFixture();
// Create release branch
fixture.MakeACommit();
fixture.BranchTo("release/1.0");
fixture.BranchTo("release/1.0.0");
fixture.MakeACommit();

// merge release into main
fixture.Checkout(MainBranch);
fixture.MergeNoFF("release/1.0");
fixture.MergeNoFF("release/1.0.0");
fixture.AssertFullSemver("1.0.1+2", config);

// create a feature branch from main and verify the version
Expand All @@ -372,7 +372,7 @@ public void ShouldPickUpVersionFromMainAfterReleaseBranchCreated()
fixture.MakeACommit();
fixture.BranchTo("develop");
fixture.MakeACommit();
fixture.BranchTo("release/1.0");
fixture.BranchTo("release/1.0.0");
fixture.MakeACommit();
fixture.Checkout("develop");
fixture.MakeACommit();
Expand All @@ -391,12 +391,12 @@ public void ShouldPickUpVersionFromDevelopAfterReleaseBranchMergedBack()
fixture.MakeACommit();
fixture.BranchTo("develop");
fixture.MakeACommit();
fixture.BranchTo("release/1.0");
fixture.BranchTo("release/1.0.0");
fixture.MakeACommit();

// merge release into develop
fixture.Checkout("develop");
fixture.MergeNoFF("release/1.0");
fixture.MergeNoFF("release/1.0.0");
fixture.AssertFullSemver("1.1.0-alpha.2");

// create a misnamed feature branch (i.e. it uses the default config) from develop and verify the version
Expand Down Expand Up @@ -427,7 +427,7 @@ public void ShouldPickUpVersionFromMainAfterReleaseBranchCreated()
using var fixture = new EmptyRepositoryFixture();
// Create release branch
fixture.MakeACommit();
fixture.BranchTo("release/1.0");
fixture.BranchTo("release/1.0.0");
fixture.MakeACommit();
fixture.Checkout(MainBranch);
fixture.MakeACommit();
Expand Down Expand Up @@ -458,12 +458,12 @@ public void ShouldPickUpVersionFromMainAfterReleaseBranchMergedBack()
using var fixture = new EmptyRepositoryFixture();
// Create release branch
fixture.MakeACommit();
fixture.BranchTo("release/1.0");
fixture.BranchTo("release/1.0.0");
fixture.MakeACommit();

// merge release into main
fixture.Checkout(MainBranch);
fixture.MergeNoFF("release/1.0");
fixture.MergeNoFF("release/1.0.0");
fixture.AssertFullSemver("1.0.1+2", config);

// create a misnamed feature branch (i.e. it uses the default config) from main and verify the version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,11 +485,11 @@ public static void ReleaseBranchShouldUseBranchNameVersionDespiteBumpInPreviousC
public void ReleaseBranchWithACommitShouldUseBranchNameVersionDespiteBumpInPreviousCommit()
{
using var fixture = new EmptyRepositoryFixture();
fixture.Repository.MakeATaggedCommit("1.0");
fixture.Repository.MakeATaggedCommit("1.0.0");
fixture.Repository.MakeACommit("+semver:major");
fixture.Repository.MakeACommit();

fixture.BranchTo("release/2.0");
fixture.BranchTo("release/2.0.0");

fixture.Repository.MakeACommit();

Expand All @@ -500,10 +500,10 @@ public void ReleaseBranchWithACommitShouldUseBranchNameVersionDespiteBumpInPrevi
public void ReleaseBranchedAtCommitWithSemverMessageShouldUseBranchNameVersion()
{
using var fixture = new EmptyRepositoryFixture();
fixture.Repository.MakeATaggedCommit("1.0");
fixture.Repository.MakeATaggedCommit("1.0.0");
fixture.Repository.MakeACommit("+semver:major");

fixture.BranchTo("release/2.0");
fixture.BranchTo("release/2.0.0");

fixture.AssertFullSemver("2.0.0-beta.1+1");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void GivenARemoteGitRepositoryWithCommitsThenClonedLocalShouldMatchRemote
[Test]
public void GivenARemoteGitRepositoryWithCommitsAndBranchesThenClonedLocalShouldMatchRemoteVersion()
{
const string targetBranch = "release-1.0";
const string targetBranch = "release-1.0.0";
using var fixture = new RemoteRepositoryFixture(
path =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public void WhenDevelopBranchedFromMainWithLegacyVersionTagsDevelopCanUseReachab
{
using var fixture = new EmptyRepositoryFixture();
fixture.Repository.MakeCommits(5);
fixture.Repository.MakeATaggedCommit("1.0.0.0");
fixture.Repository.MakeATaggedCommit("1.0.0");
fixture.Repository.MakeCommits(2);
Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("develop"));
fixture.AssertFullSemver("1.1.0-alpha.2");
Expand Down
26 changes: 13 additions & 13 deletions src/GitVersion.Core.Tests/Model/MergeMessageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public void EmptyTagPrefix(string prefix)
new object?[] { "Merge branch 'origin/feature/one'", "origin/feature/one", null, null },
new object?[] { $"Merge tag 'v4.0.0' into {MainBranch}", "v4.0.0", MainBranch, new SemanticVersion(4) },
new object?[] { $"Merge tag 'V4.0.0' into {MainBranch}", "V4.0.0", MainBranch, new SemanticVersion(4) },
new object?[] { "Merge branch 'feature/4.1/one'", "feature/4.1/one", null, new SemanticVersion(4, 1) },
new object?[] { "Merge branch 'origin/4.1/feature/one'", "origin/4.1/feature/one", null, new SemanticVersion(4, 1) },
new object?[] { "Merge branch 'feature/4.1.0/one'", "feature/4.1.0/one", null, new SemanticVersion(4, 1) },
new object?[] { "Merge branch 'origin/4.1.0/feature/one'", "origin/4.1.0/feature/one", null, new SemanticVersion(4, 1) },
new object?[] { $"Merge tag 'v://10.10.10.10' into {MainBranch}", "v://10.10.10.10", MainBranch, null }
};

Expand Down Expand Up @@ -86,7 +86,7 @@ public void ParsesMergeMessage(
new object?[] { "Merge pull request #1234 in feature/one", "feature/one", null, null, 1234 },
new object?[] { "Merge pull request #1234 in v4.0.0", "v4.0.0", null, new SemanticVersion(4), 1234 },
new object?[] { "Merge pull request #1234 from origin/feature/one", "origin/feature/one", null, null, 1234 },
new object?[] { "Merge pull request #1234 in feature/4.1/one", "feature/4.1/one", null, new SemanticVersion(4,1), 1234 },
new object?[] { "Merge pull request #1234 in feature/4.1.0/one", "feature/4.1.0/one", null, new SemanticVersion(4,1), 1234 },
new object?[] { "Merge pull request #1234 in V://10.10.10.10", "V://10.10.10.10", null, null, 1234 },
new object?[] { "Merge pull request #1234 from feature/one into dev", "feature/one", "dev", null, 1234 }
};
Expand Down Expand Up @@ -116,8 +116,8 @@ public void ParsesGitHubPullMergeMessage(
new object?[] { "Merge pull request #1234 from feature/one from feature/two to dev", "feature/two", "dev", null, 1234 },
new object?[] { "Merge pull request #1234 in feature/one from feature/two to dev", "feature/two", "dev", null, 1234 },
new object?[] { "Merge pull request #1234 in v4.0.0 from v4.1.0 to dev", "v4.1.0", "dev", new SemanticVersion(4,1), 1234 },
new object?[] { "Merge pull request #1234 from origin/feature/one from origin/feature/4.2/two to dev", "origin/feature/4.2/two", "dev", new SemanticVersion(4,2), 1234 },
new object?[] { "Merge pull request #1234 in feature/4.1/one from feature/4.2/two to dev", "feature/4.2/two", "dev", new SemanticVersion(4,2), 1234 },
new object?[] { "Merge pull request #1234 from origin/feature/one from origin/feature/4.2.0/two to dev", "origin/feature/4.2.0/two", "dev", new SemanticVersion(4,2), 1234 },
new object?[] { "Merge pull request #1234 in feature/4.1.0/one from feature/4.2.0/two to dev", "feature/4.2.0/two", "dev", new SemanticVersion(4,2), 1234 },
new object?[] { $"Merge pull request #1234 from feature/one from feature/two to {MainBranch}" , "feature/two", MainBranch, null, 1234 },
new object?[] { "Merge pull request #1234 in V4.1.0 from V://10.10.10.10 to dev", "V://10.10.10.10", "dev", null, 1234 },
//TODO: Investigate successful bitbucket merge messages that may be invalid
Expand Down Expand Up @@ -147,11 +147,11 @@ public void ParsesBitBucketPullMergeMessage(

private static readonly object[] BitBucketPullMergeMessages_v7 =
{
new object[] { $@"Pull request #68: Release/2.2
new object[] { $@"Pull request #68: Release/2.2.0

Merge in aaa/777 from release/2.2 to {MainBranch}
Merge in aaa/777 from release/2.2.0 to {MainBranch}

* commit '750aa37753dec1a85b22cc16db851187649d9e97':", "release/2.2", MainBranch, new SemanticVersion(2,2), 68 }
* commit '750aa37753dec1a85b22cc16db851187649d9e97':", "release/2.2.0", MainBranch, new SemanticVersion(2,2), 68 }
};

[TestCaseSource(nameof(BitBucketPullMergeMessages_v7))]
Expand Down Expand Up @@ -179,8 +179,8 @@ public void ParsesBitBucketPullMergeMessage_v7(
new object?[] { "Finish feature/one", "feature/one", null, null },
new object?[] { "Finish origin/feature/one", "origin/feature/one", null, null },
new object?[] { "Finish v4.0.0", "v4.0.0", null, new SemanticVersion(4) },
new object?[] { "Finish feature/4.1/one", "feature/4.1/one", null, new SemanticVersion(4, 1) },
new object?[] { "Finish origin/4.1/feature/one", "origin/4.1/feature/one", null, new SemanticVersion(4, 1) },
new object?[] { "Finish feature/4.1.0/one", "feature/4.1.0/one", null, new SemanticVersion(4, 1) },
new object?[] { "Finish origin/4.1.0/feature/one", "origin/4.1.0/feature/one", null, new SemanticVersion(4, 1) },
new object?[] { "Finish V://10.10.10.10", "V://10.10.10.10", null, null },
new object?[] { $"Finish V4.0.0 into {MainBranch}", "V4.0.0", MainBranch, new SemanticVersion(4) }
};
Expand Down Expand Up @@ -210,8 +210,8 @@ public void ParsesSmartGitMergeMessage(
new object?[] { "Merge remote-tracking branch 'origin/feature/one' into dev", "origin/feature/one", "dev", null },
new object?[] { $"Merge remote-tracking branch 'v4.0.0' into {MainBranch}", "v4.0.0", MainBranch, new SemanticVersion(4) },
new object?[] { $"Merge remote-tracking branch 'V4.0.0' into {MainBranch}", "V4.0.0", MainBranch, new SemanticVersion(4) },
new object?[] { "Merge remote-tracking branch 'feature/4.1/one' into dev", "feature/4.1/one", "dev", new SemanticVersion(4, 1) },
new object?[] { $"Merge remote-tracking branch 'origin/4.1/feature/one' into {MainBranch}", "origin/4.1/feature/one", MainBranch, new SemanticVersion(4, 1) },
new object?[] { "Merge remote-tracking branch 'feature/4.1.0/one' into dev", "feature/4.1.0/one", "dev", new SemanticVersion(4, 1) },
new object?[] { $"Merge remote-tracking branch 'origin/4.1.0/feature/one' into {MainBranch}", "origin/4.1.0/feature/one", MainBranch, new SemanticVersion(4, 1) },
new object?[] { $"Merge remote-tracking branch 'v://10.10.10.10' into {MainBranch}", "v://10.10.10.10", MainBranch, null }
};

Expand Down Expand Up @@ -321,7 +321,7 @@ public void MatchesCaptureGroupsFromCustomMessages()
};
const int pr = 1234;
const string target = MainBranch;
const string source = "feature/2.0/example";
const string source = "feature/2.0.0/example";

// Act
var sut = new MergeMessage($"Merged PR #{pr} into {target} from {source}", this.config);
Expand Down
Loading