Skip to content

Commit 19b97e5

Browse files
authored
Merge pull request #3235 from HHobeck/feature/2388_root-configuration-should-propoagate-branches
Create new fallback and unknown section in GitVersionConfiguration an…
2 parents 5f40019 + 28d075c commit 19b97e5

File tree

73 files changed

+1479
-1613
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+1479
-1613
lines changed

BREAKING_CHANGES.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,22 @@
66
* Instead of having a single effective configuration, we now have one effective configuration per branch where the increment strategy is not set to `inherit`.
77
* The new implementation of the branch configuration inheritance affects per default only the pull-requests, hotfix and feature branches. In this case the next version will be generated like the child branch is not existing and the commits have been made on the source branch.
88
* The following example illustrates this behavior. On the feature branch the semantic version `1.1.0-just-a-test.1+2` will now be generated instead of version `1.0.0-just-a-test.1+3` previously:
9-
```
9+
```
1010
* 1f1cfb4 52 minutes ago (HEAD -> feature/just-a-test)
11-
* 1f9654d 54 minutes ago (release/1.1.0)
12-
* be72411 56 minutes ago (develop)
13-
* 14800ff 58 minutes ago (tag: 1.0.0, main)
14-
```
11+
* 1f9654d 54 minutes ago (release/1.1.0)
12+
* be72411 56 minutes ago (develop)
13+
* 14800ff 58 minutes ago (tag: 1.0.0, main)
14+
```
15+
* A new `unknown` branch magic string has been introduced to give the user the possibility to specify the branch configuration for a branch which is not known. A branch is not known if only the regular expression of the branch configuration with the name `unknown` is matching. Please notice that this branch configuration behaves like any other branch configurations.
16+
* Additional `fallback` branch configuration properties have been introduced at the root to define base properties which will be inherit to the branch configurations. That means if no other branch configuration in the inheritance line defines the given property the fallback property applies. Notice that the inheritance tree can be controlled using the increment strategy property in the branch configuration section.
17+
* The following example illustrates this behavior. The hotfix branch configuration overrides the main branch configuration and the result overrides the fallback branch configuration.
18+
```
19+
* 1f1cfb4 52 minutes ago (HEAD -> hotfix/just-a-test)
20+
* 14800ff 58 minutes ago (tag: 1.0.0, main)
21+
```
22+
* When overriding the configuration with e.g. GitVersion.yaml the software distinguishes between properties who are not existent and properties who are `null`. This is especially important if the user wants to define branch related configuration which are marked with `increment` strategy `Inherit`.
23+
* Following root configuration properties have been removed:
24+
* continuous-delivery-fallback-tag
1525
1626
## v5.0.0
1727

docs/input/docs/reference/configuration.md

Lines changed: 123 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,134 @@ created. Modify this to suit your needs.
4040
The global configuration looks like this:
4141

