Skip to content

Commit

Permalink
Implement prevent-increment-when-tagged and consolidat logic in NextV…
Browse files Browse the repository at this point in the history
…ersionCalculator.
  • Loading branch information
HHobeck committed Feb 15, 2024
1 parent eeb0f0e commit 7c10519
Show file tree
Hide file tree
Showing 70 changed files with 1,198 additions and 946 deletions.
217 changes: 207 additions & 10 deletions docs/input/docs/reference/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,19 @@ created. Modify this to suit your needs.

## Global configuration

The global configuration looks like this:
Following supported workflow configurations are available in GitVersion and can be referenced by the workflow property:
- GitFlow (GitFlow/v1)
- GitHubFlow (GitHubFlow/v1) and
- TrunkBased (TrunkBased/v1)

Example of using a TrunkBased workflow with a different tag-prefix:

```yaml
workflow: TrunkBased/v1
tag-prefix: '[abc]'
```
The build-in configuration for the `GitFlow` workflow (`workflow: GitFlow/v1`) looks like:

```yaml
assembly-versioning-scheme: MajorMinorPatch
Expand All @@ -61,10 +73,10 @@ strategies:
- VersionInBranchName
branches:
develop:
take-incremented-version: TakeAlwaysIncrementedVersion
label: alpha
increment: Minor
prevent-increment-of-merged-branch-version: false
prevent-increment-when-tagged: false
track-merge-target: true
regex: ^dev(elop)?(ment)?$
source-branches: []
Expand All @@ -89,10 +101,10 @@ branches:
pre-release-weight: 55000
release:
mode: ManualDeployment
take-incremented-version: TakeAlwaysIncrementedVersion
label: beta
increment: None
prevent-increment-of-merged-branch-version: true
prevent-increment-when-tagged: false
track-merge-target: false
regex: ^releases?[/-]
source-branches:
Expand Down Expand Up @@ -138,6 +150,7 @@ branches:
mode: ManualDeployment
label: beta
increment: Inherit
prevent-increment-when-tagged: false
regex: ^hotfix(es)?[/-]
source-branches:
- release
Expand Down Expand Up @@ -177,10 +190,10 @@ branches:
ignore:
sha: []
mode: ContinuousDelivery
take-incremented-version: TakeTaggedOtherwiseIncrementedVersion
label: '{BranchName}'
increment: Inherit
prevent-increment-of-merged-branch-version: false
prevent-increment-when-tagged: true
track-merge-target: false
track-merge-message: true
commit-message-incrementing: Enabled
Expand All @@ -192,11 +205,195 @@ is-release-branch: false
is-main-branch: false
```

The supported build-in configuration for the `GitHubFlow` workflow (`workflow: GitHubFlow/v1`) looks like:

```yaml
assembly-versioning-scheme: MajorMinorPatch
assembly-file-versioning-scheme: MajorMinorPatch
tag-prefix: '[vV]?'
version-in-branch-pattern: (?<version>[vV]?\d+(\.\d+)?(\.\d+)?).*
major-version-bump-message: '\+semver:\s?(breaking|major)'
minor-version-bump-message: '\+semver:\s?(feature|minor)'
patch-version-bump-message: '\+semver:\s?(fix|patch)'
no-bump-message: '\+semver:\s?(none|skip)'
tag-pre-release-weight: 60000
commit-date-format: yyyy-MM-dd
merge-message-formats: {}
update-build-number: true
semantic-version-format: Strict
strategies:
- ConfiguredNextVersion
- MergeMessage
- TaggedCommit
- TrackReleaseBranches
- VersionInBranchName
branches:
main:
label: ''
increment: Patch
prevent-increment-of-merged-branch-version: true
track-merge-target: false
regex: ^master$|^main$
source-branches:
- release
is-source-branch-for: []
tracks-release-branches: false
is-release-branch: false
is-main-branch: true
pre-release-weight: 55000
release:
mode: ManualDeployment
label: beta
increment: None
prevent-increment-of-merged-branch-version: true
prevent-increment-when-tagged: false
track-merge-target: false
regex: ^releases?[/-]
source-branches:
- main
- release
is-source-branch-for: []
tracks-release-branches: false
is-release-branch: true
is-main-branch: false
pre-release-weight: 30000
feature:
mode: ManualDeployment
label: '{BranchName}'
increment: Inherit
regex: ^features?[/-](?<BranchName>.+)
source-branches:
- main
- release
- feature
is-source-branch-for: []
pre-release-weight: 30000
pull-request:
mode: ContinuousDelivery
label: PullRequest
increment: Inherit
label-number-pattern: '[/-](?<number>\d+)'
regex: ^(pull|pull\-requests|pr)[/-]
source-branches:
- main
- release
- feature
is-source-branch-for: []
pre-release-weight: 30000
unknown:
mode: ManualDeployment
label: '{BranchName}'
increment: Inherit
regex: (?<BranchName>.+)
source-branches:
- main
- release
- feature
- pull-request
is-source-branch-for: []
ignore:
sha: []
mode: ContinuousDelivery
label: '{BranchName}'
increment: Inherit
prevent-increment-of-merged-branch-version: false
prevent-increment-when-tagged: true
track-merge-target: false
track-merge-message: true
commit-message-incrementing: Enabled
regex: ''
source-branches: []
is-source-branch-for: []
tracks-release-branches: false
is-release-branch: false
is-main-branch: false
```

