Skip to content

Throw error when user is using legacy configuration values #342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
1 change: 1 addition & 0 deletions GitVersion.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=PossibleMistakenCallToGetType_002E2/@EntryIndexedValue">ERROR</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=PossibleNullReferenceException/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=PrivateFieldCanBeConvertedToLocalVariable/@EntryIndexedValue">ERROR</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=RedundantArgumentNameForLiteralExpression/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=RedundantAssignment/@EntryIndexedValue">ERROR</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=RedundantBaseConstructorCall/@EntryIndexedValue">ERROR</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=RedundantBoolCompare/@EntryIndexedValue">ERROR</s:String>
Expand Down
13 changes: 7 additions & 6 deletions GitVersionCore.Tests/ConfigProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public void CanInheritVersioningMode()
SetupConfigFileContent(text);
var config = ConfigurationProvider.Provide(gitDirectory, fileSystem);
config.Branches["develop"].VersioningMode.ShouldBe(VersioningMode.ContinuousDeployment);
config.Release.VersioningMode.ShouldBe(VersioningMode.ContinuousDelivery);
config.Develop.Tag.ShouldBe("unstable");
config.Branches["develop"].Tag.ShouldBe("unstable");
config.Branches["release[/-]"].VersioningMode.ShouldBe(VersioningMode.ContinuousDelivery);
}

