Skip to content
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

Create new fallback and unknown section in GitVersionConfiguration an… #3235

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
20 changes: 15 additions & 5 deletions BREAKING_CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,22 @@
* Instead of having a single effective configuration, we now have one effective configuration per branch where the increment strategy is not set to `inherit`.
* 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.
* 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:
```
```
* 1f1cfb4 52 minutes ago (HEAD -> feature/just-a-test)
* 1f9654d 54 minutes ago (release/1.1.0)
* be72411 56 minutes ago (develop)
* 14800ff 58 minutes ago (tag: 1.0.0, main)
```
* 1f9654d 54 minutes ago (release/1.1.0)
* be72411 56 minutes ago (develop)
* 14800ff 58 minutes ago (tag: 1.0.0, main)
```
* 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.
* 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.
* The following example illustrates this behavior. The hotfix branch configuration overrides the main branch configuration and the result overrides the fallback branch configuration.
```
* 1f1cfb4 52 minutes ago (HEAD -> hotfix/just-a-test)
* 14800ff 58 minutes ago (tag: 1.0.0, main)
```
* 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`.
* Following root configuration properties have been removed:
* continuous-delivery-fallback-tag

## v5.0.0

Expand Down
156 changes: 123 additions & 33 deletions docs/input/docs/reference/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,134 @@ created. Modify this to suit your needs.
The global configuration looks like this:

```yaml
next-version: 1.0
assembly-versioning-scheme: MajorMinorPatch
assembly-file-versioning-scheme: MajorMinorPatch
assembly-informational-format: '{InformationalVersion}'
mode: ContinuousDelivery
increment: Inherit
continuous-delivery-fallback-label: ci
label-prefix: '[vV]'
label-prefix: '[vV]?'
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)'
label-pre-release-weight: 60000
commit-message-incrementing: Enabled
ignore:
sha: []
commits-before: yyyy-MM-ddTHH:mm:ss
commit-date-format: yyyy-MM-dd
merge-message-formats: {}
update-build-number: true
semantic-version-format: Strict
branches:
develop:
mode: ContinuousDeployment
label: alpha
increment: Minor
prevent-increment-of-merged-branch-version: false
track-merge-target: true
regex: ^dev(elop)?(ment)?$
source-branches: []
tracks-release-branches: true
is-release-branch: false
is-mainline: false
pre-release-weight: 0
main:
label: ''
increment: Patch
prevent-increment-of-merged-branch-version: true
track-merge-target: false
regex: ^master$|^main$
source-branches:
- develop
- release
tracks-release-branches: false
is-release-branch: false
is-mainline: true
pre-release-weight: 55000
release:
label: beta
increment: None
prevent-increment-of-merged-branch-version: true
track-merge-target: false
regex: ^releases?[/-]
source-branches:
- develop
- main
- support
- release
tracks-release-branches: false
is-release-branch: true
is-mainline: false
pre-release-weight: 30000
feature:
mode: ContinuousDelivery
label: '{BranchName}'
increment: Inherit
regex: ^features?[/-]
source-branches:
- develop
- main
- release
- feature
- support
- hotfix
pre-release-weight: 30000
pull-request:
mode: ContinuousDelivery
label: PullRequest
increment: Inherit
label-number-pattern: '[/-](?<number>\d+)'
regex: ^(pull|pull\-requests|pr)[/-]
source-branches:
- develop
- main
- release
- feature
- support
- hotfix
pre-release-weight: 30000
hotfix:
mode: ContinuousDelivery
label: beta
increment: Inherit
regex: ^hotfix(es)?[/-]
source-branches:
- release
- main
- support
- hotfix
pre-release-weight: 30000
support:
label: ''
increment: Patch
prevent-increment-of-merged-branch-version: true
track-merge-target: false
regex: ^support[/-]
source-branches:
- main
tracks-release-branches: false
is-release-branch: false
is-mainline: true
pre-release-weight: 55000
unknown:
mode: ContinuousDelivery
label: '{BranchName}'
increment: Inherit
regex: .*
source-branches:
- main
- develop
- release
- feature
- pull-request
- hotfix
- support
ignore:
sha: []
mode: ContinuousDelivery
label: '{BranchName}'
increment: Inherit
prevent-increment-of-merged-branch-version: false
track-merge-target: false
commit-message-incrementing: Enabled
regex: ''
tracks-release-branches: false
is-release-branch: false
is-mainline: false
```

The details of the available options are as follows:
Expand Down Expand Up @@ -142,25 +251,6 @@ for [increment](#increment),
[prevent-increment-of-merged-branch-version](#prevent-increment-of-merged-branch-version)
and [tracks-release-branches](#tracks-release-branches).

### continuous-delivery-fallback-label

When using `mode: ContinuousDeployment`, the value specified in
`continuous-delivery-fallback-label` will be used as the pre-release label for
branches which do not have one specified. Default set to `ci`.

Just to clarify: For a build name without `...-ci-<buildnumber>` or in other
words without a `PreReleaseTag` (ergo `"PreReleaseTag":""` in GitVersion's JSON output)
at the end you would need to set `continuous-delivery-fallback-label` to an empty
string (`''`):

```yaml
mode: ContinuousDeployment
continuous-delivery-fallback-label: ''
...
```

Doing so can be helpful if you use your `main` branch as a `release` branch.

### label-prefix

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

### commit-message-incrementing
Expand Down Expand Up @@ -441,7 +531,7 @@ Without this configuration value you would have to do:
```yaml
branches:
unstable:
regex: ...
regex:
feature:
source-branches: ['unstable', 'develop', 'feature', 'hotfix', 'support']
release:
Expand Down Expand Up @@ -539,9 +629,9 @@ 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][1145]
and [1366][1366].