The supported build-in configuration for the `TrunkBased` workflow (`workflow: TrunkBased/v1`) looks like:

```yaml
assembly-versioning-scheme: MajorMinorPatch
assembly-file-versioning-scheme: MajorMinorPatch
tag-prefix: '[vV]?'
version-in-branch-pattern: (?<version>[vV]?\d+(\.\d+)?(\.\d+)?).*
major-version-bump-message: '\+semver:\s?(breaking|major)'
minor-version-bump-message: '\+semver:\s?(feature|minor)'
patch-version-bump-message: '\+semver:\s?(fix|patch)'
no-bump-message: '\+semver:\s?(none|skip)'
tag-pre-release-weight: 60000
commit-date-format: yyyy-MM-dd
merge-message-formats: {}
update-build-number: true
semantic-version-format: Strict
strategies:
- TrunkBased
- ConfiguredNextVersion
branches:
main:
mode: ContinuousDeployment
label: ''
increment: Patch
prevent-increment-of-merged-branch-version: true
track-merge-target: false
regex: ^master$|^main$
source-branches: []
tracks-release-branches: false
is-release-branch: false
is-main-branch: true
pre-release-weight: 55000
feature:
increment: Minor
regex: ^features?[/-](?<BranchName>.+)
prevent-increment-when-tagged: false
source-branches:
- main
pre-release-weight: 30000
hotfix:
increment: Patch
regex: ^hotfix(es)?[/-](?<BranchName>.+)
prevent-increment-when-tagged: false
source-branches:
- main
pre-release-weight: 30000
pull-request:
mode: ManualDeployment
label: PullRequest
increment: Inherit
label-number-pattern: '[/-](?<number>\d+)'
regex: ^(pull|pull\-requests|pr)[/-]
source-branches:
- main
pre-release-weight: 30000
unknown:
mode: ManualDeployment
increment: Inherit
regex: (?<BranchName>.+)
source-branches:
- main
- release
- feature
- pull-request
ignore:
sha: []
mode: ManualDeployment
label: '{BranchName}'
increment: Inherit
prevent-increment-of-merged-branch-version: false
prevent-increment-when-tagged: true
track-merge-target: false
track-merge-message: true
commit-message-incrementing: Enabled
regex: ''
tracks-release-branches: false
is-release-branch: false
is-main-branch: false
```

The details of the available options are as follows:

### workflow

The base template of the configuration to use. Possible values are: GitFlow/v1 or GitHubFlow/v1
The base template of the configuration to use. Possible values are: GitFlow/v1 or GitHubFlow/v1 or TrunkBased/v1. Defaults to GitFlow/v1 if not set.

### next-version

Expand Down Expand Up @@ -266,10 +463,6 @@ The default value is `{InformationalVersion}`.
Sets the `mode` of how GitVersion should create a new version. Read more at
[deployment modes][modes].

### take-incremented-version

This branch related property can be used to control the behavior weither to take the incremented or the tagged version.

### increment

The part of the SemVer to increment when GitVersion detects it needs to be
Expand Down Expand Up @@ -612,6 +805,10 @@ In a GitFlow-based repository, setting this option can have implications on the
better version source proposed by the `MergeMessageBaseVersionStrategy`. For
more details and an in-depth analysis, please see [the discussion][2506].

### prevent-increment-when-tagged

This branch related property can be used to control the behavior weither to take the incremented or the current tagged version.

### label-number-pattern

Pull requests require us to extract the pre-release number out of the branch
Expand Down Expand Up @@ -706,4 +903,4 @@ Specifies which version strategy implementation (one ore more) will be used to d
* TaggedCommit
* TrackReleaseBranches
* VersionInBranchName
* TrunkBased
* TrunkBased
1 change: 0 additions & 1 deletion src/GitVersion.App.Tests/GitVersion.App.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
<Compile Include="..\GitVersion.Core.Tests\Helpers\DirectoryHelper.cs" Link="Helpers\DirectoryHelper.cs" />
<Compile Include="..\GitVersion.Core.Tests\Helpers\ExecutableHelper.cs" Link="Helpers\ExecutableHelper.cs" />
<Compile Include="..\GitVersion.Core.Tests\Helpers\TestConsoleAdapter.cs" Link="Helpers\TestConsoleAdapter.cs" />
<Compile Include="..\GitVersion.Core.Tests\Helpers\TestEffectiveConfiguration.cs" Link="Helpers\TestEffectiveConfiguration.cs" />
<Compile Include="..\GitVersion.Core.Tests\Helpers\TestEnvironment.cs" Link="Helpers\TestEnvironment.cs" />
<Compile Include="..\GitVersion.Core.Tests\Helpers\TestFileSystem.cs" Link="Helpers\TestFileSystem.cs" />
<Compile Include="..\GitVersion.Core.Tests\Helpers\TestLogAppender.cs" Link="Helpers\TestLogAppender.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using GitVersion.Configuration;
using GitVersion.Core.Tests.Helpers;
using GitVersion.Helpers;
using GitVersion.VersionCalculation;
Expand Down Expand Up @@ -144,10 +145,9 @@ private void AssertVariablesAreWrittenToFile(string propertyFile, string ps1File
BuildMetaData = new SemanticVersionBuildMetaData("5") { Sha = "f28807e615e9f06aec8a33c87780374e0c1f6fb8", CommitDate = new DateTimeOffset(2022, 4, 6, 16, 10, 59, TimeSpan.FromHours(10)) }
};

