diff --git a/BREAKING_CHANGES.md b/BREAKING_CHANGES.md index cc1b75e6fe..7ac3dde2dc 100644 --- a/BREAKING_CHANGES.md +++ b/BREAKING_CHANGES.md @@ -32,12 +32,20 @@ * The `BranchPrefixToTrim` configuration property has been removed. `RegularExpression` is now used to capture named groups instead. * Default `RegularExpression` for feature branches is changed from `^features?[/-]` to `^features?[/-](?.+)` to support using `{BranchName}` out-of-the-box * Default `RegularExpression` for unknown branches is changed from `.*` to `(?.*)` to support using `{BranchName}` out-of-the-box +* The `Mainline` mode and the related implementation has been removed completely. The new `TrunkBased` version strategy should be used instead. * The branch related property `is-mainline` in the configuration system has been renamed to `is-main-branch` * The versioning mode has been renamed to deployment mode and consists of following values: * ManualDeployment (previously ContinuousDelivery) * ContinuousDelivery (previously ContinuousDeployment) * ContinuousDeployment (new) - +* At the configuration root level, a new array called `strategies` has been introduced, which can consist of on or more following values: + * ConfiguredNextVersion + * MergeMessage + * TaggedCommit + * TrackReleaseBranches + * VersionInBranchName + * TrunkBased + ## v5.0.0 * Version numbers in branches other than `release` branches are no longer diff --git a/docs/input/docs/reference/configuration.md b/docs/input/docs/reference/configuration.md index 6a179fa957..f4f6bb5e3a 100644 --- a/docs/input/docs/reference/configuration.md +++ b/docs/input/docs/reference/configuration.md @@ -43,7 +43,6 @@ The global configuration looks like this: assembly-versioning-scheme: MajorMinorPatch assembly-file-versioning-scheme: MajorMinorPatch tag-prefix: '[vV]?' -version-in-branch-pattern: (?[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)' @@ -53,6 +52,7 @@ commit-date-format: yyyy-MM-dd merge-message-formats: {} update-build-number: true semantic-version-format: Strict +strategies: [ConfigNext, MergeMessage, TaggedCommit, TrackReleaseBranches, VersionInBranchName] branches: develop: mode: ContinuousDeployment @@ -62,7 +62,6 @@ branches: 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 @@ -76,7 +75,6 @@ branches: source-branches: - develop - release - is-source-branch-for: [] tracks-release-branches: false is-release-branch: false is-main-branch: true @@ -92,7 +90,6 @@ branches: - main - support - release - is-source-branch-for: [] tracks-release-branches: false is-release-branch: true is-main-branch: false @@ -101,7 +98,7 @@ branches: mode: ContinuousDelivery label: '{BranchName}' increment: Inherit - regex: ^features?[/-] + regex: ^features?[/-](?.+) source-branches: - develop - main @@ -109,7 +106,6 @@ branches: - feature - support - hotfix - is-source-branch-for: [] pre-release-weight: 30000 pull-request: mode: ContinuousDelivery @@ -124,7 +120,6 @@ branches: - feature - support - hotfix - is-source-branch-for: [] pre-release-weight: 30000 hotfix: mode: ContinuousDelivery @@ -136,8 +131,6 @@ branches: - main - support - hotfix - is-source-branch-for: [] - is-release-branch: true pre-release-weight: 30000 support: label: '' @@ -147,7 +140,6 @@ branches: regex: ^support[/-] source-branches: - main - is-source-branch-for: [] tracks-release-branches: false is-release-branch: false is-main-branch: true @@ -156,7 +148,7 @@ branches: mode: ContinuousDelivery label: '{BranchName}' increment: Inherit - regex: .* + regex: (?.*) source-branches: - main - develop @@ -165,7 +157,6 @@ branches: - pull-request - hotfix - support - is-source-branch-for: [] ignore: sha: [] mode: ContinuousDelivery @@ -176,8 +167,6 @@ 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 @@ -684,3 +673,13 @@ Example of invalid `Strict`, but valid `Loose` [modes]: /docs/reference/modes [variables]: /docs/reference/variables [version-sources]: /docs/reference/version-sources + +### strategies + +Specifies which version strategy implementation (one ore more) will be used to determine the next version. Following values are supported and can be combined: +* ConfiguredNextVersion +* MergeMessage +* TaggedCommit +* TrackReleaseBranches +* VersionInBranchName +* TrunkBased \ No newline at end of file diff --git a/src/GitVersion.Configuration.Tests/Configuration/ConfigurationProviderTests.CanWriteOutEffectiveConfiguration.approved.txt b/src/GitVersion.Configuration.Tests/Configuration/ConfigurationProviderTests.CanWriteOutEffectiveConfiguration.approved.txt index d937e92ad3..5ec390d2d5 100644 --- a/src/GitVersion.Configuration.Tests/Configuration/ConfigurationProviderTests.CanWriteOutEffectiveConfiguration.approved.txt +++ b/src/GitVersion.Configuration.Tests/Configuration/ConfigurationProviderTests.CanWriteOutEffectiveConfiguration.approved.txt @@ -11,6 +11,12 @@ commit-date-format: yyyy-MM-dd merge-message-formats: {} update-build-number: true semantic-version-format: Strict +strategies: +- ConfiguredNextVersion +- MergeMessage +- TaggedCommit +- TrackReleaseBranches +- VersionInBranchName branches: develop: label: alpha diff --git a/src/GitVersion.Configuration.Tests/Configuration/ConfigurationProviderTests.cs b/src/GitVersion.Configuration.Tests/Configuration/ConfigurationProviderTests.cs index 0ccd5f74a7..de631d05bf 100644 --- a/src/GitVersion.Configuration.Tests/Configuration/ConfigurationProviderTests.cs +++ b/src/GitVersion.Configuration.Tests/Configuration/ConfigurationProviderTests.cs @@ -56,6 +56,19 @@ public void OverwritesDefaultsWithProvidedConfig() developConfiguration.Label.ShouldBe("dev"); } + [Test] + public void CombineVersionStrategyConfigNextAndTaggedCommit() + { + // Arrange + SetupConfigFileContent("strategies: [ConfiguredNextVersion, TaggedCommit]"); + + // Act + var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath); + + // Assert + configuration.VersionStrategy.ShouldBe(VersionStrategies.ConfiguredNextVersion | VersionStrategies.TaggedCommit); + } + [Test] public void CanRemoveLabel() { diff --git a/src/GitVersion.Configuration.Tests/Configuration/Init/InitScenarios.CanSetNextVersion.approved.txt b/src/GitVersion.Configuration.Tests/Configuration/Init/InitScenarios.CanSetNextVersion.approved.txt index 5d5d726917..32913c39f0 100644 --- a/src/GitVersion.Configuration.Tests/Configuration/Init/InitScenarios.CanSetNextVersion.approved.txt +++ b/src/GitVersion.Configuration.Tests/Configuration/Init/InitScenarios.CanSetNextVersion.approved.txt @@ -2,6 +2,7 @@ next-version: 2.0.0 merge-message-formats: {} update-build-number: true semantic-version-format: Strict +strategies: [] branches: {} ignore: sha: [] diff --git a/src/GitVersion.Configuration/ConfigurationBuilderBase.cs b/src/GitVersion.Configuration/ConfigurationBuilderBase.cs index 8cc7e81ca4..5f14b2a5f8 100644 --- a/src/GitVersion.Configuration/ConfigurationBuilderBase.cs +++ b/src/GitVersion.Configuration/ConfigurationBuilderBase.cs @@ -24,6 +24,7 @@ internal abstract class ConfigurationBuilderBase : IConfi private string? commitDateFormat; private bool updateBuildNumber; private SemanticVersionFormat semanticVersionFormat; + private VersionStrategies versionStrategy; private Dictionary mergeMessageFormats = new(); private readonly List> overrides = new(); private readonly Dictionary branchConfigurationBuilders = new(); @@ -199,6 +200,12 @@ public virtual TConfigurationBuilder WithSemanticVersionFormat(SemanticVersionFo return (TConfigurationBuilder)this; } + public virtual TConfigurationBuilder WithVersionStrategy(VersionStrategies value) + { + this.versionStrategy = value; + return (TConfigurationBuilder)this; + } + public virtual TConfigurationBuilder WithMergeMessageFormats(IReadOnlyDictionary value) { this.mergeMessageFormats = new(value); @@ -321,6 +328,7 @@ public virtual TConfigurationBuilder WithConfiguration(IGitVersionConfiguration WithCommitDateFormat(value.CommitDateFormat); WithUpdateBuildNumber(value.UpdateBuildNumber); WithSemanticVersionFormat(value.SemanticVersionFormat); + WithVersionStrategy(value.VersionStrategy); WithMergeMessageFormats(value.MergeMessageFormats); foreach (var (name, branchConfiguration) in value.Branches) { @@ -358,6 +366,10 @@ public virtual IGitVersionConfiguration Build() branches.Add(name, (BranchConfiguration)branchConfigurationBuilder.Build()); } + var versionStrategies = Enum.GetValues() + .Where(element => element != VersionStrategies.None && this.versionStrategy.HasFlag(element)) + .ToArray(); + IGitVersionConfiguration configuration = new GitVersionConfiguration { AssemblyVersioningScheme = this.assemblyVersioningScheme, @@ -377,6 +389,7 @@ public virtual IGitVersionConfiguration Build() CommitDateFormat = this.commitDateFormat, UpdateBuildNumber = this.updateBuildNumber, SemanticVersionFormat = this.semanticVersionFormat, + VersionStrategies = versionStrategies, Branches = branches, MergeMessageFormats = this.mergeMessageFormats, DeploymentMode = this.versioningMode, diff --git a/src/GitVersion.Configuration/ConfigurationFileLocator.cs b/src/GitVersion.Configuration/ConfigurationFileLocator.cs index 1a0a3425d9..4421d46383 100644 --- a/src/GitVersion.Configuration/ConfigurationFileLocator.cs +++ b/src/GitVersion.Configuration/ConfigurationFileLocator.cs @@ -1,6 +1,5 @@ using GitVersion.Extensions; using GitVersion.Helpers; -using GitVersion.VersionCalculation; using Microsoft.Extensions.Options; namespace GitVersion.Configuration; @@ -29,11 +28,7 @@ public IGitVersionConfiguration ReadConfiguration(string? configFilePath) if (configFilePath == null || !fileSystem.Exists(configFilePath)) return new GitVersionConfiguration(); var readAllText = fileSystem.ReadAllText(configFilePath); - var readConfig = ConfigurationSerializer.Read(new StringReader(readAllText)); - - VerifyReadConfig(readConfig); - - return readConfig; + return ConfigurationSerializer.Read(new StringReader(readAllText)); } public IReadOnlyDictionary? ReadOverrideConfiguration(string? configFilePath) @@ -64,19 +59,6 @@ bool HasConfigurationFileAt(string fileName, out string? configFile) || HasConfigurationFileAt(DefaultAlternativeFileName, out path); } - private static void VerifyReadConfig(IGitVersionConfiguration configuration) - { - // Verify no branches are set to TrunkBased mode - if (configuration.Branches.Any(b => b.Value.DeploymentMode == DeploymentMode.TrunkBased)) - { - throw new ConfigurationException(@"TrunkBased mode only works at the repository level, a single branch cannot be put into TrunkBased mode - -This is because TrunkBased mode treats your entire git repository as an event source with each merge into the 'TrunkBased' incrementing the version. - -If the docs do not help you decide on the mode open an issue to discuss what you are trying to do."); - } - } - private void WarnAboutAmbiguousConfigFileSelection(string? workingDirectory, string? projectRootDirectory) { TryGetConfigurationFile(workingDirectory, null, out var workingConfigFile); diff --git a/src/GitVersion.Configuration/GitFlowConfigurationBuilder.cs b/src/GitVersion.Configuration/GitFlowConfigurationBuilder.cs index 763e43e91d..8eb9ad2080 100644 --- a/src/GitVersion.Configuration/GitFlowConfigurationBuilder.cs +++ b/src/GitVersion.Configuration/GitFlowConfigurationBuilder.cs @@ -18,6 +18,7 @@ private GitFlowConfigurationBuilder() NoBumpMessage = IncrementStrategyFinder.DefaultNoBumpPattern, PatchVersionBumpMessage = IncrementStrategyFinder.DefaultPatchPattern, SemanticVersionFormat = ConfigurationConstants.DefaultSemanticVersionFormat, + VersionStrategies = ConfigurationConstants.DefaultVersionStrategies, TagPrefix = ConfigurationConstants.DefaultTagPrefix, VersionInBranchPattern = ConfigurationConstants.DefaultVersionInBranchPattern, TagPreReleaseWeight = ConfigurationConstants.DefaultTagPreReleaseWeight, diff --git a/src/GitVersion.Configuration/GitHubFlowConfigurationBuilder.cs b/src/GitVersion.Configuration/GitHubFlowConfigurationBuilder.cs index 9b792ae976..64473f276b 100644 --- a/src/GitVersion.Configuration/GitHubFlowConfigurationBuilder.cs +++ b/src/GitVersion.Configuration/GitHubFlowConfigurationBuilder.cs @@ -18,6 +18,7 @@ private GitHubFlowConfigurationBuilder() NoBumpMessage = IncrementStrategyFinder.DefaultNoBumpPattern, PatchVersionBumpMessage = IncrementStrategyFinder.DefaultPatchPattern, SemanticVersionFormat = ConfigurationConstants.DefaultSemanticVersionFormat, + VersionStrategies = ConfigurationConstants.DefaultVersionStrategies, TagPrefix = ConfigurationConstants.DefaultTagPrefix, VersionInBranchPattern = ConfigurationConstants.DefaultVersionInBranchPattern, TagPreReleaseWeight = ConfigurationConstants.DefaultTagPreReleaseWeight, diff --git a/src/GitVersion.Configuration/GitVersion.Configuration.csproj b/src/GitVersion.Configuration/GitVersion.Configuration.csproj index 8d6358dd77..73acc1ab24 100644 --- a/src/GitVersion.Configuration/GitVersion.Configuration.csproj +++ b/src/GitVersion.Configuration/GitVersion.Configuration.csproj @@ -1,4 +1,7 @@ + + + @@ -10,6 +13,7 @@ + diff --git a/src/GitVersion.Configuration/GitVersionConfiguration.cs b/src/GitVersion.Configuration/GitVersionConfiguration.cs index a87959a8d9..5700548f0f 100644 --- a/src/GitVersion.Configuration/GitVersionConfiguration.cs +++ b/src/GitVersion.Configuration/GitVersionConfiguration.cs @@ -124,6 +124,14 @@ public string? NextVersion [JsonPropertyDefault(DefaultSemanticVersionFormat)] public SemanticVersionFormat SemanticVersionFormat { get; internal set; } + [JsonIgnore] + VersionStrategies IGitVersionConfiguration.VersionStrategy => VersionStrategies.Length == 0 + ? VersionCalculation.VersionStrategies.None : VersionStrategies.Aggregate((one, another) => one | another); + + [JsonPropertyName("strategies")] + [JsonPropertyDescription($"Specifies which version strategies (one or more) will be used to determine the next version. Following values are available: 'ConfiguredNextVersion', 'MergeMessage', 'TaggedCommit', 'TrackReleaseBranches', 'VersionInBranchName' and 'TrunkBased'.")] + public VersionStrategies[] VersionStrategies { get; internal set; } = []; + [JsonIgnore] IReadOnlyDictionary IGitVersionConfiguration.Branches => Branches.ToDictionary(element => element.Key, element => (IBranchConfiguration)element.Value); diff --git a/src/GitVersion.Configuration/Init/SetConfig/GlobalModeSetting.cs b/src/GitVersion.Configuration/Init/SetConfig/GlobalModeSetting.cs index 3e965d0561..79e954b0f5 100644 --- a/src/GitVersion.Configuration/Init/SetConfig/GlobalModeSetting.cs +++ b/src/GitVersion.Configuration/Init/SetConfig/GlobalModeSetting.cs @@ -23,15 +23,15 @@ protected override StepResult HandleResult( switch (result) { case "1": - configurationBuilder.WithDeploymentMode(DeploymentMode.ContinuousDelivery); + configurationBuilder.WithDeploymentMode(DeploymentMode.ManualDeployment); steps.Enqueue(this.returnToStep); return StepResult.Ok(); case "2": - configurationBuilder.WithDeploymentMode(DeploymentMode.ContinuousDeployment); + configurationBuilder.WithDeploymentMode(DeploymentMode.ContinuousDelivery); steps.Enqueue(this.returnToStep); return StepResult.Ok(); case "3": - configurationBuilder.WithDeploymentMode(DeploymentMode.TrunkBased); + configurationBuilder.WithDeploymentMode(DeploymentMode.ContinuousDeployment); steps.Enqueue(this.returnToStep); return StepResult.Ok(); case "0": diff --git a/src/GitVersion.Configuration/SupportedWorkflows/GitFlow/v1.yml b/src/GitVersion.Configuration/SupportedWorkflows/GitFlow/v1.yml index 83da461357..b659a13f3b 100644 --- a/src/GitVersion.Configuration/SupportedWorkflows/GitFlow/v1.yml +++ b/src/GitVersion.Configuration/SupportedWorkflows/GitFlow/v1.yml @@ -10,6 +10,7 @@ commit-date-format: yyyy-MM-dd merge-message-formats: {} update-build-number: true semantic-version-format: Strict +strategies: [ConfigNext, MergeMessage, TaggedCommit, TrackReleaseBranches, VersionInBranchName] branches: develop: mode: ContinuousDeployment diff --git a/src/GitVersion.Configuration/SupportedWorkflows/GitHubFlow/v1.yml b/src/GitVersion.Configuration/SupportedWorkflows/GitHubFlow/v1.yml index 79d1b21710..3556395487 100644 --- a/src/GitVersion.Configuration/SupportedWorkflows/GitHubFlow/v1.yml +++ b/src/GitVersion.Configuration/SupportedWorkflows/GitHubFlow/v1.yml @@ -10,6 +10,7 @@ commit-date-format: yyyy-MM-dd merge-message-formats: {} update-build-number: true semantic-version-format: Strict +strategies: [ConfigNext, MergeMessage, TaggedCommit, TrackReleaseBranches, VersionInBranchName] branches: main: label: '' diff --git a/src/GitVersion.Configuration/SupportedWorkflows/TrunkBased/v1.yml b/src/GitVersion.Configuration/SupportedWorkflows/TrunkBased/v1.yml new file mode 100644 index 0000000000..3289a1b7b9 --- /dev/null +++ b/src/GitVersion.Configuration/SupportedWorkflows/TrunkBased/v1.yml @@ -0,0 +1,69 @@ +assembly-versioning-scheme: MajorMinorPatch +assembly-file-versioning-scheme: MajorMinorPatch +tag-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)' +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?[/-](?.+) + source-branches: + - main + pre-release-weight: 30000 + hotfix: + increment: Patch + regex: ^hotfix(es)?[/-](?.+) + source-branches: + - main + pre-release-weight: 30000 + pull-request: + mode: ManualDeployment + label: PullRequest + increment: Inherit + label-number-pattern: '[/-](?\d+)' + regex: ^(pull|pull\-requests|pr)[/-] + source-branches: + - main + pre-release-weight: 30000 + unknown: + mode: ManualDeployment + increment: Inherit + regex: (?.*) + source-branches: + - main + - release + - feature + - pull-request +ignore: + sha: [] +mode: ManualDeployment +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-main-branch: false diff --git a/src/GitVersion.Core.Tests/IntegrationTests/ComparingTheBehaviorOfDifferentVersioningModes.cs b/src/GitVersion.Core.Tests/IntegrationTests/ComparingTheBehaviorOfDifferentVersioningModes.cs index 88eeb91400..fb234bb458 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/ComparingTheBehaviorOfDifferentVersioningModes.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/ComparingTheBehaviorOfDifferentVersioningModes.cs @@ -11,7 +11,7 @@ namespace GitVersion.Core.Tests.IntegrationTests; [TestFixture] internal class ComparingTheBehaviorOfDifferentDeploymentModes { - private static readonly GitHubFlowConfigurationBuilder configurationBuilder = GitHubFlowConfigurationBuilder.New + private static GitHubFlowConfigurationBuilder GetConfigurationBuilder() => GitHubFlowConfigurationBuilder.New .WithLabel(null) .WithBranch("main", _ => _ .WithIncrement(IncrementStrategy.Patch).WithLabel(null) @@ -19,25 +19,25 @@ internal class ComparingTheBehaviorOfDifferentDeploymentModes .WithIncrement(IncrementStrategy.Inherit).WithLabel("{BranchName}") ); - private static readonly IGitVersionConfiguration trunkBased = configurationBuilder - .WithDeploymentMode(DeploymentMode.TrunkBased) + private static readonly IGitVersionConfiguration trunkBased = GetConfigurationBuilder() + .WithVersionStrategy(VersionStrategies.TrunkBased) .WithBranch("main", _ => _.WithIsMainBranch(true).WithDeploymentMode(DeploymentMode.ContinuousDeployment)) .WithBranch("feature", _ => _.WithIsMainBranch(false).WithDeploymentMode(DeploymentMode.ContinuousDelivery)) .Build(); - private static readonly IGitVersionConfiguration continuousDeployment = configurationBuilder + private static readonly IGitVersionConfiguration continuousDeployment = GetConfigurationBuilder() .WithDeploymentMode(DeploymentMode.ContinuousDeployment) .WithBranch("main", _ => _.WithIsMainBranch(true).WithDeploymentMode(DeploymentMode.ContinuousDeployment)) .WithBranch("feature", _ => _.WithIsMainBranch(false).WithDeploymentMode(DeploymentMode.ContinuousDeployment)) .Build(); - private static readonly IGitVersionConfiguration continuousDelivery = configurationBuilder + private static readonly IGitVersionConfiguration continuousDelivery = GetConfigurationBuilder() .WithDeploymentMode(DeploymentMode.ContinuousDelivery) .WithBranch("main", _ => _.WithIsMainBranch(true).WithDeploymentMode(DeploymentMode.ContinuousDelivery)) .WithBranch("feature", _ => _.WithIsMainBranch(false).WithDeploymentMode(DeploymentMode.ContinuousDelivery)) .Build(); - private static readonly IGitVersionConfiguration manualDeployment = configurationBuilder + private static readonly IGitVersionConfiguration manualDeployment = GetConfigurationBuilder() .WithDeploymentMode(DeploymentMode.ManualDeployment) .WithBranch("main", _ => _.WithIsMainBranch(true).WithDeploymentMode(DeploymentMode.ManualDeployment)) .WithBranch("feature", _ => _.WithIsMainBranch(false).WithDeploymentMode(DeploymentMode.ManualDeployment)) diff --git a/src/GitVersion.Core.Tests/IntegrationTests/TrunkBasedDevelopmentScenarios.cs b/src/GitVersion.Core.Tests/IntegrationTests/TrunkBasedDevelopmentScenarios.cs index 06f72983f5..80be294775 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/TrunkBasedDevelopmentScenarios.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/TrunkBasedDevelopmentScenarios.cs @@ -8,7 +8,7 @@ namespace GitVersion.Core.Tests.IntegrationTests; public class TrunkBasedDevelopmentScenarios : TestBase { private static GitFlowConfigurationBuilder GetConfigurationBuilder() => GitFlowConfigurationBuilder.New - .WithDeploymentMode(DeploymentMode.TrunkBased) + .WithVersionStrategy(VersionStrategies.TrunkBased) .WithBranch("main", builder => builder .WithIsMainBranch(true).WithIncrement(IncrementStrategy.Patch) .WithDeploymentMode(DeploymentMode.ContinuousDeployment) @@ -511,7 +511,7 @@ public void MergingFeatureBranchThatIncrementsMinorNumberIncrementsMinorVersionO public void VerifyIncrementConfigIsHonoured() { var minorIncrementConfig = GitFlowConfigurationBuilder.New - .WithDeploymentMode(DeploymentMode.TrunkBased) + .WithVersionStrategy(VersionStrategies.TrunkBased) .WithBranch("main", builder => builder .WithDeploymentMode(DeploymentMode.ContinuousDeployment) .WithIncrement(IncrementStrategy.None) diff --git a/src/GitVersion.Core.Tests/IntegrationTests/VersionBumpingScenarios.cs b/src/GitVersion.Core.Tests/IntegrationTests/VersionBumpingScenarios.cs index a977c7f0eb..c0e322fe86 100644 --- a/src/GitVersion.Core.Tests/IntegrationTests/VersionBumpingScenarios.cs +++ b/src/GitVersion.Core.Tests/IntegrationTests/VersionBumpingScenarios.cs @@ -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-]*\\))?:") - .WithDeploymentMode(DeploymentMode.TrunkBased) + .WithVersionStrategy(VersionStrategies.TrunkBased) .WithBranch("main", builder => builder.WithDeploymentMode(DeploymentMode.ContinuousDeployment)) .Build(); diff --git a/src/GitVersion.Core.Tests/VersionCalculation/EffectiveBranchConfigurationFinderTests.cs b/src/GitVersion.Core.Tests/VersionCalculation/EffectiveBranchConfigurationFinderTests.cs index 1055e06f55..3d754c8afe 100644 --- a/src/GitVersion.Core.Tests/VersionCalculation/EffectiveBranchConfigurationFinderTests.cs +++ b/src/GitVersion.Core.Tests/VersionCalculation/EffectiveBranchConfigurationFinderTests.cs @@ -156,7 +156,6 @@ public void UsesFirstBranchConfigWhenMultipleMatch(string branchName, IncrementS var releaseBranchMock = GitToolsTestingExtensions.CreateMockBranch(branchName, GitToolsTestingExtensions.CreateMockCommit()); var branchConfiguration = new BranchConfiguration { - DeploymentMode = DeploymentMode.TrunkBased, Increment = IncrementStrategy.None, PreventIncrementOfMergedBranchVersion = false, TrackMergeTarget = false, diff --git a/src/GitVersion.Core.Tests/VersionCalculation/Strategies/ConfigNextVersionBaseVersionStrategyTests.cs b/src/GitVersion.Core.Tests/VersionCalculation/Strategies/ConfiguredNextVersionVersionStrategyTests.cs similarity index 86% rename from src/GitVersion.Core.Tests/VersionCalculation/Strategies/ConfigNextVersionBaseVersionStrategyTests.cs rename to src/GitVersion.Core.Tests/VersionCalculation/Strategies/ConfiguredNextVersionVersionStrategyTests.cs index 78b9453adc..142fec703e 100644 --- a/src/GitVersion.Core.Tests/VersionCalculation/Strategies/ConfigNextVersionBaseVersionStrategyTests.cs +++ b/src/GitVersion.Core.Tests/VersionCalculation/Strategies/ConfiguredNextVersionVersionStrategyTests.cs @@ -7,7 +7,7 @@ namespace GitVersion.Core.Tests.VersionCalculation.Strategies; [TestFixture] -public class ConfigNextVersionBaseVersionStrategyTests : TestBase +public class ConfiguredNextVersionVersionStrategyTests : TestBase { [Test] public void ReturnsNullWhenNoNextVersionIsInConfig() @@ -22,7 +22,7 @@ public void ReturnsNullWhenNoNextVersionIsInConfig() [TestCase("2.12.654651698", "2.12.654651698", SemanticVersionFormat.Strict)] [TestCase("2.12.654651698", "2.12.654651698", SemanticVersionFormat.Loose)] [TestCase("0.1", "0.1.0", SemanticVersionFormat.Loose)] - public void ConfigNextVersionTest(string nextVersion, string expectedVersion, SemanticVersionFormat versionFormat) + public void ConfiguredNextVersionTest(string nextVersion, string expectedVersion, SemanticVersionFormat versionFormat) { var overrideConfiguration = new Dictionary { @@ -37,7 +37,7 @@ public void ConfigNextVersionTest(string nextVersion, string expectedVersion, Se } [TestCase("0.1", SemanticVersionFormat.Strict)] - public void ConfigNextVersionTestShouldFail(string nextVersion, SemanticVersionFormat versionFormat) + public void ConfiguredNextVersionTestShouldFail(string nextVersion, SemanticVersionFormat versionFormat) { var overrideConfiguration = new Dictionary { @@ -54,7 +54,7 @@ public void ConfigNextVersionTestShouldFail(string nextVersion, SemanticVersionF var contextBuilder = new GitVersionContextBuilder().WithOverrideConfiguration(overrideConfiguration); contextBuilder.Build(); contextBuilder.ServicesProvider.ShouldNotBeNull(); - var strategy = contextBuilder.ServicesProvider.GetServiceForType(); + var strategy = contextBuilder.ServicesProvider.GetServiceForType(); var context = contextBuilder.ServicesProvider.GetRequiredService>().Value; var branchMock = GitToolsTestingExtensions.CreateMockBranch("main", GitToolsTestingExtensions.CreateMockCommit()); diff --git a/src/GitVersion.Core/Configuration/ConfigurationConstants.cs b/src/GitVersion.Core/Configuration/ConfigurationConstants.cs index c0296ee261..b3a8ffa6ef 100644 --- a/src/GitVersion.Core/Configuration/ConfigurationConstants.cs +++ b/src/GitVersion.Core/Configuration/ConfigurationConstants.cs @@ -1,4 +1,5 @@ using GitVersion.Extensions; +using GitVersion.VersionCalculation; namespace GitVersion.Configuration; @@ -13,6 +14,13 @@ internal static class ConfigurationConstants public const AssemblyVersioningScheme DefaultAssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinorPatch; public const AssemblyFileVersioningScheme DefaultAssemblyFileVersioningScheme = AssemblyFileVersioningScheme.MajorMinorPatch; public const SemanticVersionFormat DefaultSemanticVersionFormat = SemanticVersionFormat.Strict; + public static readonly VersionStrategies[] DefaultVersionStrategies = [ + VersionStrategies.ConfiguredNextVersion, + VersionStrategies.MergeMessage, + VersionStrategies.TaggedCommit, + VersionStrategies.TrackReleaseBranches, + VersionStrategies.VersionInBranchName + ]; public const string DefaultAssemblyInformationalFormat = "{InformationalVersion}"; public const string DefaultTagPrefix = "[vV]?"; public const string DefaultVersionInBranchPattern = @"(?[vV]?\d+(\.\d+)?(\.\d+)?).*"; diff --git a/src/GitVersion.Core/Configuration/EffectiveConfiguration.cs b/src/GitVersion.Core/Configuration/EffectiveConfiguration.cs index f3d8a9b295..6482eb5b16 100644 --- a/src/GitVersion.Core/Configuration/EffectiveConfiguration.cs +++ b/src/GitVersion.Core/Configuration/EffectiveConfiguration.cs @@ -61,6 +61,7 @@ public EffectiveConfiguration(IGitVersionConfiguration configuration, IBranchCon CommitDateFormat = configuration.CommitDateFormat; UpdateBuildNumber = configuration.UpdateBuildNumber; SemanticVersionFormat = configuration.SemanticVersionFormat; + VersionStrategy = configuration.VersionStrategy; PreReleaseWeight = branchConfiguration.PreReleaseWeight ?? 0; TagPreReleaseWeight = configuration.TagPreReleaseWeight.Value; } @@ -176,7 +177,9 @@ protected EffectiveConfiguration(AssemblyVersioningScheme assemblyVersioningSche public bool UpdateBuildNumber { get; } - public SemanticVersionFormat SemanticVersionFormat { get; set; } + public SemanticVersionFormat SemanticVersionFormat { get; } + + public VersionStrategies VersionStrategy { get; } public int PreReleaseWeight { get; } diff --git a/src/GitVersion.Core/Configuration/IGitVersionConfiguration.cs b/src/GitVersion.Core/Configuration/IGitVersionConfiguration.cs index 37d7bf8ce9..47a5db9e31 100644 --- a/src/GitVersion.Core/Configuration/IGitVersionConfiguration.cs +++ b/src/GitVersion.Core/Configuration/IGitVersionConfiguration.cs @@ -1,5 +1,6 @@ using System.Text.RegularExpressions; using GitVersion.Extensions; +using GitVersion.VersionCalculation; namespace GitVersion.Configuration; @@ -43,6 +44,8 @@ public interface IGitVersionConfiguration : IBranchConfiguration SemanticVersionFormat SemanticVersionFormat { get; } + VersionStrategies VersionStrategy { get; } + IReadOnlyDictionary Branches { get; } IIgnoreConfiguration Ignore { get; } diff --git a/src/GitVersion.Core/Core/Abstractions/IRepositoryStore.cs b/src/GitVersion.Core/Core/Abstractions/IRepositoryStore.cs index 49a0f6bede..ef813cef07 100644 --- a/src/GitVersion.Core/Core/Abstractions/IRepositoryStore.cs +++ b/src/GitVersion.Core/Core/Abstractions/IRepositoryStore.cs @@ -11,21 +11,15 @@ public interface IRepositoryStore ICommit? FindMergeBase(ICommit commit, ICommit mainlineTip); ICommit? GetCurrentCommit(IBranch currentBranch, string? commitId); - IEnumerable GetMainlineCommitLog(ICommit? baseVersionSource, ICommit? mainlineTip); - IEnumerable GetMergeBaseCommits(ICommit? mergeCommit, ICommit? mergedHead, ICommit? findMergeBase); IEnumerable GetCommitLog(ICommit? baseVersionSource, ICommit? currentCommit); IBranch GetTargetBranch(string? targetBranchName); IBranch? FindBranch(ReferenceName branchName); IBranch? FindBranch(string branchName); - IBranch? FindMainBranch(IGitVersionConfiguration configuration); - IEnumerable FindMainlineBranches(IGitVersionConfiguration configuration); IEnumerable GetReleaseBranches(IEnumerable> releaseBranchConfig); IEnumerable ExcludingBranches(IEnumerable branchesToExclude); IEnumerable GetBranchesContainingCommit(ICommit commit, IEnumerable? branches = null, bool onlyTrackedBranches = false); - IDictionary> GetMainlineBranches(ICommit commit, IGitVersionConfiguration configuration); - /// /// Find the commit where the given branch was branched from another branch. /// If there are multiple such commits and branches, tries to guess based on commit histories. diff --git a/src/GitVersion.Core/Core/BranchRepository.cs b/src/GitVersion.Core/Core/BranchRepository.cs index 1108b2d8d2..6962fb1d7d 100644 --- a/src/GitVersion.Core/Core/BranchRepository.cs +++ b/src/GitVersion.Core/Core/BranchRepository.cs @@ -11,7 +11,7 @@ internal sealed class BranchRepository(Lazy versionContext, I private readonly IGitRepository gitRepository = gitRepository.NotNull(); - public IEnumerable GetMainlineBranches(params IBranch[] excludeBranches) + public IEnumerable GetMainBranches(params IBranch[] excludeBranches) => GetBranches([.. excludeBranches], configuration => configuration.IsMainBranch == true); public IEnumerable GetReleaseBranches(params IBranch[] excludeBranches) diff --git a/src/GitVersion.Core/Core/IBranchRepository.cs b/src/GitVersion.Core/Core/IBranchRepository.cs index bc13477299..11a74ac41c 100644 --- a/src/GitVersion.Core/Core/IBranchRepository.cs +++ b/src/GitVersion.Core/Core/IBranchRepository.cs @@ -2,7 +2,7 @@ namespace GitVersion.Core; internal interface IBranchRepository { - IEnumerable GetMainlineBranches(params IBranch[] excludeBranches); + IEnumerable GetMainBranches(params IBranch[] excludeBranches); IEnumerable GetReleaseBranches(params IBranch[] excludeBranches); } diff --git a/src/GitVersion.Core/Core/RepositoryStore.cs b/src/GitVersion.Core/Core/RepositoryStore.cs index 1514cecd7a..7ce3847f4c 100644 --- a/src/GitVersion.Core/Core/RepositoryStore.cs +++ b/src/GitVersion.Core/Core/RepositoryStore.cs @@ -55,29 +55,6 @@ public RepositoryStore(ILog log, IGitRepository repository) return currentBranch.Tip; } - public IEnumerable GetMainlineCommitLog(ICommit? baseVersionSource, ICommit? mainlineTip) - { - if (mainlineTip is null) - { - return []; - } - - var filter = new CommitFilter { IncludeReachableFrom = mainlineTip, ExcludeReachableFrom = baseVersionSource, SortBy = CommitSortStrategies.Reverse, FirstParentOnly = true }; - - return this.repository.Commits.QueryBy(filter); - } - - public IEnumerable GetMergeBaseCommits(ICommit? mergeCommit, ICommit? mergedHead, ICommit? findMergeBase) - { - var filter = new CommitFilter { IncludeReachableFrom = mergedHead, ExcludeReachableFrom = findMergeBase }; - var commitCollection = this.repository.Commits.QueryBy(filter); - - var commits = mergeCommit != null - ? new[] { mergeCommit }.Union(commitCollection) - : commitCollection; - return commits; - } - public IBranch GetTargetBranch(string? targetBranchName) { // By default, we assume HEAD is pointing to the desired branch @@ -108,35 +85,6 @@ public IBranch GetTargetBranch(string? targetBranchName) public IBranch? FindBranch(string branchName) => this.repository.Branches.FirstOrDefault(x => x.Name.EquivalentTo(branchName)); - public IBranch? FindMainBranch(IGitVersionConfiguration configuration) - { - var branches = configuration.Branches; - var mainBranchRegex = branches[ConfigurationConstants.MainBranchKey].RegularExpression - ?? branches[ConfigurationConstants.MasterBranchKey].RegularExpression; - - if (mainBranchRegex == null) - { - return FindBranch(ConfigurationConstants.MainBranchKey) ?? FindBranch(ConfigurationConstants.MasterBranchKey); - } - - return this.repository.Branches.FirstOrDefault(b => - Regex.IsMatch(b.Name.WithoutOrigin, mainBranchRegex, RegexOptions.IgnoreCase)); - } - - public IEnumerable FindMainlineBranches(IGitVersionConfiguration configuration) - { - configuration.NotNull(); - - foreach (var branch in this.repository.Branches) - { - var branchConfiguration = configuration.GetBranchConfiguration(branch.Name); - if (branchConfiguration.IsMainBranch == true) - { - yield return branch; - } - } - } - public IEnumerable GetReleaseBranches(IEnumerable> releaseBranchConfig) => this.repository.Branches.Where(b => IsReleaseBranch(b, releaseBranchConfig)); @@ -153,12 +101,6 @@ public IEnumerable GetBranchesContainingCommit(ICommit commit, IEnumera return branchesContainingCommitFinder.GetBranchesContainingCommit(commit, branches, onlyTrackedBranches); } - public IDictionary> GetMainlineBranches(ICommit commit, IGitVersionConfiguration configuration) - { - var mainlineBranchFinder = new MainlineBranchFinder(this, this.repository, configuration, this.log); - return mainlineBranchFinder.FindMainlineBranches(commit); - } - public IEnumerable GetSourceBranches(IBranch branch, IGitVersionConfiguration configuration, params IBranch[] excludedBranches) => GetSourceBranches(branch, configuration, (IEnumerable)excludedBranches); diff --git a/src/GitVersion.Core/Core/TaggedSemanticVersionRepository.cs b/src/GitVersion.Core/Core/TaggedSemanticVersionRepository.cs index 4154616094..5f24743346 100644 --- a/src/GitVersion.Core/Core/TaggedSemanticVersionRepository.cs +++ b/src/GitVersion.Core/Core/TaggedSemanticVersionRepository.cs @@ -199,7 +199,7 @@ IEnumerable GetElements() using (this.log.IndentLog($"Getting tagged semantic versions of mainline branches. " + $"TagPrefix: {tagPrefix} and Format: {format}")) { - foreach (var mainlinemBranch in branchRepository.GetMainlineBranches(excludeBranches)) + foreach (var mainlinemBranch in branchRepository.GetMainBranches(excludeBranches)) { foreach (var semanticVersion in GetTaggedSemanticVersionsOfBranch(mainlinemBranch, tagPrefix, format).SelectMany(_ => _)) { diff --git a/src/GitVersion.Core/PublicAPI.Unshipped.txt b/src/GitVersion.Core/PublicAPI.Unshipped.txt index 86db54b030..a0a180be0b 100644 --- a/src/GitVersion.Core/PublicAPI.Unshipped.txt +++ b/src/GitVersion.Core/PublicAPI.Unshipped.txt @@ -93,17 +93,12 @@ GitVersion.Common.IRepositoryStore.FindBranch(string! branchName) -> GitVersion. GitVersion.Common.IRepositoryStore.FindCommitBranchWasBranchedFrom(GitVersion.IBranch? branch, GitVersion.Configuration.IGitVersionConfiguration! configuration, params GitVersion.IBranch![]! excludedBranches) -> GitVersion.BranchCommit GitVersion.Common.IRepositoryStore.FindCommitBranchesWasBranchedFrom(GitVersion.IBranch! branch, GitVersion.Configuration.IGitVersionConfiguration! configuration, System.Collections.Generic.IEnumerable! excludedBranches) -> System.Collections.Generic.IEnumerable! GitVersion.Common.IRepositoryStore.FindCommitBranchesWasBranchedFrom(GitVersion.IBranch! branch, GitVersion.Configuration.IGitVersionConfiguration! configuration, params GitVersion.IBranch![]! excludedBranches) -> System.Collections.Generic.IEnumerable! -GitVersion.Common.IRepositoryStore.FindMainBranch(GitVersion.Configuration.IGitVersionConfiguration! configuration) -> GitVersion.IBranch? -GitVersion.Common.IRepositoryStore.FindMainlineBranches(GitVersion.Configuration.IGitVersionConfiguration! configuration) -> System.Collections.Generic.IEnumerable! GitVersion.Common.IRepositoryStore.FindMergeBase(GitVersion.IBranch? branch, GitVersion.IBranch? otherBranch) -> GitVersion.ICommit? GitVersion.Common.IRepositoryStore.FindMergeBase(GitVersion.ICommit! commit, GitVersion.ICommit! mainlineTip) -> GitVersion.ICommit? GitVersion.Common.IRepositoryStore.GetBranchesContainingCommit(GitVersion.ICommit! commit, System.Collections.Generic.IEnumerable? branches = null, bool onlyTrackedBranches = false) -> System.Collections.Generic.IEnumerable! GitVersion.Common.IRepositoryStore.GetCommitLog(GitVersion.ICommit? baseVersionSource, GitVersion.ICommit? currentCommit) -> System.Collections.Generic.IEnumerable! GitVersion.Common.IRepositoryStore.GetCurrentCommit(GitVersion.IBranch! currentBranch, string? commitId) -> GitVersion.ICommit? GitVersion.Common.IRepositoryStore.GetCurrentCommitTaggedVersion(GitVersion.ICommit? commit, string? tagPrefix, GitVersion.SemanticVersionFormat format, bool handleDetachedBranch) -> GitVersion.SemanticVersion? -GitVersion.Common.IRepositoryStore.GetMainlineBranches(GitVersion.ICommit! commit, GitVersion.Configuration.IGitVersionConfiguration! configuration) -> System.Collections.Generic.IDictionary!>! -GitVersion.Common.IRepositoryStore.GetMainlineCommitLog(GitVersion.ICommit? baseVersionSource, GitVersion.ICommit? mainlineTip) -> System.Collections.Generic.IEnumerable! -GitVersion.Common.IRepositoryStore.GetMergeBaseCommits(GitVersion.ICommit? mergeCommit, GitVersion.ICommit? mergedHead, GitVersion.ICommit? findMergeBase) -> System.Collections.Generic.IEnumerable! GitVersion.Common.IRepositoryStore.GetNumberOfUncommittedChanges() -> int GitVersion.Common.IRepositoryStore.GetReleaseBranches(System.Collections.Generic.IEnumerable>! releaseBranchConfig) -> System.Collections.Generic.IEnumerable! GitVersion.Common.IRepositoryStore.GetSourceBranches(GitVersion.IBranch! branch, GitVersion.Configuration.IGitVersionConfiguration! configuration, System.Collections.Generic.IEnumerable! excludedBranches) -> System.Collections.Generic.IEnumerable! @@ -144,13 +139,13 @@ GitVersion.Configuration.EffectiveConfiguration.PatchVersionBumpMessage.get -> s GitVersion.Configuration.EffectiveConfiguration.PreReleaseWeight.get -> int GitVersion.Configuration.EffectiveConfiguration.PreventIncrementOfMergedBranchVersion.get -> bool GitVersion.Configuration.EffectiveConfiguration.SemanticVersionFormat.get -> GitVersion.SemanticVersionFormat -GitVersion.Configuration.EffectiveConfiguration.SemanticVersionFormat.set -> void GitVersion.Configuration.EffectiveConfiguration.TrackMergeMessage.get -> bool GitVersion.Configuration.EffectiveConfiguration.TrackMergeTarget.get -> bool GitVersion.Configuration.EffectiveConfiguration.TracksReleaseBranches.get -> bool GitVersion.Configuration.EffectiveConfiguration.UpdateBuildNumber.get -> bool GitVersion.Configuration.EffectiveConfiguration.VersionFilters.get -> System.Collections.Generic.IEnumerable! GitVersion.Configuration.EffectiveConfiguration.VersionInBranchRegex.get -> System.Text.RegularExpressions.Regex! +GitVersion.Configuration.EffectiveConfiguration.VersionStrategy.get -> GitVersion.VersionCalculation.VersionStrategies GitVersion.Configuration.IBranchConfiguration GitVersion.Configuration.IBranchConfiguration.CommitMessageIncrementing.get -> GitVersion.VersionCalculation.CommitMessageIncrementMode? GitVersion.Configuration.IBranchConfiguration.DeploymentMode.get -> GitVersion.VersionCalculation.DeploymentMode? @@ -200,6 +195,7 @@ GitVersion.Configuration.IGitVersionConfiguration.ToJsonString() -> string! GitVersion.Configuration.IGitVersionConfiguration.UpdateBuildNumber.get -> bool GitVersion.Configuration.IGitVersionConfiguration.VersionInBranchPattern.get -> string? GitVersion.Configuration.IGitVersionConfiguration.VersionInBranchRegex.get -> System.Text.RegularExpressions.Regex! +GitVersion.Configuration.IGitVersionConfiguration.VersionStrategy.get -> GitVersion.VersionCalculation.VersionStrategies GitVersion.Configuration.IGitVersionConfiguration.Workflow.get -> string? GitVersion.Configuration.IIgnoreConfiguration GitVersion.Configuration.IIgnoreConfiguration.Before.get -> System.DateTimeOffset? @@ -694,7 +690,6 @@ GitVersion.VersionCalculation.DeploymentMode GitVersion.VersionCalculation.DeploymentMode.ContinuousDelivery = 1 -> GitVersion.VersionCalculation.DeploymentMode GitVersion.VersionCalculation.DeploymentMode.ContinuousDeployment = 2 -> GitVersion.VersionCalculation.DeploymentMode GitVersion.VersionCalculation.DeploymentMode.ManualDeployment = 0 -> GitVersion.VersionCalculation.DeploymentMode -GitVersion.VersionCalculation.DeploymentMode.TrunkBased = 3 -> GitVersion.VersionCalculation.DeploymentMode GitVersion.VersionCalculation.IEffectiveBranchConfigurationFinder GitVersion.VersionCalculation.IEffectiveBranchConfigurationFinder.GetConfigurations(GitVersion.IBranch! branch, GitVersion.Configuration.IGitVersionConfiguration! configuration) -> System.Collections.Generic.IEnumerable! GitVersion.VersionCalculation.IIncrementStrategyFinder @@ -723,6 +718,14 @@ GitVersion.VersionCalculation.NextVersion.NextVersion(GitVersion.SemanticVersion GitVersion.VersionCalculation.VersionCalculationModule GitVersion.VersionCalculation.VersionCalculationModule.RegisterTypes(Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> void GitVersion.VersionCalculation.VersionCalculationModule.VersionCalculationModule() -> void +GitVersion.VersionCalculation.VersionStrategies +GitVersion.VersionCalculation.VersionStrategies.ConfiguredNextVersion = 1 -> GitVersion.VersionCalculation.VersionStrategies +GitVersion.VersionCalculation.VersionStrategies.MergeMessage = 2 -> GitVersion.VersionCalculation.VersionStrategies +GitVersion.VersionCalculation.VersionStrategies.None = 0 -> GitVersion.VersionCalculation.VersionStrategies +GitVersion.VersionCalculation.VersionStrategies.TaggedCommit = 4 -> GitVersion.VersionCalculation.VersionStrategies +GitVersion.VersionCalculation.VersionStrategies.TrackReleaseBranches = 8 -> GitVersion.VersionCalculation.VersionStrategies +GitVersion.VersionCalculation.VersionStrategies.TrunkBased = 32 -> GitVersion.VersionCalculation.VersionStrategies +GitVersion.VersionCalculation.VersionStrategies.VersionInBranchName = 16 -> GitVersion.VersionCalculation.VersionStrategies GitVersion.VersionCalculation.VersionStrategyBase GitVersion.VersionCalculation.VersionStrategyBase.Context.get -> GitVersion.GitVersionContext! GitVersion.VersionCalculation.VersionStrategyBase.VersionStrategyBase(System.Lazy! versionContext) -> void diff --git a/src/GitVersion.Core/VersionCalculation/DeploymentMode.cs b/src/GitVersion.Core/VersionCalculation/DeploymentMode.cs index def5b72b1c..e6fa322591 100644 --- a/src/GitVersion.Core/VersionCalculation/DeploymentMode.cs +++ b/src/GitVersion.Core/VersionCalculation/DeploymentMode.cs @@ -4,6 +4,5 @@ public enum DeploymentMode { ManualDeployment, ContinuousDelivery, - ContinuousDeployment, - TrunkBased + ContinuousDeployment } diff --git a/src/GitVersion.Core/VersionCalculation/VariableProvider.cs b/src/GitVersion.Core/VersionCalculation/VariableProvider.cs index 75864f24e5..03b86e7fa8 100644 --- a/src/GitVersion.Core/VersionCalculation/VariableProvider.cs +++ b/src/GitVersion.Core/VersionCalculation/VariableProvider.cs @@ -79,48 +79,6 @@ public GitVersionVariables GetVariablesFor( ); } - private static SemanticVersion PromoteNumberOfCommitsToTagNumber(SemanticVersion semanticVersion, string preReleaseTagName) - { - var preReleaseTagNumber = semanticVersion.PreReleaseTag.Number; - long buildMetaDataCommitsSinceVersionSource; - var buildMetaDataCommitsSinceTag = semanticVersion.BuildMetaData.CommitsSinceTag; - - // For continuous deployment the commits since tag gets promoted to the pre-release number - if (!semanticVersion.BuildMetaData.CommitsSinceTag.HasValue) - { - preReleaseTagNumber = null; - buildMetaDataCommitsSinceVersionSource = 0; - } - else - { - // Number of commits since last tag should be added to PreRelease number if given. Remember to deduct automatic version bump. - if (preReleaseTagNumber.HasValue) - { - preReleaseTagNumber += semanticVersion.BuildMetaData.CommitsSinceTag - 1; - } - else - { - preReleaseTagNumber = semanticVersion.BuildMetaData.CommitsSinceTag; - } - buildMetaDataCommitsSinceVersionSource = semanticVersion.BuildMetaData.CommitsSinceTag.Value; - buildMetaDataCommitsSinceTag = null; // why is this set to null ? - } - - return new(semanticVersion) - { - PreReleaseTag = new(semanticVersion.PreReleaseTag) - { - Name = preReleaseTagName, - Number = preReleaseTagNumber - }, - BuildMetaData = new(semanticVersion.BuildMetaData) - { - CommitsSinceVersionSource = buildMetaDataCommitsSinceVersionSource, - CommitsSinceTag = buildMetaDataCommitsSinceTag - } - }; - } - private string? CheckAndFormatString(string? formatString, T source, string? defaultValue, string formatVarName) { string? formattedString; diff --git a/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/ConfigNextVersionVersionStrategy.cs b/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/ConfiguredNextVersionVersionStrategy.cs similarity index 77% rename from src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/ConfigNextVersionVersionStrategy.cs rename to src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/ConfiguredNextVersionVersionStrategy.cs index ce74043e45..aee6524a66 100644 --- a/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/ConfigNextVersionVersionStrategy.cs +++ b/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/ConfiguredNextVersionVersionStrategy.cs @@ -8,10 +8,13 @@ namespace GitVersion.VersionCalculation; /// BaseVersionSource is null. /// Does not increment. /// -internal class ConfigNextVersionVersionStrategy(Lazy versionContext) : VersionStrategyBase(versionContext) +internal class ConfiguredNextVersionVersionStrategy(Lazy versionContext) : VersionStrategyBase(versionContext) { public override IEnumerable GetBaseVersions(EffectiveBranchConfiguration configuration) { + if (!Context.Configuration.VersionStrategy.HasFlag(VersionStrategies.ConfiguredNextVersion)) + yield break; + var contextConfiguration = Context.Configuration; var nextVersion = contextConfiguration.NextVersion; if (!nextVersion.IsNullOrEmpty() && !Context.IsCurrentCommitTagged) diff --git a/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/MergeMessageVersionStrategy.cs b/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/MergeMessageVersionStrategy.cs index 5477d80310..00ef491390 100644 --- a/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/MergeMessageVersionStrategy.cs +++ b/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/MergeMessageVersionStrategy.cs @@ -19,7 +19,7 @@ internal class MergeMessageVersionStrategy(ILog log, Lazy ver public override IEnumerable GetBaseVersions(EffectiveBranchConfiguration configuration) { - if (!configuration.Value.TrackMergeMessage || Context.Configuration.DeploymentMode == DeploymentMode.TrunkBased) + if (!Context.Configuration.VersionStrategy.HasFlag(VersionStrategies.MergeMessage) || !configuration.Value.TrackMergeMessage) return []; var commitsPriorToThan = Context.CurrentBranch.Commits.GetCommitsPriorTo(Context.CurrentCommit.When); diff --git a/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/TaggedCommitVersionStrategy.cs b/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/TaggedCommitVersionStrategy.cs index 7b51852061..6fedc16132 100644 --- a/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/TaggedCommitVersionStrategy.cs +++ b/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/TaggedCommitVersionStrategy.cs @@ -15,7 +15,7 @@ internal sealed class TaggedCommitVersionStrategy(ITaggedSemanticVersionReposito private readonly ITaggedSemanticVersionRepository taggedSemanticVersionRepository = taggedSemanticVersionRepository.NotNull(); public override IEnumerable GetBaseVersions(EffectiveBranchConfiguration configuration) - => Context.Configuration.DeploymentMode == DeploymentMode.TrunkBased ? [] + => !Context.Configuration.VersionStrategy.HasFlag(VersionStrategies.TaggedCommit) ? [] : GetTaggedSemanticVersions(configuration).Select(CreateBaseVersion); private IEnumerable GetTaggedSemanticVersions(EffectiveBranchConfiguration configuration) diff --git a/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/TrackReleaseBranchesVersionStrategy.cs b/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/TrackReleaseBranchesVersionStrategy.cs index 1d3f88601b..1ef811eb6f 100644 --- a/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/TrackReleaseBranchesVersionStrategy.cs +++ b/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/TrackReleaseBranchesVersionStrategy.cs @@ -29,7 +29,8 @@ internal class TrackReleaseBranchesVersionStrategy(IRepositoryStore repositorySt public override IEnumerable GetBaseVersions(EffectiveBranchConfiguration configuration) { - if (Context.Configuration.DeploymentMode == DeploymentMode.TrunkBased) return []; + if (!Context.Configuration.VersionStrategy.HasFlag(VersionStrategies.TrackReleaseBranches)) + return []; return configuration.Value.TracksReleaseBranches ? ReleaseBranchBaseVersions() : []; } diff --git a/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/TrunkBasedVersionStrategy.cs b/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/TrunkBasedVersionStrategy.cs index 2052689c57..4a9bc16a63 100644 --- a/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/TrunkBasedVersionStrategy.cs +++ b/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/TrunkBasedVersionStrategy.cs @@ -66,7 +66,8 @@ internal sealed class TrunkBasedVersionStrategy( public override IEnumerable GetBaseVersions(EffectiveBranchConfiguration configuration) { - if (Context.Configuration.DeploymentMode != DeploymentMode.TrunkBased) yield break; + if (!Context.Configuration.VersionStrategy.HasFlag(VersionStrategies.TrunkBased)) + yield break; var iteration = CreateIteration(branchName: Context.CurrentBranch.Name, configuration: configuration.Value); diff --git a/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/VersionInBranchNameVersionStrategy.cs b/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/VersionInBranchNameVersionStrategy.cs index 0c9a1df281..bc7cfb215d 100644 --- a/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/VersionInBranchNameVersionStrategy.cs +++ b/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/VersionInBranchNameVersionStrategy.cs @@ -17,7 +17,8 @@ internal class VersionInBranchNameVersionStrategy(IRepositoryStore repositorySto public override IEnumerable GetBaseVersions(EffectiveBranchConfiguration configuration) { - if (Context.Configuration.DeploymentMode == DeploymentMode.TrunkBased) yield break; + if (!Context.Configuration.VersionStrategy.HasFlag(VersionStrategies.VersionInBranchName)) + yield break; if (configuration.Value.IsReleaseBranch && TryGetBaseVersion(out var baseVersion, configuration)) { diff --git a/src/GitVersion.Core/VersionCalculation/VersionStrategies.cs b/src/GitVersion.Core/VersionCalculation/VersionStrategies.cs new file mode 100644 index 0000000000..395a5d38ac --- /dev/null +++ b/src/GitVersion.Core/VersionCalculation/VersionStrategies.cs @@ -0,0 +1,13 @@ +namespace GitVersion.VersionCalculation; + +[Flags] +public enum VersionStrategies +{ + None = 0, + ConfiguredNextVersion = 1, + MergeMessage = 2, + TaggedCommit = 4, + TrackReleaseBranches = 8, + VersionInBranchName = 16, + TrunkBased = 32 +}