[Test]
Expand All @@ -76,10 +76,11 @@ public void CanReadOldDocument()
release-branch-tag: rc
";
SetupConfigFileContent(text);
var config = ConfigurationProvider.Provide(gitDirectory, fileSystem);
config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinor);
config.Branches["develop"].Tag.ShouldBe("alpha");
config.Branches["release[/-]"].Tag.ShouldBe("rc");
var error = Should.Throw<OldConfigurationException>(() => ConfigurationProvider.Provide(gitDirectory, fileSystem));
error.Message.ShouldContainWithoutWhitespace(@"GitVersionConfig.yaml contains old configuration, please fix the following errors:
assemblyVersioningScheme has been replaced by assembly-versioning-scheme
develop-branch-tag has been replaced by branch specific configuration.See https://github.com/ParticularLabs/GitVersion/wiki/Branch-Specific-Configuration
release-branch-tag has been replaced by branch specific configuration.See https://github.com/ParticularLabs/GitVersion/wiki/Branch-Specific-Configuration");
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,9 @@ public void CanHandleContinuousDelivery()
[Test]
public void CanClearDevelopTagViaConfig()
{
using (var fixture = new EmptyRepositoryFixture(new Config
{
Develop = {Tag= ""}
}))
var config = new Config();
config.Branches["develop"].Tag = "";
using (var fixture = new EmptyRepositoryFixture(config))
{
fixture.Repository.MakeATaggedCommit("1.0.0");
fixture.Repository.CreateBranch("develop").Checkout();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ public void CanTakeVersionFromReleaseBranch()
[Test]
public void CanTakeVersionFromReleaseBranchWithTagOverriden()
{
using (var fixture = new EmptyRepositoryFixture(new Config { ReleaseBranchTag = "rc" }))
var config = new Config();
config.Branches["release[/-]"].Tag = "rc";
using (var fixture = new EmptyRepositoryFixture(config))
{
fixture.Repository.MakeATaggedCommit("1.0.3");
fixture.Repository.CreateBranch("develop");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ public void CanTakeVersionFromReleaseBranch()
[Test]
public void CanTakeVersionFromReleaseBranchWithTagOverriden()
{
using (var fixture = new EmptyRepositoryFixture(new Config { ReleaseBranchTag = "rc" }))
var config = new Config();
config.Branches["release[/-]"].Tag = "rc";
using (var fixture = new EmptyRepositoryFixture(config))
{
fixture.Repository.MakeATaggedCommit("1.0.3");
fixture.Repository.MakeCommits(5);
Expand Down
57 changes: 6 additions & 51 deletions GitVersionCore/Configuration/Config.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
namespace GitVersion
{
using System;
using System.Collections.Generic;
using System.Linq;

using YamlDotNet.Serialization;

public class Config
Expand All @@ -16,44 +14,19 @@ public Config()
{
AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinorPatch;
TagPrefix = "[vV]";
VersioningMode = VersioningMode.ContinuousDelivery;
Branches["release[/-]"] = new BranchConfig { Tag = "beta" };
Branches["hotfix[/-]"] = new BranchConfig { Tag = "beta" };
Branches["develop"] = new BranchConfig { Tag = "unstable" };
VersioningMode = VersioningMode.ContinuousDelivery;
Develop.VersioningMode = VersioningMode.ContinuousDeployment;
Branches["develop"] = new BranchConfig
{
Tag = "unstable",
VersioningMode = VersioningMode.ContinuousDeployment
};
}

[YamlAlias("assembly-versioning-scheme")]
public AssemblyVersioningScheme AssemblyVersioningScheme { get; set; }

[YamlAlias("develop-branch-tag")]
[Obsolete]
public string DevelopBranchTag
{
set
{
Develop.Tag = value;
}
get
{
return Develop.Tag;
}
}

[YamlAlias("release-branch-tag")]
[Obsolete]
public string ReleaseBranchTag
{
set
{
Release.Tag = value;
}
get
{
return Release.Tag;
}
}

[YamlAlias("mode")]
public VersioningMode VersioningMode
{
Expand Down Expand Up @@ -97,23 +70,5 @@ private T MergeObjects<T>(T target, T source)

[YamlAlias("next-version")]
public string NextVersion { get; set; }

[Obsolete]
public BranchConfig Develop
{
get
{
return Branches["develop"];
}
}

[Obsolete]
public BranchConfig Release
{
get
{
return Branches["release[/-]"];
}
}
}
}
7 changes: 1 addition & 6 deletions GitVersionCore/Configuration/ConfigurationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@ public static Config Provide(string gitDirectory, IFileSystem fileSystem)
if (fileSystem.Exists(configFilePath))
{
var readAllText = fileSystem.ReadAllText(configFilePath);
if (oldAssemblyVersioningScheme.IsMatch(readAllText))
{
readAllText = oldAssemblyVersioningScheme.Replace(readAllText, "assembly-versioning-scheme");
fileSystem.WriteAllText(configFilePath, readAllText);
Logger.WriteWarning("Found legacy configuration value 'assemblyVersioningScheme', replaced with 'assembly-versioning-scheme");
}
LegacyConfigNotifier.Notify(new StringReader(readAllText));

return ConfigReader.Read(new StringReader(readAllText));
}
Expand Down
18 changes: 18 additions & 0 deletions GitVersionCore/Configuration/LegacyConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace GitVersion
{
using YamlDotNet.Serialization;

/// <summary>
/// Obsolete properties are added to this, so we can check to see if they are used and provide good error messages for migration
/// </summary>
public class LegacyConfig
{
public string assemblyVersioningScheme { get; set; }

[YamlAlias("develop-branch-tag")]
public string DevelopBranchTag { get; set; }

[YamlAlias("release-branch-tag")]
public string ReleaseBranchTag { get; set; }
}
}
33 changes: 33 additions & 0 deletions GitVersionCore/Configuration/LegacyConfigNotifier.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
namespace GitVersion
{
using System.Collections.Generic;
using System.IO;
using System.Linq;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;

public class LegacyConfigNotifier
{
public static void Notify(StringReader reader)
{
var deserializer = new Deserializer(null, new NullNamingConvention(), ignoreUnmatched: true);
var legacyConfig = deserializer.Deserialize<LegacyConfig>(reader);
if (legacyConfig == null)
return;

var issues = new List<string>();

if (legacyConfig.assemblyVersioningScheme != null)
issues.Add("assemblyVersioningScheme has been replaced by assembly-versioning-scheme");

if (legacyConfig.DevelopBranchTag != null)
issues.Add("develop-branch-tag has been replaced by branch specific configuration. See https://github.com/ParticularLabs/GitVersion/wiki/Branch-Specific-Configuration");

if (legacyConfig.ReleaseBranchTag != null)
issues.Add("release-branch-tag has been replaced by branch specific configuration. See https://github.com/ParticularLabs/GitVersion/wiki/Branch-Specific-Configuration");

if (issues.Any())
throw new OldConfigurationException("GitVersionConfig.yaml contains old configuration, please fix the following errors:\r\n" + string.Join("\r\n", issues));
}
}
}
19 changes: 19 additions & 0 deletions GitVersionCore/Configuration/OldConfigurationException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace GitVersion
{
using System;
using System.Runtime.Serialization;

[Serializable]
public class OldConfigurationException : Exception
{
public OldConfigurationException(string message) : base(message)
{
}

protected OldConfigurationException(
SerializationInfo info,
StreamingContext context) : base(info, context)
{
}
}
}
3 changes: 3 additions & 0 deletions GitVersionCore/GitVersionCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@
<Compile Include="Configuration\Config.cs" />
<Compile Include="Configuration\ConfigReader.cs" />
<Compile Include="Configuration\ConfigurationProvider.cs" />
<Compile Include="Configuration\LegacyConfig.cs" />
<Compile Include="Configuration\LegacyConfigNotifier.cs" />
<Compile Include="Configuration\OldConfigurationException.cs" />
<Compile Include="GitFlow\BranchFinders\BranchCommitDifferenceFinder.cs" />
<Compile Include="GitFlow\BranchFinders\RecentTagVersionExtractor.cs" />
<Compile Include="Helpers\FileSystem.cs" />
Expand Down
14 changes: 0 additions & 14 deletions GitVersionTask/AssemblyInfoBuilder/UpdateAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ public class UpdateAssemblyInfo : Task
{
public string AssemblyVersioningScheme { get; set; }

public string DevelopBranchTag { get; set; }

public string ReleaseBranchTag { get; set; }

public string TagPrefix { get; set; }

public string NextVersion { get; set; }
Expand Down Expand Up @@ -101,16 +97,6 @@ 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)
{
configuration.DevelopBranchTag = DevelopBranchTag;
}

if (ReleaseBranchTag != null)
{
configuration.ReleaseBranchTag = ReleaseBranchTag;
}

if (TagPrefix != null)
{
configuration.TagPrefix = TagPrefix;
Expand Down
14 changes: 0 additions & 14 deletions GitVersionTask/GetVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ public class GetVersion : Task
[Output]
public string NuGetVersion { get; set; }

public string DevelopBranchTag { get; set; }

public string ReleaseBranchTag { get; set; }

public string TagPrefix { get; set; }

public string NextVersion { get; set; }
Expand All @@ -104,16 +100,6 @@ public override bool Execute()

// TODO This should be covered by tests
// 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)
{
configuration.DevelopBranchTag = DevelopBranchTag;
}

if (ReleaseBranchTag != null)
{
configuration.ReleaseBranchTag = ReleaseBranchTag;
}

if (TagPrefix != null)
{
configuration.TagPrefix = TagPrefix;
Expand Down