From a02af29799a909e7fed5e1b034aacc5d4b079be9 Mon Sep 17 00:00:00 2001 From: Simon Ejsing Date: Tue, 14 Jun 2016 11:56:39 -0700 Subject: [PATCH 1/9] Support for tagging prerelease based on branch ref spec when running in ContinuousDeployment mode. This enables pull request branches to produce unique version numbers when the pull request branch is set to ContinuousDeployment mode. --- .../VariableProviderTests.cs | 23 +++++++++++++++++++ .../Configuration/BranchConfig.cs | 4 ++++ .../Configuration/ConfigurationProvider.cs | 4 +++- src/GitVersionCore/EffectiveConfiguration.cs | 4 ++++ src/GitVersionCore/GitVersionContext.cs | 2 ++ .../OutputVariables/VariableProvider.cs | 12 ++++++++++ 6 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/GitVersionCore.Tests/VariableProviderTests.cs b/src/GitVersionCore.Tests/VariableProviderTests.cs index 285ab46692..ff596cc9a1 100644 --- a/src/GitVersionCore.Tests/VariableProviderTests.cs +++ b/src/GitVersionCore.Tests/VariableProviderTests.cs @@ -152,4 +152,27 @@ public void ProvidesVariablesInContinuousDeploymentModeForStableWhenCurrentCommi JsonOutputFormatter.ToJson(vars).ShouldMatchApproved(c => c.SubFolder("Approved")); } + + [Test] + public void ProvidesVariablesInContinuousDeploymentModeForTagNumber() + { + var semVer = new SemanticVersion + { + Major = 1, + Minor = 2, + Patch = 3, + PreReleaseTag = "PullRequest", + BuildMetaData = "5.Branch.develop" + }; + + semVer.BuildMetaData.Branch = "pull/2/merge"; + semVer.BuildMetaData.Sha = "commitSha"; + semVer.BuildMetaData.CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z"); + + var config = new TestEffectiveConfiguration(versioningMode: VersioningMode.ContinuousDeployment, tagNamePattern: @"[/-](?\d+)[-/]"); + var vars = VariableProvider.GetVariablesFor(semVer, config, false); + + vars.FullSemVer.ShouldBe("1.2.3-PullRequest2.5"); + } + } \ No newline at end of file diff --git a/src/GitVersionCore/Configuration/BranchConfig.cs b/src/GitVersionCore/Configuration/BranchConfig.cs index 821a413811..dd795fc539 100644 --- a/src/GitVersionCore/Configuration/BranchConfig.cs +++ b/src/GitVersionCore/Configuration/BranchConfig.cs @@ -14,6 +14,7 @@ public BranchConfig(BranchConfig branchConfiguration) Tag = branchConfiguration.Tag; Increment = branchConfiguration.Increment; PreventIncrementOfMergedBranchVersion = branchConfiguration.PreventIncrementOfMergedBranchVersion; + TagNamePattern = branchConfiguration.TagNamePattern; TagNumberPattern = branchConfiguration.TagNumberPattern; TrackMergeTarget = branchConfiguration.TrackMergeTarget; CommitMessageIncrementing = branchConfiguration.CommitMessageIncrementing; @@ -34,6 +35,9 @@ public BranchConfig(BranchConfig branchConfiguration) [YamlMember(Alias = "prevent-increment-of-merged-branch-version")] public bool? PreventIncrementOfMergedBranchVersion { get; set; } + [YamlMember(Alias = "tag-name-pattern")] + public string TagNamePattern { get; set; } + [YamlMember(Alias = "tag-number-pattern")] public string TagNumberPattern { get; set; } diff --git a/src/GitVersionCore/Configuration/ConfigurationProvider.cs b/src/GitVersionCore/Configuration/ConfigurationProvider.cs index dc6ecf4741..e0416e9852 100644 --- a/src/GitVersionCore/Configuration/ConfigurationProvider.cs +++ b/src/GitVersionCore/Configuration/ConfigurationProvider.cs @@ -114,9 +114,11 @@ public static void ApplyBranchDefaults(Config config, bool defaultPreventIncrement = false, VersioningMode? defaultVersioningMode = null, // Looked up from main config bool defaultTrackMergeTarget = false, - string defaultTagNumberPattern = null) + string defaultTagNumberPattern = null, + string defaultTagNamePattern = null) { branchConfig.Tag = branchConfig.Tag ?? defaultTag; + branchConfig.TagNamePattern = branchConfig.TagNamePattern ?? defaultTagNamePattern; branchConfig.TagNumberPattern = branchConfig.TagNumberPattern ?? defaultTagNumberPattern; branchConfig.Increment = branchConfig.Increment ?? defaultIncrementStrategy; branchConfig.PreventIncrementOfMergedBranchVersion = branchConfig.PreventIncrementOfMergedBranchVersion ?? defaultPreventIncrement; diff --git a/src/GitVersionCore/EffectiveConfiguration.cs b/src/GitVersionCore/EffectiveConfiguration.cs index 3f99ca0fa8..23c4ba53bf 100644 --- a/src/GitVersionCore/EffectiveConfiguration.cs +++ b/src/GitVersionCore/EffectiveConfiguration.cs @@ -15,6 +15,7 @@ public EffectiveConfiguration( string tag, string nextVersion, IncrementStrategy increment, string branchPrefixToTrim, bool preventIncrementForMergedBranchVersion, + string tagNamePattern, string tagNumberPattern, string continuousDeploymentFallbackTag, bool trackMergeTarget, @@ -37,6 +38,7 @@ IEnumerable versionFilters Increment = increment; BranchPrefixToTrim = branchPrefixToTrim; PreventIncrementForMergedBranchVersion = preventIncrementForMergedBranchVersion; + TagNamePattern = tagNamePattern; TagNumberPattern = tagNumberPattern; ContinuousDeploymentFallbackTag = continuousDeploymentFallbackTag; TrackMergeTarget = trackMergeTarget; @@ -73,6 +75,8 @@ IEnumerable versionFilters public bool PreventIncrementForMergedBranchVersion { get; private set; } + public string TagNamePattern { get; private set; } + public string TagNumberPattern { get; private set; } public string ContinuousDeploymentFallbackTag { get; private set; } diff --git a/src/GitVersionCore/GitVersionContext.cs b/src/GitVersionCore/GitVersionContext.cs index 1ede21235a..70b033b4a3 100644 --- a/src/GitVersionCore/GitVersionContext.cs +++ b/src/GitVersionCore/GitVersionContext.cs @@ -96,6 +96,7 @@ void CalculateEffectiveConfiguration() var versioningMode = currentBranchConfig.Value.VersioningMode.Value; var tag = currentBranchConfig.Value.Tag; + var tagNamePattern = currentBranchConfig.Value.TagNamePattern; var tagNumberPattern = currentBranchConfig.Value.TagNumberPattern; var incrementStrategy = currentBranchConfig.Value.Increment.Value; var preventIncrementForMergedBranchVersion = currentBranchConfig.Value.PreventIncrementOfMergedBranchVersion.Value; @@ -116,6 +117,7 @@ void CalculateEffectiveConfiguration() assemblyVersioningScheme, assemblyInformationalFormat, versioningMode, gitTagPrefix, tag, nextVersion, incrementStrategy, currentBranchConfig.Key, preventIncrementForMergedBranchVersion, + tagNamePattern, tagNumberPattern, configuration.ContinuousDeploymentFallbackTag, trackMergeTarget, majorMessage, minorMessage, patchMessage, diff --git a/src/GitVersionCore/OutputVariables/VariableProvider.cs b/src/GitVersionCore/OutputVariables/VariableProvider.cs index 7aaf205c13..7f7b669b2b 100644 --- a/src/GitVersionCore/OutputVariables/VariableProvider.cs +++ b/src/GitVersionCore/OutputVariables/VariableProvider.cs @@ -2,6 +2,7 @@ { using System; using System.ComponentModel; + using System.Text.RegularExpressions; public static class VariableProvider { @@ -16,6 +17,17 @@ public static VersionVariables GetVariablesFor(SemanticVersion semanticVersion, semanticVersion.PreReleaseTag.Name = config.ContinuousDeploymentFallbackTag; } + // Evaluate tag name pattern and append to prerelease tag + if (!string.IsNullOrEmpty(config.TagNamePattern)) + { + var match = Regex.Match(semanticVersion.BuildMetaData.Branch, config.TagNamePattern); + var numberGroup = match.Groups["number"]; + if (numberGroup.Success) + { + semanticVersion.PreReleaseTag.Name += numberGroup.Value; + } + } + // For continuous deployment the commits since tag gets promoted to the pre-release number semanticVersion.PreReleaseTag.Number = semanticVersion.BuildMetaData.CommitsSinceTag; semanticVersion.BuildMetaData.CommitsSinceVersionSource = semanticVersion.BuildMetaData.CommitsSinceTag ?? 0; From d63a4e70a8fd34334ac369d425a2842732119e6c Mon Sep 17 00:00:00 2001 From: Simon Ejsing Date: Tue, 14 Jun 2016 12:03:03 -0700 Subject: [PATCH 2/9] Fix tests and rename unit test --- src/GitVersionCore.Tests/TestEffectiveConfiguration.cs | 3 ++- src/GitVersionCore.Tests/VariableProviderTests.cs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/GitVersionCore.Tests/TestEffectiveConfiguration.cs b/src/GitVersionCore.Tests/TestEffectiveConfiguration.cs index 1d445f77d7..fdeebd7512 100644 --- a/src/GitVersionCore.Tests/TestEffectiveConfiguration.cs +++ b/src/GitVersionCore.Tests/TestEffectiveConfiguration.cs @@ -16,6 +16,7 @@ public TestEffectiveConfiguration( string nextVersion = null, string branchPrefixToTrim = "", bool preventIncrementForMergedBranchVersion = false, + string tagNamePattern = null, string tagNumberPattern = null, string continuousDeploymentFallbackTag = "ci", bool trackMergeTarget = false, @@ -29,7 +30,7 @@ public TestEffectiveConfiguration( IEnumerable versionFilters = null ) : base(assemblyVersioningScheme, assemblyInformationalFormat, versioningMode, gitTagPrefix, tag, nextVersion, IncrementStrategy.Patch, - branchPrefixToTrim, preventIncrementForMergedBranchVersion, tagNumberPattern, continuousDeploymentFallbackTag, + branchPrefixToTrim, preventIncrementForMergedBranchVersion, tagNamePattern, tagNumberPattern, continuousDeploymentFallbackTag, trackMergeTarget, majorMessage, minorMessage, patchMessage, commitMessageMode, legacySemVerPadding, buildMetaDataPadding, commitsSinceVersionSourcePadding, diff --git a/src/GitVersionCore.Tests/VariableProviderTests.cs b/src/GitVersionCore.Tests/VariableProviderTests.cs index ff596cc9a1..968b4722dc 100644 --- a/src/GitVersionCore.Tests/VariableProviderTests.cs +++ b/src/GitVersionCore.Tests/VariableProviderTests.cs @@ -154,7 +154,7 @@ public void ProvidesVariablesInContinuousDeploymentModeForStableWhenCurrentCommi } [Test] - public void ProvidesVariablesInContinuousDeploymentModeForTagNumber() + public void ProvidesVariablesInContinuousDeploymentModeWithTagNamePattern() { var semVer = new SemanticVersion { From f8cdb532cf9c47fe0e273b84c86529d3574341ff Mon Sep 17 00:00:00 2001 From: Simon Ejsing Date: Tue, 14 Jun 2016 12:46:00 -0700 Subject: [PATCH 3/9] Add documentation for new feature --- docs/configuration.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/configuration.md b/docs/configuration.md index bea563f6e1..495b14dfa8 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -1,4 +1,4 @@ -# Configuration +# Configuration GitVersion 3.0 is mainly powered by configuration and no longer has branching strategies hard coded. ## Configuration tool @@ -82,6 +82,21 @@ The options in here are: - **`tag-number-pattern:`** Pull requests require us to pull the pre-release number out of the branch name so `refs/pulls/534/merge` builds as `PullRequest.534`. This is a regex with a named capture group called `number` + - **`tag-name-pattern:`** This is similar to `tag-number-pattern` but instead of using the pull request number as the number part of the prerelease tag, the number is instead appended to the tag. + This is only applicable when the branch mode is set to ContinuousDeployment, where the prerelease tag number part is based on the number of commits since the last tag. + It enables consecutive commits to the pull request branch to generate unique full semantic version numbers when the branch is configured to use ContinuousDeployment mode and this value is set. + This is a regex with a named capture group called `number`. + Example usage: +```yaml +branches: + (pull|pull\-requests|pr)[/-]: + mode: ContinuousDeployment + tag: PullRequest + increment: Inherit + track-merge-target: true + tag-name-pattern: '[/-](?\d+)[-/]' +``` + - **`track-merge-target:`** Strategy which will look for tagged merge commits directly off the current branch. For example `develop` → `release/1.0.0` → merge into `master` and tag `1.0.0`. The tag is *not* on develop, but develop should be version `1.0.0` now. We don't envision many people needing to change most of these configuration values, but they are there if you need to. From 16de5ef58040a8ebdbdcbcea897607fac00e672d Mon Sep 17 00:00:00 2001 From: Simon Ejsing Date: Tue, 14 Jun 2016 12:48:19 -0700 Subject: [PATCH 4/9] Test wont run on mono --- src/GitVersionCore.Tests/VariableProviderTests.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/GitVersionCore.Tests/VariableProviderTests.cs b/src/GitVersionCore.Tests/VariableProviderTests.cs index 968b4722dc..d66e9acf00 100644 --- a/src/GitVersionCore.Tests/VariableProviderTests.cs +++ b/src/GitVersionCore.Tests/VariableProviderTests.cs @@ -154,6 +154,8 @@ public void ProvidesVariablesInContinuousDeploymentModeForStableWhenCurrentCommi } [Test] + [Category("NoMono")] + [Description("Won't run on Mono due to source information not being available for ShouldMatchApproved.")] public void ProvidesVariablesInContinuousDeploymentModeWithTagNamePattern() { var semVer = new SemanticVersion From d61d207ee0c77871353b7166b8d0bc9d20b7c64d Mon Sep 17 00:00:00 2001 From: Simon Ejsing Date: Wed, 15 Jun 2016 14:59:00 -0700 Subject: [PATCH 5/9] re-enable unit test on mono --- src/GitVersionCore.Tests/VariableProviderTests.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/GitVersionCore.Tests/VariableProviderTests.cs b/src/GitVersionCore.Tests/VariableProviderTests.cs index d66e9acf00..968b4722dc 100644 --- a/src/GitVersionCore.Tests/VariableProviderTests.cs +++ b/src/GitVersionCore.Tests/VariableProviderTests.cs @@ -154,8 +154,6 @@ public void ProvidesVariablesInContinuousDeploymentModeForStableWhenCurrentCommi } [Test] - [Category("NoMono")] - [Description("Won't run on Mono due to source information not being available for ShouldMatchApproved.")] public void ProvidesVariablesInContinuousDeploymentModeWithTagNamePattern() { var semVer = new SemanticVersion From 27710192e1c544a959dc7a6a227448803dc31a83 Mon Sep 17 00:00:00 2001 From: Simon Ejsing Date: Fri, 17 Jun 2016 12:22:32 -0700 Subject: [PATCH 6/9] Reuse the tagNumberPattern option for ContinuousDeployment scenario and fix for useBranchName as the tag value --- .../VariableProviderTests.cs | 22 +++++++++- .../OutputVariables/VariableProvider.cs | 13 ++++-- .../NextVersionCalculator.cs | 42 +++++++++++-------- 3 files changed, 54 insertions(+), 23 deletions(-) diff --git a/src/GitVersionCore.Tests/VariableProviderTests.cs b/src/GitVersionCore.Tests/VariableProviderTests.cs index 968b4722dc..876e39920f 100644 --- a/src/GitVersionCore.Tests/VariableProviderTests.cs +++ b/src/GitVersionCore.Tests/VariableProviderTests.cs @@ -169,10 +169,30 @@ public void ProvidesVariablesInContinuousDeploymentModeWithTagNamePattern() semVer.BuildMetaData.Sha = "commitSha"; semVer.BuildMetaData.CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z"); - var config = new TestEffectiveConfiguration(versioningMode: VersioningMode.ContinuousDeployment, tagNamePattern: @"[/-](?\d+)[-/]"); + var config = new TestEffectiveConfiguration(versioningMode: VersioningMode.ContinuousDeployment, tagNumberPattern: @"[/-](?\d+)[-/]"); var vars = VariableProvider.GetVariablesFor(semVer, config, false); vars.FullSemVer.ShouldBe("1.2.3-PullRequest2.5"); } + [Test] + public void ProvidesVariablesInContinuousDeploymentModeWithTagSetToUseBranchName() + { + var semVer = new SemanticVersion + { + Major = 1, + Minor = 2, + Patch = 3, + BuildMetaData = "5.Branch.develop" + }; + + semVer.BuildMetaData.Branch = "feature"; + semVer.BuildMetaData.Sha = "commitSha"; + semVer.BuildMetaData.CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z"); + + var config = new TestEffectiveConfiguration(versioningMode: VersioningMode.ContinuousDeployment, tag: "useBranchName"); + var vars = VariableProvider.GetVariablesFor(semVer, config, false); + + vars.FullSemVer.ShouldBe("1.2.3-feature.5"); + } } \ No newline at end of file diff --git a/src/GitVersionCore/OutputVariables/VariableProvider.cs b/src/GitVersionCore/OutputVariables/VariableProvider.cs index 7f7b669b2b..40feab562d 100644 --- a/src/GitVersionCore/OutputVariables/VariableProvider.cs +++ b/src/GitVersionCore/OutputVariables/VariableProvider.cs @@ -3,6 +3,7 @@ using System; using System.ComponentModel; using System.Text.RegularExpressions; + using GitVersion.VersionCalculation; public static class VariableProvider { @@ -14,13 +15,17 @@ public static VersionVariables GetVariablesFor(SemanticVersion semanticVersion, // Continuous Deployment always requires a pre-release tag unless the commit is tagged if (!semanticVersion.PreReleaseTag.HasTag()) { - semanticVersion.PreReleaseTag.Name = config.ContinuousDeploymentFallbackTag; + semanticVersion.PreReleaseTag.Name = NextVersionCalculator.GetBranchSpecificTag(config, semanticVersion.BuildMetaData.Branch, null); + if (string.IsNullOrEmpty(semanticVersion.PreReleaseTag.Name)) + { + semanticVersion.PreReleaseTag.Name = config.ContinuousDeploymentFallbackTag; + } } - // Evaluate tag name pattern and append to prerelease tag - if (!string.IsNullOrEmpty(config.TagNamePattern)) + // Evaluate tag number pattern and append to prerelease tag, preserving build metadata + if (!string.IsNullOrEmpty(config.TagNumberPattern)) { - var match = Regex.Match(semanticVersion.BuildMetaData.Branch, config.TagNamePattern); + var match = Regex.Match(semanticVersion.BuildMetaData.Branch, config.TagNumberPattern); var numberGroup = match.Groups["number"]; if (numberGroup.Success) { diff --git a/src/GitVersionCore/VersionCalculation/NextVersionCalculator.cs b/src/GitVersionCore/VersionCalculation/NextVersionCalculator.cs index eebc26527a..2b4bf6183c 100644 --- a/src/GitVersionCore/VersionCalculation/NextVersionCalculator.cs +++ b/src/GitVersionCore/VersionCalculation/NextVersionCalculator.cs @@ -69,24 +69,7 @@ public SemanticVersion FindVersion(GitVersionContext context) void UpdatePreReleaseTag(GitVersionContext context, SemanticVersion semanticVersion, string branchNameOverride) { - var tagToUse = context.Configuration.Tag; - if (tagToUse == "useBranchName") - { - tagToUse = "{BranchName}"; - } - if (tagToUse.Contains("{BranchName}")) - { - Logger.WriteInfo("Using branch name to calculate version tag"); - - var branchName = branchNameOverride ?? context.CurrentBranch.FriendlyName; - if (!string.IsNullOrWhiteSpace(context.Configuration.BranchPrefixToTrim)) - { - branchName = branchName.RegexReplace(context.Configuration.BranchPrefixToTrim, string.Empty, RegexOptions.IgnoreCase); - } - branchName = branchName.RegexReplace("[^a-zA-Z0-9-]", "-"); - - tagToUse = tagToUse.Replace("{BranchName}", branchName); - } + var tagToUse = GetBranchSpecificTag(context.Configuration, context.CurrentBranch.FriendlyName, branchNameOverride); int? number = null; if (!string.IsNullOrEmpty(context.Configuration.TagNumberPattern)) @@ -119,6 +102,29 @@ void UpdatePreReleaseTag(GitVersionContext context, SemanticVersion semanticVers semanticVersion.PreReleaseTag = new SemanticVersionPreReleaseTag(tagToUse, number); } + public static string GetBranchSpecificTag(EffectiveConfiguration configuration, string branchFriendlyName, string branchNameOverride) + { + var tagToUse = configuration.Tag; + if (tagToUse == "useBranchName") + { + tagToUse = "{BranchName}"; + } + if (tagToUse.Contains("{BranchName}")) + { + Logger.WriteInfo("Using branch name to calculate version tag"); + + var branchName = branchNameOverride ?? branchFriendlyName; + if (!string.IsNullOrWhiteSpace(configuration.BranchPrefixToTrim)) + { + branchName = branchName.RegexReplace(configuration.BranchPrefixToTrim, string.Empty, RegexOptions.IgnoreCase); + } + branchName = branchName.RegexReplace("[^a-zA-Z0-9-]", "-"); + + tagToUse = tagToUse.Replace("{BranchName}", branchName); + } + return tagToUse; + } + static bool MajorMinorPatchEqual(SemanticVersion lastTag, SemanticVersion baseVersion) { return lastTag.Major == baseVersion.Major && From 41ed6591f81d7e6a098d211a5a6490b76ffc69f8 Mon Sep 17 00:00:00 2001 From: Simon Ejsing Date: Fri, 17 Jun 2016 12:25:29 -0700 Subject: [PATCH 7/9] remove tagNamePattern option --- src/GitVersionCore.Tests/TestEffectiveConfiguration.cs | 3 +-- src/GitVersionCore/Configuration/BranchConfig.cs | 4 ---- src/GitVersionCore/Configuration/ConfigurationProvider.cs | 4 +--- src/GitVersionCore/EffectiveConfiguration.cs | 4 ---- src/GitVersionCore/GitVersionContext.cs | 2 -- 5 files changed, 2 insertions(+), 15 deletions(-) diff --git a/src/GitVersionCore.Tests/TestEffectiveConfiguration.cs b/src/GitVersionCore.Tests/TestEffectiveConfiguration.cs index fdeebd7512..1d445f77d7 100644 --- a/src/GitVersionCore.Tests/TestEffectiveConfiguration.cs +++ b/src/GitVersionCore.Tests/TestEffectiveConfiguration.cs @@ -16,7 +16,6 @@ public TestEffectiveConfiguration( string nextVersion = null, string branchPrefixToTrim = "", bool preventIncrementForMergedBranchVersion = false, - string tagNamePattern = null, string tagNumberPattern = null, string continuousDeploymentFallbackTag = "ci", bool trackMergeTarget = false, @@ -30,7 +29,7 @@ public TestEffectiveConfiguration( IEnumerable versionFilters = null ) : base(assemblyVersioningScheme, assemblyInformationalFormat, versioningMode, gitTagPrefix, tag, nextVersion, IncrementStrategy.Patch, - branchPrefixToTrim, preventIncrementForMergedBranchVersion, tagNamePattern, tagNumberPattern, continuousDeploymentFallbackTag, + branchPrefixToTrim, preventIncrementForMergedBranchVersion, tagNumberPattern, continuousDeploymentFallbackTag, trackMergeTarget, majorMessage, minorMessage, patchMessage, commitMessageMode, legacySemVerPadding, buildMetaDataPadding, commitsSinceVersionSourcePadding, diff --git a/src/GitVersionCore/Configuration/BranchConfig.cs b/src/GitVersionCore/Configuration/BranchConfig.cs index dd795fc539..821a413811 100644 --- a/src/GitVersionCore/Configuration/BranchConfig.cs +++ b/src/GitVersionCore/Configuration/BranchConfig.cs @@ -14,7 +14,6 @@ public BranchConfig(BranchConfig branchConfiguration) Tag = branchConfiguration.Tag; Increment = branchConfiguration.Increment; PreventIncrementOfMergedBranchVersion = branchConfiguration.PreventIncrementOfMergedBranchVersion; - TagNamePattern = branchConfiguration.TagNamePattern; TagNumberPattern = branchConfiguration.TagNumberPattern; TrackMergeTarget = branchConfiguration.TrackMergeTarget; CommitMessageIncrementing = branchConfiguration.CommitMessageIncrementing; @@ -35,9 +34,6 @@ public BranchConfig(BranchConfig branchConfiguration) [YamlMember(Alias = "prevent-increment-of-merged-branch-version")] public bool? PreventIncrementOfMergedBranchVersion { get; set; } - [YamlMember(Alias = "tag-name-pattern")] - public string TagNamePattern { get; set; } - [YamlMember(Alias = "tag-number-pattern")] public string TagNumberPattern { get; set; } diff --git a/src/GitVersionCore/Configuration/ConfigurationProvider.cs b/src/GitVersionCore/Configuration/ConfigurationProvider.cs index e0416e9852..dc6ecf4741 100644 --- a/src/GitVersionCore/Configuration/ConfigurationProvider.cs +++ b/src/GitVersionCore/Configuration/ConfigurationProvider.cs @@ -114,11 +114,9 @@ public static void ApplyBranchDefaults(Config config, bool defaultPreventIncrement = false, VersioningMode? defaultVersioningMode = null, // Looked up from main config bool defaultTrackMergeTarget = false, - string defaultTagNumberPattern = null, - string defaultTagNamePattern = null) + string defaultTagNumberPattern = null) { branchConfig.Tag = branchConfig.Tag ?? defaultTag; - branchConfig.TagNamePattern = branchConfig.TagNamePattern ?? defaultTagNamePattern; branchConfig.TagNumberPattern = branchConfig.TagNumberPattern ?? defaultTagNumberPattern; branchConfig.Increment = branchConfig.Increment ?? defaultIncrementStrategy; branchConfig.PreventIncrementOfMergedBranchVersion = branchConfig.PreventIncrementOfMergedBranchVersion ?? defaultPreventIncrement; diff --git a/src/GitVersionCore/EffectiveConfiguration.cs b/src/GitVersionCore/EffectiveConfiguration.cs index 23c4ba53bf..3f99ca0fa8 100644 --- a/src/GitVersionCore/EffectiveConfiguration.cs +++ b/src/GitVersionCore/EffectiveConfiguration.cs @@ -15,7 +15,6 @@ public EffectiveConfiguration( string tag, string nextVersion, IncrementStrategy increment, string branchPrefixToTrim, bool preventIncrementForMergedBranchVersion, - string tagNamePattern, string tagNumberPattern, string continuousDeploymentFallbackTag, bool trackMergeTarget, @@ -38,7 +37,6 @@ IEnumerable versionFilters Increment = increment; BranchPrefixToTrim = branchPrefixToTrim; PreventIncrementForMergedBranchVersion = preventIncrementForMergedBranchVersion; - TagNamePattern = tagNamePattern; TagNumberPattern = tagNumberPattern; ContinuousDeploymentFallbackTag = continuousDeploymentFallbackTag; TrackMergeTarget = trackMergeTarget; @@ -75,8 +73,6 @@ IEnumerable versionFilters public bool PreventIncrementForMergedBranchVersion { get; private set; } - public string TagNamePattern { get; private set; } - public string TagNumberPattern { get; private set; } public string ContinuousDeploymentFallbackTag { get; private set; } diff --git a/src/GitVersionCore/GitVersionContext.cs b/src/GitVersionCore/GitVersionContext.cs index 70b033b4a3..1ede21235a 100644 --- a/src/GitVersionCore/GitVersionContext.cs +++ b/src/GitVersionCore/GitVersionContext.cs @@ -96,7 +96,6 @@ void CalculateEffectiveConfiguration() var versioningMode = currentBranchConfig.Value.VersioningMode.Value; var tag = currentBranchConfig.Value.Tag; - var tagNamePattern = currentBranchConfig.Value.TagNamePattern; var tagNumberPattern = currentBranchConfig.Value.TagNumberPattern; var incrementStrategy = currentBranchConfig.Value.Increment.Value; var preventIncrementForMergedBranchVersion = currentBranchConfig.Value.PreventIncrementOfMergedBranchVersion.Value; @@ -117,7 +116,6 @@ void CalculateEffectiveConfiguration() assemblyVersioningScheme, assemblyInformationalFormat, versioningMode, gitTagPrefix, tag, nextVersion, incrementStrategy, currentBranchConfig.Key, preventIncrementForMergedBranchVersion, - tagNamePattern, tagNumberPattern, configuration.ContinuousDeploymentFallbackTag, trackMergeTarget, majorMessage, minorMessage, patchMessage, From dadb5ea764244fe7e4071a739dd2ecf8bd660d9f Mon Sep 17 00:00:00 2001 From: Simon Ejsing Date: Fri, 17 Jun 2016 12:32:15 -0700 Subject: [PATCH 8/9] update documentation to reflect the new implementation --- docs/configuration.md | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 495b14dfa8..26f9cf2eec 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -79,13 +79,10 @@ The options in here are: - **`prevent-increment-of-merged-branch-version:`** When `release-2.0.0` is merged into master, we want master to build `2.0.0`. If `release-2.0.0` is merged into develop we want it to build `2.1.0`, this option prevents incrementing after a versioned branch is merged - - **`tag-number-pattern:`** Pull requests require us to pull the pre-release number out of the branch name so `refs/pulls/534/merge` builds as `PullRequest.534`. - This is a regex with a named capture group called `number` - - - **`tag-name-pattern:`** This is similar to `tag-number-pattern` but instead of using the pull request number as the number part of the prerelease tag, the number is instead appended to the tag. - This is only applicable when the branch mode is set to ContinuousDeployment, where the prerelease tag number part is based on the number of commits since the last tag. - It enables consecutive commits to the pull request branch to generate unique full semantic version numbers when the branch is configured to use ContinuousDeployment mode and this value is set. - This is a regex with a named capture group called `number`. + - **`tag-number-pattern:`** Pull requests require us to extract the pre-release number out of the branch name so `refs/pulls/534/merge` builds as `PullRequest.534`. + This is a regex with a named capture group called `number` + If the branch mode is set to ContinuousDeployment, then the extracted `number` is appended to the name of the pre-release tag and the number portion is the number of commits since the last tag. + This enables consecutive commits to the pull request branch to generate unique full semantic version numbers when the branch is configured to use ContinuousDeployment mode. Example usage: ```yaml branches: From 959e84a8f70e0fffd248d9a35186f5dc2c3cd929 Mon Sep 17 00:00:00 2001 From: Simon Ejsing Date: Sat, 25 Jun 2016 00:06:03 -0700 Subject: [PATCH 9/9] zero pad pull tag number --- src/GitVersionCore.Tests/VariableProviderTests.cs | 2 +- src/GitVersionCore/OutputVariables/VariableProvider.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/GitVersionCore.Tests/VariableProviderTests.cs b/src/GitVersionCore.Tests/VariableProviderTests.cs index 876e39920f..7ae6e64eb3 100644 --- a/src/GitVersionCore.Tests/VariableProviderTests.cs +++ b/src/GitVersionCore.Tests/VariableProviderTests.cs @@ -172,7 +172,7 @@ public void ProvidesVariablesInContinuousDeploymentModeWithTagNamePattern() var config = new TestEffectiveConfiguration(versioningMode: VersioningMode.ContinuousDeployment, tagNumberPattern: @"[/-](?\d+)[-/]"); var vars = VariableProvider.GetVariablesFor(semVer, config, false); - vars.FullSemVer.ShouldBe("1.2.3-PullRequest2.5"); + vars.FullSemVer.ShouldBe("1.2.3-PullRequest0002.5"); } [Test] diff --git a/src/GitVersionCore/OutputVariables/VariableProvider.cs b/src/GitVersionCore/OutputVariables/VariableProvider.cs index 40feab562d..6e0eb13a18 100644 --- a/src/GitVersionCore/OutputVariables/VariableProvider.cs +++ b/src/GitVersionCore/OutputVariables/VariableProvider.cs @@ -29,7 +29,7 @@ public static VersionVariables GetVariablesFor(SemanticVersion semanticVersion, var numberGroup = match.Groups["number"]; if (numberGroup.Success) { - semanticVersion.PreReleaseTag.Name += numberGroup.Value; + semanticVersion.PreReleaseTag.Name += numberGroup.Value.PadLeft(config.BuildMetaDataPadding, '0'); } }