Skip to content
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
4 changes: 4 additions & 0 deletions docs/input/docs/reference/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ is-mainline: 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

### next-version

Allows you to bump the next version explicitly. Useful for bumping `main` or a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,27 @@ public void FeatureOnHotfixFeatureBranchNotDeleted()
fixture.MergeNoFF(featureBranch); // commit 2
fixture.AssertFullSemver("4.5.1-beta.2", configuration);
}

[Test]
public void IsVersionTakenFromHotfixBranchName()
{
var configuration = GitFlowConfigurationBuilder.New.Build();

using var fixture = new BaseGitFlowRepositoryFixture("4.20.4");

fixture.Checkout("develop");
fixture.AssertFullSemver("4.21.0-alpha.1", configuration);

fixture.BranchTo("release/4.21.1");
fixture.AssertFullSemver("4.21.1-beta.1+0", configuration);

fixture.MakeACommit();
fixture.AssertFullSemver("4.21.1-beta.1+1", configuration);

fixture.BranchTo("hotfix/4.21.1");
fixture.AssertFullSemver("4.21.1-beta.1+1", configuration);

fixture.MakeACommit();
fixture.AssertFullSemver("4.21.1-beta.1+2", configuration);
}
}
6 changes: 6 additions & 0 deletions src/GitVersion.Core/Configuration/ConfigurationBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace GitVersion.Configuration;

internal sealed class ConfigurationBuilder : ConfigurationBuilderBase<ConfigurationBuilder>
{
public static ConfigurationBuilder New => new();
}
5 changes: 2 additions & 3 deletions src/GitVersion.Core/Configuration/ConfigurationBuilderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace GitVersion.Configuration;