4242
```yaml
43-
next-version: 1.0
4443
assembly-versioning-scheme: MajorMinorPatch
4544
assembly-file-versioning-scheme: MajorMinorPatch
46-
assembly-informational-format: '{InformationalVersion}'
47-
mode: ContinuousDelivery
48-
increment: Inherit
49-
continuous-delivery-fallback-label: ci
50-
label-prefix: '[vV]'
45+
label-prefix: '[vV]?'
5146
major-version-bump-message: '\+semver:\s?(breaking|major)'
5247
minor-version-bump-message: '\+semver:\s?(feature|minor)'
5348
patch-version-bump-message: '\+semver:\s?(fix|patch)'
5449
no-bump-message: '\+semver:\s?(none|skip)'
5550
label-pre-release-weight: 60000
56-
commit-message-incrementing: Enabled
57-
ignore:
58-
sha: []
59-
commits-before: yyyy-MM-ddTHH:mm:ss
51+
commit-date-format: yyyy-MM-dd
6052
merge-message-formats: {}
6153
update-build-number: true
54+
semantic-version-format: Strict
55+
branches:
56+
develop:
57+
mode: ContinuousDeployment
58+
label: alpha
59+
increment: Minor
60+
prevent-increment-of-merged-branch-version: false
61+
track-merge-target: true
62+
regex: ^dev(elop)?(ment)?$
63+
source-branches: []
64+
tracks-release-branches: true
65+
is-release-branch: false
66+
is-mainline: false
67+
pre-release-weight: 0
68+
main:
69+
label: ''
70+
increment: Patch
71+
prevent-increment-of-merged-branch-version: true
72+
track-merge-target: false
73+
regex: ^master$|^main$
74+
source-branches:
75+
- develop
76+
- release
77+
tracks-release-branches: false
78+
is-release-branch: false
79+
is-mainline: true
80+
pre-release-weight: 55000
81+
release:
82+
label: beta
83+
increment: None
84+
prevent-increment-of-merged-branch-version: true
85+
track-merge-target: false
86+
regex: ^releases?[/-]
87+
source-branches:
88+
- develop
89+
- main
90+
- support
91+
- release
92+
tracks-release-branches: false
93+
is-release-branch: true
94+
is-mainline: false
95+
pre-release-weight: 30000
96+
feature:
97+
mode: ContinuousDelivery
98+
label: '{BranchName}'
99+
increment: Inherit
100+
regex: ^features?[/-]
101+
source-branches:
102+
- develop
103+
- main
104+
- release
105+
- feature
106+
- support
107+
- hotfix
108+
pre-release-weight: 30000
109+
pull-request:
110+
mode: ContinuousDelivery
111+
label: PullRequest
112+
increment: Inherit
113+
label-number-pattern: '[/-](?<number>\d+)'
114+
regex: ^(pull|pull\-requests|pr)[/-]
115+
source-branches:
116+
- develop
117+
- main
118+
- release
119+
- feature
120+
- support
121+
- hotfix
122+
pre-release-weight: 30000
123+
hotfix:
124+
mode: ContinuousDelivery
125+
label: beta
126+
increment: Inherit
127+
regex: ^hotfix(es)?[/-]
128+
source-branches:
129+
- release
130+
- main
131+
- support
132+
- hotfix
133+
pre-release-weight: 30000
134+
support:
135+
label: ''
136+
increment: Patch
137+
prevent-increment-of-merged-branch-version: true
138+
track-merge-target: false
139+
regex: ^support[/-]
140+
source-branches:
141+
- main
142+
tracks-release-branches: false
143+
is-release-branch: false
144+
is-mainline: true
145+
pre-release-weight: 55000
146+
unknown:
147+
mode: ContinuousDelivery
148+
label: '{BranchName}'
149+
increment: Inherit
150+
regex: .*
151+
source-branches:
152+
- main
153+
- develop
154+
- release
155+
- feature
156+
- pull-request
157+
- hotfix
158+
- support
159+
ignore:
160+
sha: []
161+
mode: ContinuousDelivery
162+
label: '{BranchName}'
163+
increment: Inherit
164+
prevent-increment-of-merged-branch-version: false
165+
track-merge-target: false
166+
commit-message-incrementing: Enabled
167+
regex: ''
168+
tracks-release-branches: false
169+
is-release-branch: false
170+
is-mainline: false
62171
```
63172
64173
The details of the available options are as follows:
@@ -142,25 +251,6 @@ for [increment](#increment),
142251
[prevent-increment-of-merged-branch-version](#prevent-increment-of-merged-branch-version)
143252
and [tracks-release-branches](#tracks-release-branches).
144253

145-
### continuous-delivery-fallback-label
146-
147-
When using `mode: ContinuousDeployment`, the value specified in
148-
`continuous-delivery-fallback-label` will be used as the pre-release label for
149-
branches which do not have one specified. Default set to `ci`.
150-
151-
Just to clarify: For a build name without `...-ci-<buildnumber>` or in other
152-
words without a `PreReleaseTag` (ergo `"PreReleaseTag":""` in GitVersion's JSON output)
153-
at the end you would need to set `continuous-delivery-fallback-label` to an empty
154-
string (`''`):
155-
156-
```yaml
157-
mode: ContinuousDeployment
158-
continuous-delivery-fallback-label: ''
159-
...
160-
```
161-
162-
Doing so can be helpful if you use your `main` branch as a `release` branch.
163-
164254
### label-prefix
165255

166256
A regex which is used to trim Git tags before processing (e.g., v1.0.0). Default
@@ -200,7 +290,7 @@ The pre-release weight in case of tagged commits. If the value is not set in the
200290
configuration, a default weight of 60000 is used instead. If the
201291
`WeightedPreReleaseNumber` [variable][variables] is 0 and this parameter is set,
202292
its value is used. This helps if your branching model is GitFlow and the last
203-
release build, which is often tagged, can utilise this parameter to produce a
293+
release build, which is often tagged, can utilize this parameter to produce a
204294
monotonically increasing build number.
205295

206296
### commit-message-incrementing
@@ -441,7 +531,7 @@ Without this configuration value you would have to do:
441531
```yaml
442532
branches:
443533
unstable:
444-
regex: ...
534+
regex:
445535
feature:
446536
source-branches: ['unstable', 'develop', 'feature', 'hotfix', 'support']
447537
release:
@@ -539,9 +629,9 @@ is set, it would be added to the `PreReleaseNumber` to get a final
539629
`pre-release-weight` will be used in the calculation. Related Issues [1145][1145]
540630
and [1366][1366].
541631

542-
### semver-format
632+
### semantic-version-format
543633

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

docs/input/docs/usage/cli/arguments.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ Following options are supported:
117117
5. `assembly-versioning-scheme`
118118
7. `commit-date-format`
119119
8. `commit-message-incrementing`
120-
10. `continuous-delivery-fallback-label`
120+
10. `label`
121121
11. `increment`
122122
13. `major-version-bump-message`
123123
14. `minor-version-bump-message`

src/GitVersion.App.Tests/ArgumentParserTests.cs

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -386,30 +386,15 @@ private static IEnumerable<TestCaseData> OverrideconfigWithInvalidOptionTestData
386386
{
387387
ExpectedResult = "Could not parse /overrideconfig option: unknown-option=25. Unsupported 'key'."
388388
};
389-
yield return new TestCaseData("update-build-number=1")
390-
{
391-
ExpectedResult = "Could not parse /overrideconfig option: update-build-number=1. Ensure that 'value' is 'true' or 'false'."
392-
};
393-
yield return new TestCaseData("label-pre-release-weight=invalid-value")
394-
{
395-
ExpectedResult = "Could not parse /overrideconfig option: label-pre-release-weight=invalid-value. Ensure that 'value' is valid integer number."
396-
};
397-
yield return new TestCaseData("assembly-versioning-scheme=WrongEnumValue")
398-
{
399-
ExpectedResult = $"Could not parse /overrideconfig option: assembly-versioning-scheme=WrongEnumValue. Ensure that 'value' is valid for specified 'key' enumeration: {System.Environment.NewLine}" +
400-
$"MajorMinorPatchTag{System.Environment.NewLine}" +
401-
$"MajorMinorPatch{System.Environment.NewLine}" +
402-
$"MajorMinor{System.Environment.NewLine}" +
403-
$"Major{System.Environment.NewLine}" +
404-
$"None{System.Environment.NewLine}"
405-
};
406389
}
407390

408391
[TestCaseSource(nameof(OverrideConfigWithSingleOptionTestData))]
409392
public void OverrideConfigWithSingleOptions(string options, GitVersionConfiguration expected)
410393
{
411394
var arguments = this.argumentParser.ParseArguments($"/overrideconfig {options}");
412-
arguments.OverrideConfig.ShouldBeEquivalentTo(expected);
395+
396+
ConfigurationHelper configruationHelper = new(arguments.OverrideConfig);
397+
configruationHelper.Configuration.ShouldBeEquivalentTo(expected);
413398
}
414399

415400
private static IEnumerable<TestCaseData> OverrideConfigWithSingleOptionTestData()
@@ -464,10 +449,10 @@ private static IEnumerable<TestCaseData> OverrideConfigWithSingleOptionTestData(
464449
}
465450
);
466451
yield return new TestCaseData(
467-
"continuous-delivery-fallback-label=cd-label",
452+
"label=cd-label",
468453
new GitVersionConfiguration
469454
{
470-
ContinuousDeploymentFallbackLabel = "cd-label"
455+
Label = "cd-label"
471456
}
472457
);
473458
yield return new TestCaseData(
@@ -546,7 +531,8 @@ private static IEnumerable<TestCaseData> OverrideConfigWithSingleOptionTestData(
546531
public void OverrideConfigWithMultipleOptions(string options, GitVersionConfiguration expected)
547532
{
548533
var arguments = this.argumentParser.ParseArguments(options);
549-
arguments.OverrideConfig.ShouldBeEquivalentTo(expected);
534+
ConfigurationHelper configruationHelper = new(arguments.OverrideConfig);
535+
configruationHelper.Configuration.ShouldBeEquivalentTo(expected);
550536
}
551537

552538
private static IEnumerable<TestCaseData> OverrideConfigWithMultipleOptionsTestData()

src/GitVersion.App.Tests/GitVersion.App.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<ItemGroup>
4-
<PackageReference Include="Mono.Cecil"/>
4+
<PackageReference Include="Mono.Cecil" />
55
</ItemGroup>
66
<ItemGroup>
77
<ProjectReference Include="..\GitVersion.Core\GitVersion.Core.csproj" />

src/GitVersion.App/ArgumentParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ private static void ParseOverrideConfig(Arguments arguments, IReadOnlyCollection
437437
}
438438
parser.SetValue(optionKey, keyAndValue[1]);
439439
}
440-
arguments.OverrideConfig = parser.GetConfig();
440+
arguments.OverrideConfig = parser.GetOverrideConfiguration();
441441
}
442442

443443
private static void ParseUpdateAssemblyInfo(Arguments arguments, string? value, IReadOnlyCollection<string>? values)

src/GitVersion.App/Arguments.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using GitVersion.Configuration;
21
using GitVersion.Logging;
32

43
namespace GitVersion;
@@ -8,7 +7,7 @@ public class Arguments
87
public AuthenticationInfo Authentication = new();
98

109
public string? ConfigFile;
11-
public GitVersionConfiguration? OverrideConfig;
10+
public IReadOnlyDictionary<object, object?> OverrideConfig;
1211
public bool ShowConfig;
1312

1413
public string? TargetPath;
@@ -61,9 +60,9 @@ public GitVersionOptions ToOptions()
6160

6261
ConfigInfo =
6362
{
64-
ConfigFile = ConfigFile,
65-
OverrideConfig = OverrideConfig,
66-
ShowConfig = ShowConfig
63+
ConfigurationFile = ConfigFile,
64+
OverrideConfiguration = OverrideConfig,
65+
ShowConfiguration = ShowConfig
6766
},
6867

6968
RepositoryInfo =

src/GitVersion.App/GitVersionExecutor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ private int RunGitVersionTool(GitVersionOptions gitVersionOptions)
6464

6565
var variables = this.gitVersionCalculateTool.CalculateVersionVariables();
6666

67-
var configuration = this.configurationProvider.Provide(gitVersionOptions.ConfigInfo.OverrideConfig);
67+
var configuration = this.configurationProvider.Provide(gitVersionOptions.ConfigInfo.OverrideConfiguration);
6868

69-
this.gitVersionOutputTool.OutputVariables(variables, configuration.UpdateBuildNumber ?? true);
69+
this.gitVersionOutputTool.OutputVariables(variables, configuration.UpdateBuildNumber);
7070
this.gitVersionOutputTool.UpdateAssemblyInfo(variables);
7171
this.gitVersionOutputTool.UpdateWixVersionFile(variables);
7272
}
@@ -152,7 +152,7 @@ private bool HandleNonMainCommand(GitVersionOptions gitVersionOptions, out int e
152152
return true;
153153
}
154154

155-
if (gitVersionOptions.ConfigInfo.ShowConfig)
155+
if (gitVersionOptions.ConfigInfo.ShowConfiguration)
156156
{
157157
var configuration = this.configurationProvider.Provide();
158158
this.console.WriteLine(configuration.ToString());

0 commit comments

Comments
 (0)