### semver-format
### semantic-version-format

Specifies the semver format that is used when parsing the string.
Specifies the semantic version 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`
Expand Down
2 changes: 1 addition & 1 deletion docs/input/docs/usage/cli/arguments.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Following options are supported:
5. `assembly-versioning-scheme`
7. `commit-date-format`
8. `commit-message-incrementing`
10. `continuous-delivery-fallback-label`
10. `label`
11. `increment`
13. `major-version-bump-message`
14. `minor-version-bump-message`
Expand Down
28 changes: 7 additions & 21 deletions src/GitVersion.App.Tests/ArgumentParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -386,30 +386,15 @@ private static IEnumerable<TestCaseData> OverrideconfigWithInvalidOptionTestData
{
ExpectedResult = "Could not parse /overrideconfig option: unknown-option=25. Unsupported 'key'."
};
yield return new TestCaseData("update-build-number=1")
{
ExpectedResult = "Could not parse /overrideconfig option: update-build-number=1. Ensure that 'value' is 'true' or 'false'."
};
yield return new TestCaseData("label-pre-release-weight=invalid-value")
{
ExpectedResult = "Could not parse /overrideconfig option: label-pre-release-weight=invalid-value. Ensure that 'value' is valid integer number."
};
yield return new TestCaseData("assembly-versioning-scheme=WrongEnumValue")
{
ExpectedResult = $"Could not parse /overrideconfig option: assembly-versioning-scheme=WrongEnumValue. Ensure that 'value' is valid for specified 'key' enumeration: {System.Environment.NewLine}" +
$"MajorMinorPatchTag{System.Environment.NewLine}" +
$"MajorMinorPatch{System.Environment.NewLine}" +
$"MajorMinor{System.Environment.NewLine}" +
$"Major{System.Environment.NewLine}" +
$"None{System.Environment.NewLine}"
};
}

[TestCaseSource(nameof(OverrideConfigWithSingleOptionTestData))]
public void OverrideConfigWithSingleOptions(string options, GitVersionConfiguration expected)
{
var arguments = this.argumentParser.ParseArguments($"/overrideconfig {options}");
arguments.OverrideConfig.ShouldBeEquivalentTo(expected);

ConfigurationHelper configruationHelper = new(arguments.OverrideConfig);
configruationHelper.Configuration.ShouldBeEquivalentTo(expected);
}

private static IEnumerable<TestCaseData> OverrideConfigWithSingleOptionTestData()
Expand Down Expand Up @@ -464,10 +449,10 @@ private static IEnumerable<TestCaseData> OverrideConfigWithSingleOptionTestData(
}
);
yield return new TestCaseData(
"continuous-delivery-fallback-label=cd-label",
"label=cd-label",
new GitVersionConfiguration
{
ContinuousDeploymentFallbackLabel = "cd-label"
Label = "cd-label"
}
);
yield return new TestCaseData(
Expand Down Expand Up @@ -546,7 +531,8 @@ private static IEnumerable<TestCaseData> OverrideConfigWithSingleOptionTestData(
public void OverrideConfigWithMultipleOptions(string options, GitVersionConfiguration expected)
{
var arguments = this.argumentParser.ParseArguments(options);
arguments.OverrideConfig.ShouldBeEquivalentTo(expected);
ConfigurationHelper configruationHelper = new(arguments.OverrideConfig);
configruationHelper.Configuration.ShouldBeEquivalentTo(expected);
}

private static IEnumerable<TestCaseData> OverrideConfigWithMultipleOptionsTestData()
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersion.App.Tests/GitVersion.App.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<PackageReference Include="Mono.Cecil"/>
<PackageReference Include="Mono.Cecil" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\GitVersion.Core\GitVersion.Core.csproj" />
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersion.App/ArgumentParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ private static void ParseOverrideConfig(Arguments arguments, IReadOnlyCollection
}
parser.SetValue(optionKey, keyAndValue[1]);
}
arguments.OverrideConfig = parser.GetConfig();
arguments.OverrideConfig = parser.GetOverrideConfiguration();
}

private static void ParseUpdateAssemblyInfo(Arguments arguments, string? value, IReadOnlyCollection<string>? values)
Expand Down
9 changes: 4 additions & 5 deletions src/GitVersion.App/Arguments.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using GitVersion.Configuration;
using GitVersion.Logging;

namespace GitVersion;
Expand All @@ -8,7 +7,7 @@ public class Arguments
public AuthenticationInfo Authentication = new();

public string? ConfigFile;
public GitVersionConfiguration? OverrideConfig;
public IReadOnlyDictionary<object, object?> OverrideConfig;
public bool ShowConfig;

public string? TargetPath;
Expand Down Expand Up @@ -61,9 +60,9 @@ public GitVersionOptions ToOptions()

ConfigInfo =
{
ConfigFile = ConfigFile,
OverrideConfig = OverrideConfig,
ShowConfig = ShowConfig
ConfigurationFile = ConfigFile,
OverrideConfiguration = OverrideConfig,
ShowConfiguration = ShowConfig
},

RepositoryInfo =
Expand Down
6 changes: 3 additions & 3 deletions src/GitVersion.App/GitVersionExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ private int RunGitVersionTool(GitVersionOptions gitVersionOptions)

var variables = this.gitVersionCalculateTool.CalculateVersionVariables();

var configuration = this.configurationProvider.Provide(gitVersionOptions.ConfigInfo.OverrideConfig);
var configuration = this.configurationProvider.Provide(gitVersionOptions.ConfigInfo.OverrideConfiguration);

this.gitVersionOutputTool.OutputVariables(variables, configuration.UpdateBuildNumber ?? true);
this.gitVersionOutputTool.OutputVariables(variables, configuration.UpdateBuildNumber);
this.gitVersionOutputTool.UpdateAssemblyInfo(variables);
this.gitVersionOutputTool.UpdateWixVersionFile(variables);
}
Expand Down Expand Up @@ -152,7 +152,7 @@ private bool HandleNonMainCommand(GitVersionOptions gitVersionOptions, out int e
return true;
}

if (gitVersionOptions.ConfigInfo.ShowConfig)
if (gitVersionOptions.ConfigInfo.ShowConfiguration)
{
var configuration = this.configurationProvider.Provide();
this.console.WriteLine(configuration.ToString());
Expand Down
Loading