internal abstract class ConfigurationBuilderBase<TConfigurationBuilder>
internal abstract class ConfigurationBuilderBase<TConfigurationBuilder> : IConfigurationBuilder
where TConfigurationBuilder : ConfigurationBuilderBase<TConfigurationBuilder>
{
private AssemblyVersioningScheme? assemblyVersioningScheme;
Expand Down Expand Up @@ -363,13 +363,12 @@ public virtual TConfigurationBuilder WithConfiguration(GitVersionConfiguration v
return (TConfigurationBuilder)this;
}

public TConfigurationBuilder AddOverride(IReadOnlyDictionary<object, object?> value)
public void AddOverride(IReadOnlyDictionary<object, object?> value)
{
if (value.Any())
{
this.overrides.Add(value);
}
return (TConfigurationBuilder)this;
}

public virtual GitVersionConfiguration Build()
Expand Down
24 changes: 22 additions & 2 deletions src/GitVersion.Core/Configuration/ConfigurationProvider.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using GitVersion.Configuration.Init.Wizard;
using GitVersion.Configuration.SupportedWorkflows;
using GitVersion.Extensions;
using GitVersion.Logging;
using Microsoft.Extensions.Options;
Expand Down Expand Up @@ -54,8 +55,13 @@ internal GitVersionConfiguration ProvideInternal(
{
var overrideConfigurationFromFile = this.configFileLocator.ReadOverrideConfiguration(workingDirectory);

var configurationBuilder = GitFlowConfigurationBuilder.New;
foreach (var item in new[] { overrideConfigurationFromFile, overrideConfiguration })
var workflow = GetWorkflow(overrideConfiguration, overrideConfigurationFromFile);

IConfigurationBuilder configurationBuilder = (workflow is null)
? GitFlowConfigurationBuilder.New : ConfigurationBuilder.New;

var overrideConfigurationFromWorkflow = WorkflowManager.GetOverrideConfiguration(workflow);
foreach (var item in new[] { overrideConfigurationFromWorkflow, overrideConfigurationFromFile, overrideConfiguration })
{
if (item != null) configurationBuilder.AddOverride(item);
}
Expand All @@ -73,6 +79,20 @@ internal GitVersionConfiguration ProvideInternal(
}
}

private static string? GetWorkflow(IReadOnlyDictionary<object, object?>? overrideConfiguration, IReadOnlyDictionary<object, object?>? overrideConfigurationFromFile)
{
string? workflow = null;
foreach (var item in new[] { overrideConfigurationFromFile, overrideConfiguration })
{
if (item?.TryGetValue("workflow", out object? value) == true && value != null)
{
workflow = (string)value;
}
}

return workflow;
}

private static string? ReadGitDirFromFile(string fileName)
{
const string expectedPrefix = "gitdir: ";
Expand Down
4 changes: 4 additions & 0 deletions src/GitVersion.Core/Configuration/GitVersionConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public GitVersionConfiguration()
Ignore = new IgnoreConfiguration();
}

[JsonPropertyName("workflow")]
[JsonPropertyDescription("The base template of the configuration to use. Possible values are: GitFlow/v1 or GitHubFlow/v1")]
public string? Workflow { get; set; }

[JsonPropertyName("assembly-versioning-scheme")]
[JsonPropertyDescription("The scheme to use when setting AssemblyVersion attribute. Can be 'MajorMinorPatchTag', 'MajorMinorPatch', 'MajorMinor', 'Major', 'None'.")]
public AssemblyVersioningScheme? AssemblyVersioningScheme { get; set; }
Expand Down
8 changes: 8 additions & 0 deletions src/GitVersion.Core/Configuration/IConfigurationBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace GitVersion.Configuration;

internal interface IConfigurationBuilder
{
void AddOverride(IReadOnlyDictionary<object, object?> value);

GitVersionConfiguration Build();
}
129 changes: 129 additions & 0 deletions src/GitVersion.Core/Configuration/SupportedWorkflows/GitFlow/v1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
assembly-versioning-scheme: MajorMinorPatch
assembly-file-versioning-scheme: MajorMinorPatch
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-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
track-merge-message: true
commit-message-incrementing: Enabled
regex: ''
tracks-release-branches: false
is-release-branch: false
is-mainline: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
assembly-versioning-scheme: MajorMinorPatch
assembly-file-versioning-scheme: MajorMinorPatch
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-date-format: yyyy-MM-dd
merge-message-formats: {}
update-build-number: true
semantic-version-format: Strict
branches:
main:
label: ''
increment: Patch
prevent-increment-of-merged-branch-version: true
track-merge-target: false
regex: ^master$|^main$
source-branches:
- 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:
- main
- 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:
- main
- release
- feature
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
pre-release-weight: 30000
unknown:
mode: ContinuousDelivery
label: '{BranchName}'
increment: Inherit
regex: .*
source-branches:
- main
- release
- feature
- pull-request
ignore:
sha: []
mode: ContinuousDelivery
label: '{BranchName}'
increment: Inherit
prevent-increment-of-merged-branch-version: false
track-merge-target: false
track-merge-message: true
commit-message-incrementing: Enabled
regex: ''
tracks-release-branches: false
is-release-branch: false
is-mainline: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using GitVersion.Extensions;

namespace GitVersion.Configuration.SupportedWorkflows
{
internal static class WorkflowManager
{
private static readonly string ResourceNameTemplate = DetermineResourceNameTemplate();

private static string DetermineResourceNameTemplate()
{
var fullClassName = typeof(WorkflowManager).FullName!;
var resourceNamePrefix = fullClassName.Substring(0, fullClassName.Length - nameof(WorkflowManager).Length - 1);
return $"{resourceNamePrefix}.{{0}}.yml";
}

public static Dictionary<object, object?>? GetOverrideConfiguration(string? workflow)
{
if (string.IsNullOrEmpty(workflow)) return null;

var resourceName = GetResourceName(workflow);
var embeddedResource = ReadEmbeddedResourceExtensions.ReadAsStringFromEmbeddedResource(
resourceName, typeof(WorkflowManager).Assembly
);
return ConfigurationSerializer.Deserialize<Dictionary<object, object?>>(embeddedResource);
}

private static string GetResourceName(string workflow)
=> ResourceNameTemplate.Replace("{0}", workflow.Replace('/', '.'));
}
}
Loading