var configuration = new TestEffectiveConfiguration();
var variableProvider = this.sp.GetRequiredService<IVariableProvider>();

var variables = variableProvider.GetVariablesFor(semanticVersion, configuration, null);
var variables = variableProvider.GetVariablesFor(semanticVersion, new GitVersionConfiguration(), 0);

this.buildServer.WithPropertyFile(propertyFile);
this.buildServer.WithPowershellFile(ps1File);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using GitVersion.Configuration;
using GitVersion.Core.Tests.Helpers;
using GitVersion.Logging;
using GitVersion.OutputVariables;
Expand Down Expand Up @@ -36,9 +37,7 @@ public void BuildNumberIsFullSemVer()
}
};

var configuration = new TestEffectiveConfiguration();

var variables = this.buildServer.GetVariablesFor(semanticVersion, configuration, null);
var variables = this.buildServer.GetVariablesFor(semanticVersion, new GitVersionConfiguration(), 0);
var buildAgent = this.sp.GetRequiredService<BuildAgent>();
buildAgent.WriteIntegration(writes.Add, variables);

Expand Down
5 changes: 2 additions & 3 deletions src/GitVersion.BuildAgents.Tests/Agents/CodeBuildTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using GitVersion.Configuration;
using GitVersion.Core.Tests.Helpers;
using GitVersion.Helpers;
using GitVersion.VersionCalculation;
Expand Down Expand Up @@ -81,11 +82,9 @@ private void AssertVariablesAreWrittenToFile(string file)
}
};

var configuration = new TestEffectiveConfiguration();

var variableProvider = this.sp.GetRequiredService<IVariableProvider>();

var variables = variableProvider.GetVariablesFor(semanticVersion, configuration, null);
var variables = variableProvider.GetVariablesFor(semanticVersion, new GitVersionConfiguration(), 0);

this.buildServer.WithPropertyFile(file);

Expand Down
10 changes: 7 additions & 3 deletions src/GitVersion.BuildAgents.Tests/Agents/GitLabCiTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using GitVersion.Configuration;
using GitVersion.Core.Tests.Helpers;
using GitVersion.Helpers;
using GitVersion.VersionCalculation;
Expand Down Expand Up @@ -59,13 +60,16 @@ private void AssertVariablesAreWrittenToFile(string file)
Minor = 2,
Patch = 3,
PreReleaseTag = "beta1",
BuildMetaData = new SemanticVersionBuildMetaData("5") { Sha = "commitSha", CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z") }
BuildMetaData = new SemanticVersionBuildMetaData("5")
{
Sha = "commitSha",
CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z")
}
};

var configuration = new TestEffectiveConfiguration();
var variableProvider = this.sp.GetRequiredService<IVariableProvider>();

var variables = variableProvider.GetVariablesFor(semanticVersion, configuration, null);
var variables = variableProvider.GetVariablesFor(semanticVersion, new GitVersionConfiguration(), 0);

this.buildServer.WithPropertyFile(file);

Expand Down
5 changes: 2 additions & 3 deletions src/GitVersion.BuildAgents.Tests/Agents/JenkinsTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using GitVersion.Configuration;
using GitVersion.Core.Tests.Helpers;
using GitVersion.Helpers;
using GitVersion.VersionCalculation;
Expand Down Expand Up @@ -133,11 +134,9 @@ private void AssertVariablesAreWrittenToFile(string file)
BuildMetaData = new SemanticVersionBuildMetaData("5") { Sha = "commitSha", CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z") }
};

var configuration = new TestEffectiveConfiguration();

var variableProvider = this.sp.GetRequiredService<IVariableProvider>();

var variables = variableProvider.GetVariablesFor(semanticVersion, configuration, null);
var variables = variableProvider.GetVariablesFor(semanticVersion, new GitVersionConfiguration(), 0);

this.buildServer.WithPropertyFile(file);

Expand Down
Loading

0 comments on commit 7c10519

Please sign in to comment.