Skip to content

Commit

Permalink
Integrate code review suggestions.
Browse files Browse the repository at this point in the history
  • Loading branch information
HHobeck committed Jan 26, 2024
1 parent e19c90a commit e8176a6
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 74 deletions.
46 changes: 22 additions & 24 deletions docs/input/docs/reference/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,22 @@ strategies:
- VersionInBranchName
branches:
develop:
mode: ContinuousDelivery
tracks-release-branches: true
is-release-branch: false
is-main-branch: false
pre-release-weight: 0
label: alpha
increment: Minor
prevent-increment-of-merged-branch-version: false
track-merge-target: true
regex: ^dev(elop)?(ment)?$
source-branches: []
is-source-branch-for: []
tracks-release-branches: true
is-release-branch: false
is-main-branch: false
pre-release-weight: 0
main:
mode: ContinuousDeployment
tracks-release-branches: false
is-release-branch: false
is-main-branch: true
pre-release-weight: 55000
label: ''
increment: Patch
prevent-increment-of-merged-branch-version: true
Expand All @@ -84,11 +86,12 @@ branches:
- develop
- release
is-source-branch-for: []
tracks-release-branches: false
is-release-branch: false
is-main-branch: true
pre-release-weight: 55000
release:
tracks-release-branches: false
is-release-branch: true
is-main-branch: false
pre-release-weight: 30000
mode: ManualDeployment
label: beta
increment: None
prevent-increment-of-merged-branch-version: true
Expand All @@ -100,11 +103,8 @@ branches:
- support
- release
is-source-branch-for: []
tracks-release-branches: false
is-release-branch: true
is-main-branch: false
pre-release-weight: 30000
feature:
pre-release-weight: 30000
mode: ManualDeployment
label: '{BranchName}'
increment: Inherit
Expand All @@ -117,8 +117,8 @@ branches:
- support
- hotfix
is-source-branch-for: []
pre-release-weight: 30000
pull-request:
pre-release-weight: 30000
mode: ContinuousDelivery
label: PullRequest
increment: Inherit
Expand All @@ -132,8 +132,9 @@ branches:
- support
- hotfix
is-source-branch-for: []
pre-release-weight: 30000
hotfix:
is-release-branch: true
pre-release-weight: 30000
mode: ManualDeployment
label: beta
increment: Inherit
Expand All @@ -144,9 +145,11 @@ branches:
- support
- hotfix
is-source-branch-for: []
is-release-branch: true
pre-release-weight: 30000
support:
tracks-release-branches: false
is-release-branch: false
is-main-branch: true
pre-release-weight: 55000
label: ''
increment: Patch
prevent-increment-of-merged-branch-version: true
Expand All @@ -155,10 +158,6 @@ branches:
source-branches:
- main
is-source-branch-for: []
tracks-release-branches: false
is-release-branch: false
is-main-branch: true
pre-release-weight: 55000
unknown:
mode: ManualDeployment
label: '{BranchName}'
Expand All @@ -175,7 +174,7 @@ branches:
is-source-branch-for: []
ignore:
sha: []
mode: ManualDeployment
mode: ContinuousDelivery
label: '{BranchName}'
increment: Inherit
prevent-increment-of-merged-branch-version: false
Expand All @@ -188,7 +187,6 @@ is-source-branch-for: []
tracks-release-branches: false
is-release-branch: false
is-main-branch: false

