From 9f7761f33565e8664e7692913f62445ed9ff0cf3 Mon Sep 17 00:00:00 2001 From: Jake Ginnivan Date: Mon, 17 Nov 2014 09:09:32 +0000 Subject: [PATCH] Support nextversion in config --- .../GitHubFlow/MasterTests.cs | 47 +++++++++++++++++-- GitVersionCore/Configuration/Config.cs | 5 +- .../GitHubFlow/NextSemverCalculator.cs | 15 +++++- .../AssemblyInfoBuilder/UpdateAssemblyInfo.cs | 8 ++++ GitVersionTask/GetVersion.cs | 7 +++ 5 files changed, 77 insertions(+), 5 deletions(-) diff --git a/GitVersionCore.Tests/IntegrationTests/GitHubFlow/MasterTests.cs b/GitVersionCore.Tests/IntegrationTests/GitHubFlow/MasterTests.cs index 864ad7423c..29337f7004 100644 --- a/GitVersionCore.Tests/IntegrationTests/GitHubFlow/MasterTests.cs +++ b/GitVersionCore.Tests/IntegrationTests/GitHubFlow/MasterTests.cs @@ -1,6 +1,8 @@ -using GitVersion; +using System; +using GitVersion; using LibGit2Sharp; using NUnit.Framework; +using Shouldly; [TestFixture] public class MasterTests @@ -69,6 +71,31 @@ public void GivenARepositoryWithTagAndANextVersionTxtFile_VersionShouldMatchVers } } + [Test] + public void GivenARepositoryWithTagAndNextVersionInConfig_VersionShouldMatchVersionTxtFile() + { + const string ExpectedNextVersion = "1.1.0"; + using (var fixture = new EmptyRepositoryFixture(new Config { NextVersion = ExpectedNextVersion })) + { + const string TaggedVersion = "1.0.3"; + fixture.Repository.MakeATaggedCommit(TaggedVersion); + fixture.Repository.MakeCommits(5); + + fixture.AssertFullSemver("1.1.0+5"); + } + } + + [Test] + public void GivenARepositoryWithANextVersionTxtFileAndNextVersionInConfig_ErrorIsThrown() + { + using (var fixture = new EmptyRepositoryFixture(new Config { NextVersion = "1.1.0" })) + { + fixture.Repository.AddNextVersionTxtFile("1.1.0"); + + Should.Throw(() => fixture.AssertFullSemver("1.1.0+5")); + } + } + [Test] public void GivenARepositoryWithTagAndANextVersionTxtFileAndNoCommits_VersionShouldBeTag() { @@ -123,6 +150,20 @@ public void GivenARepositoryWithTagAndOldNextVersionTxtFile_VersionShouldBeTagWi } } + [Test] + public void GivenARepositoryWithTagAndOldNextVersionConfig_VersionShouldBeTagWithBumpedPatch() + { + const string NextVersionConfig = "1.0.0"; + using (var fixture = new EmptyRepositoryFixture(new Config { NextVersion = NextVersionConfig })) + { + const string TaggedVersion = "1.1.0"; + fixture.Repository.MakeATaggedCommit(TaggedVersion); + fixture.Repository.MakeCommits(5); + + fixture.AssertFullSemver("1.1.1+5"); + } + } + [Test] public void GivenARepositoryWithTagAndOldNextVersionTxtFileAndNoCommits_VersionShouldBeTag() { @@ -140,7 +181,7 @@ public void GivenARepositoryWithTagAndOldNextVersionTxtFileAndNoCommits_VersionS [Test] public void CanSpecifyTagPrefixes() { - using (var fixture = new EmptyRepositoryFixture(new Config{ TagPrefix = "version-"})) + using (var fixture = new EmptyRepositoryFixture(new Config { TagPrefix = "version-" })) { const string TaggedVersion = "version-1.0.3"; fixture.Repository.MakeATaggedCommit(TaggedVersion); @@ -153,7 +194,7 @@ public void CanSpecifyTagPrefixes() [Test] public void CanSpecifyTagPrefixesAsRegex() { - using (var fixture = new EmptyRepositoryFixture(new Config{ TagPrefix = "[version-|v]"})) + using (var fixture = new EmptyRepositoryFixture(new Config { TagPrefix = "[version-|v]" })) { const string TaggedVersion = "v1.0.3"; fixture.Repository.MakeATaggedCommit(TaggedVersion); diff --git a/GitVersionCore/Configuration/Config.cs b/GitVersionCore/Configuration/Config.cs index b056549a82..4b8f6cf078 100644 --- a/GitVersionCore/Configuration/Config.cs +++ b/GitVersionCore/Configuration/Config.cs @@ -9,7 +9,7 @@ public Config() AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinorPatch; DevelopBranchTag = "unstable"; ReleaseBranchTag = "beta"; - TagPrefix = "v"; + TagPrefix = "[vV]"; } public AssemblyVersioningScheme AssemblyVersioningScheme { get; set; } @@ -22,5 +22,8 @@ public Config() [YamlAlias("tag-prefix")] public string TagPrefix { get; set; } + + [YamlAlias("next-version")] + public string NextVersion { get; set; } } } \ No newline at end of file diff --git a/GitVersionCore/GitHubFlow/NextSemverCalculator.cs b/GitVersionCore/GitHubFlow/NextSemverCalculator.cs index 888e5d1bf0..9be2747f5a 100644 --- a/GitVersionCore/GitHubFlow/NextSemverCalculator.cs +++ b/GitVersionCore/GitHubFlow/NextSemverCalculator.cs @@ -1,5 +1,6 @@ namespace GitVersion { + using System; using System.Collections.Generic; using System.Linq; @@ -58,10 +59,22 @@ public IEnumerable GetPossibleVersions() } SemanticVersion fileVersion; - if (nextVersionTxtFileFinder.TryGetNextVersion(out fileVersion)) + var hasNextVersionTxtVersion = nextVersionTxtFileFinder.TryGetNextVersion(out fileVersion); + if (hasNextVersionTxtVersion && !string.IsNullOrEmpty(context.Configuration.NextVersion)) + { + throw new Exception("You cannot specify a next version in both NextVersion.txt and GitVersionConfig.yaml. Please delete NextVersion.txt and use GitVersionConfig.yaml"); + } + + if (!string.IsNullOrEmpty(context.Configuration.NextVersion)) + { + yield return SemanticVersion.Parse(context.Configuration.NextVersion, context.Configuration.TagPrefix); + } + + if (hasNextVersionTxtVersion) { yield return fileVersion; } + SemanticVersion tryGetVersion; if (mergedBranchesWithVersionFinder.TryGetVersion(out tryGetVersion)) { diff --git a/GitVersionTask/AssemblyInfoBuilder/UpdateAssemblyInfo.cs b/GitVersionTask/AssemblyInfoBuilder/UpdateAssemblyInfo.cs index fb241a92c2..107999cf2c 100644 --- a/GitVersionTask/AssemblyInfoBuilder/UpdateAssemblyInfo.cs +++ b/GitVersionTask/AssemblyInfoBuilder/UpdateAssemblyInfo.cs @@ -17,6 +17,8 @@ public class UpdateAssemblyInfo : Task public string TagPrefix { get; set; } + public string NextVersion { get; set; } + [Required] public string SolutionDirectory { get; set; } @@ -87,6 +89,7 @@ public void InnerExecute() } // TODO This should be covered by tests + // TODO would be good to not have to duplicate this in both msbuild tasks // Null is intentional. Empty string means the user has set the value to an empty string and wants to clear the tag if (DevelopBranchTag != null) { @@ -103,6 +106,11 @@ public void InnerExecute() configuration.TagPrefix = TagPrefix; } + if (NextVersion != null) + { + configuration.NextVersion = NextVersion; + } + CachedVersion semanticVersion; if (!VersionAndBranchFinder.TryGetVersion(SolutionDirectory, out semanticVersion, configuration)) { diff --git a/GitVersionTask/GetVersion.cs b/GitVersionTask/GetVersion.cs index 2c80c70996..c39ec0b480 100644 --- a/GitVersionTask/GetVersion.cs +++ b/GitVersionTask/GetVersion.cs @@ -80,6 +80,8 @@ public class GetVersion : Task public string TagPrefix { get; set; } + public string NextVersion { get; set; } + TaskLogger logger; public GetVersion() @@ -114,6 +116,11 @@ public override bool Execute() configuration.TagPrefix = TagPrefix; } + if (NextVersion != null) + { + configuration.NextVersion = NextVersion; + } + if (VersionAndBranchFinder.TryGetVersion(SolutionDirectory, out versionAndBranch, configuration)) { var thisType = typeof(GetVersion);