```
The details of the available options are as follows:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ strategies:
- VersionInBranchName
branches:
develop:
mode: ContinuousDelivery
label: alpha
increment: Minor
prevent-increment-of-merged-branch-version: false
Expand All @@ -32,7 +31,6 @@ branches:
is-main-branch: false
pre-release-weight: 0
main:
mode: ContinuousDelivery
label: ''
increment: Patch
prevent-increment-of-merged-branch-version: true
Expand All @@ -47,6 +45,7 @@ branches:
is-main-branch: true
pre-release-weight: 55000
release:
mode: ManualDeployment
label: beta
increment: None
prevent-increment-of-merged-branch-version: true
Expand Down Expand Up @@ -105,7 +104,6 @@ branches:
is-release-branch: true
pre-release-weight: 30000
support:
mode: ContinuousDelivery
label: ''
increment: Patch
prevent-increment-of-merged-branch-version: true
Expand Down Expand Up @@ -134,7 +132,7 @@ branches:
is-source-branch-for: []
ignore:
sha: []
mode: ManualDeployment
mode: ContinuousDelivery
label: '{BranchName}'
increment: Inherit
prevent-increment-of-merged-branch-version: false
Expand Down
25 changes: 9 additions & 16 deletions src/GitVersion.Configuration/ConfigurationBuilderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal abstract class ConfigurationBuilderBase<TConfigurationBuilder> : IConfi
private string? commitDateFormat;
private bool updateBuildNumber;
private SemanticVersionFormat semanticVersionFormat;
private VersionStrategies[] versionStrategies;
private VersionStrategies versionStrategy;
private Dictionary<string, string> mergeMessageFormats = new();
private readonly List<IReadOnlyDictionary<object, object?>> overrides = new();
private readonly Dictionary<string, BranchConfigurationBuilder> branchConfigurationBuilders = new();
Expand Down Expand Up @@ -200,20 +200,9 @@ public virtual TConfigurationBuilder WithSemanticVersionFormat(SemanticVersionFo
return (TConfigurationBuilder)this;
}

public virtual TConfigurationBuilder WithVersionStrategies(params VersionStrategies[] values)
=> WithVersionStrategies((IEnumerable<VersionStrategies>)values);

public virtual TConfigurationBuilder WithVersionStrategies(IEnumerable<VersionStrategies> values)
public virtual TConfigurationBuilder WithVersionStrategy(VersionStrategies value)
{
HashSet<VersionStrategies> versionStrategies = new();
foreach (var versionStrategy in values)
{
versionStrategies.AddRange(
Enum.GetValues<VersionStrategies>().Where(
element => element != VersionStrategies.None && versionStrategy.HasFlag(element))
);
}
this.versionStrategies = versionStrategies.ToArray();
this.versionStrategy = value;
return (TConfigurationBuilder)this;
}

Expand Down Expand Up @@ -339,7 +328,7 @@ public virtual TConfigurationBuilder WithConfiguration(IGitVersionConfiguration
WithCommitDateFormat(value.CommitDateFormat);
WithUpdateBuildNumber(value.UpdateBuildNumber);
WithSemanticVersionFormat(value.SemanticVersionFormat);
WithVersionStrategies(value.VersionStrategy);
WithVersionStrategy(value.VersionStrategy);
WithMergeMessageFormats(value.MergeMessageFormats);
foreach (var (name, branchConfiguration) in value.Branches)
{
Expand Down Expand Up @@ -377,6 +366,10 @@ public virtual IGitVersionConfiguration Build()
branches.Add(name, (BranchConfiguration)branchConfigurationBuilder.Build());
}

var versionStrategies = Enum.GetValues<VersionStrategies>()
.Where(element => element != VersionStrategies.None && this.versionStrategy.HasFlag(element))
.ToArray();

IGitVersionConfiguration configuration = new GitVersionConfiguration
{
AssemblyVersioningScheme = this.assemblyVersioningScheme,
Expand All @@ -396,7 +389,7 @@ public virtual IGitVersionConfiguration Build()
CommitDateFormat = this.commitDateFormat,
UpdateBuildNumber = this.updateBuildNumber,
SemanticVersionFormat = this.semanticVersionFormat,
VersionStrategies = this.versionStrategies,
VersionStrategies = versionStrategies,
Branches = branches,
MergeMessageFormats = this.mergeMessageFormats,
DeploymentMode = this.versioningMode,
Expand Down
38 changes: 12 additions & 26 deletions src/GitVersion.Configuration/SupportedWorkflows/TrunkBased/v1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,57 +10,43 @@ commit-date-format: yyyy-MM-dd
merge-message-formats: {}
update-build-number: true
semantic-version-format: Strict
strategies: [TrunkBased]
strategies: [TrunkBased, ConfigNextVersion]
branches:
main:
mode: ContinuousDeployment
label: ''
increment: Patch
prevent-increment-of-merged-branch-version: true
track-merge-target: false
regex: ^master$|^main$
source-branches:
- release
source-branches: []
tracks-release-branches: false
is-release-branch: false
is-main-branch: true
pre-release-weight: 55000
release:
label: beta
increment: None
prevent-increment-of-merged-branch-version: true
track-merge-target: false
regex: ^releases?[/-]
feature:
increment: Minor
regex: ^features?[/-](?<BranchName>.+)
source-branches:
- main
- release
tracks-release-branches: false
is-release-branch: true
is-main-branch: false
pre-release-weight: 30000
feature:
mode: ContinuousDelivery
label: '{BranchName}'
increment: Inherit
regex: ^features?[/-](?<BranchName>.+)
hotfix:
increment: Patch
regex: ^hotfix(es)?[/-](?<BranchName>.+)
source-branches:
- main
- release
- feature
pre-release-weight: 30000
pull-request:
mode: ContinuousDelivery
mode: ManualDeployment
label: PullRequest
increment: Inherit
label-number-pattern: '[/-](?<number>\d+)'
regex: ^(pull|pull\-requests|pr)[/-]
source-branches:
- main
- release
- feature
pre-release-weight: 30000
unknown:
mode: ContinuousDelivery
label: '{BranchName}'
mode: ManualDeployment
increment: Inherit
regex: (?<BranchName>.*)
source-branches:
Expand All @@ -70,7 +56,7 @@ branches:
- pull-request
ignore:
sha: []
mode: ContinuousDelivery
mode: ManualDeployment
label: '{BranchName}'
increment: Inherit
prevent-increment-of-merged-branch-version: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private static GitHubFlowConfigurationBuilder GetConfigurationBuilder() => GitHu
);

private static readonly IGitVersionConfiguration trunkBased = GetConfigurationBuilder()
.WithVersionStrategies(VersionStrategies.TrunkBased)
.WithVersionStrategy(VersionStrategies.TrunkBased)
.WithBranch("main", _ => _.WithIsMainBranch(true).WithDeploymentMode(DeploymentMode.ContinuousDeployment))
.WithBranch("feature", _ => _.WithIsMainBranch(false).WithDeploymentMode(DeploymentMode.ContinuousDelivery))
.Build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace GitVersion.Core.Tests.IntegrationTests;
public class TrunkBasedDevelopmentScenarios : TestBase
{
private static GitFlowConfigurationBuilder GetConfigurationBuilder() => GitFlowConfigurationBuilder.New
.WithVersionStrategies(VersionStrategies.TrunkBased)
.WithVersionStrategy(VersionStrategies.TrunkBased)
.WithBranch("main", builder => builder
.WithIsMainBranch(true).WithIncrement(IncrementStrategy.Patch)
.WithDeploymentMode(DeploymentMode.ContinuousDeployment)
Expand Down Expand Up @@ -511,7 +511,7 @@ public void MergingFeatureBranchThatIncrementsMinorNumberIncrementsMinorVersionO
public void VerifyIncrementConfigIsHonoured()
{
var minorIncrementConfig = GitFlowConfigurationBuilder.New
.WithVersionStrategies(VersionStrategies.TrunkBased)
.WithVersionStrategy(VersionStrategies.TrunkBased)
.WithBranch("main", builder => builder
.WithDeploymentMode(DeploymentMode.ContinuousDeployment)
.WithIncrement(IncrementStrategy.None)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void CanUseConventionalCommitsToBumpVersion(string commitMessage, string
.WithMinorVersionBumpMessage("^(feat)(\\([\\w\\s-]*\\))?:")
// For future debugging of this regex: https://regex101.com/r/oFpqxA/2
.WithPatchVersionBumpMessage("^(build|chore|ci|docs|fix|perf|refactor|revert|style|test)(\\([\\w\\s-]*\\))?:")
.WithVersionStrategies(VersionStrategies.TrunkBased)
.WithVersionStrategy(VersionStrategies.TrunkBased)
.WithBranch("main", builder => builder.WithDeploymentMode(DeploymentMode.ContinuousDeployment))
.Build();

Expand Down

0 comments on commit e8176a6

Please sign in to comment.