Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/GitVersion.App.Tests/ArgumentParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,13 @@ private static IEnumerable<TestCaseData> OverrideConfigWithSingleOptionTestData(
UpdateBuildNumber = true
}
);
yield return new TestCaseData(
"strategies=[\"None\",\"Mainline\"]",
new GitVersionConfiguration
{
VersionStrategies = [VersionStrategies.None, VersionStrategies.Mainline]
}
);
}

[TestCaseSource(nameof(OverrideConfigWithMultipleOptionsTestData))]
Expand Down
4 changes: 3 additions & 1 deletion src/GitVersion.App/OverrideConfigurationOptionParser.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using GitVersion.Configuration;
using GitVersion.VersionCalculation;

namespace GitVersion;

Expand Down Expand Up @@ -45,7 +46,8 @@ private static bool IsSupportedPropertyType(Type propertyType)
return unwrappedType == typeof(string)
|| unwrappedType.IsEnum
|| unwrappedType == typeof(int)
|| unwrappedType == typeof(bool);
|| unwrappedType == typeof(bool)
|| unwrappedType == typeof(VersionStrategies[]);
}

internal void SetValue(string key, string value) => overrideConfiguration[key] = QuotedStringHelpers.UnquoteText(value);
Expand Down
1 change: 1 addition & 0 deletions src/GitVersion.Configuration/ConfigurationSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ internal class ConfigurationSerializer : IConfigurationSerializer
{
private static IDeserializer Deserializer => new DeserializerBuilder()
.WithNamingConvention(HyphenatedNamingConvention.Instance)
.WithTypeConverter(VersionStrategiesConverter.Instance)
.WithTypeInspector(inspector => new JsonPropertyNameInspector(inspector))
.Build();

Expand Down
54 changes: 54 additions & 0 deletions src/GitVersion.Configuration/VersionStrategiesConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using GitVersion.VersionCalculation;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;

namespace GitVersion.Configuration;

internal class VersionStrategiesConverter : IYamlTypeConverter
{
public static readonly IYamlTypeConverter Instance = new VersionStrategiesConverter();

public bool Accepts(Type type) => type == typeof(VersionStrategies[]);

public object? ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeserializer)
{
List<VersionStrategies> strategies = new();

if (parser.TryConsume<SequenceStart>(out var _))
{
while (!parser.TryConsume<SequenceEnd>(out var _))
{
string data = parser.Consume<Scalar>().Value;

var strategy = Enum.Parse<VersionStrategies>(data);
strategies.Add(strategy);
}
}
else
{
string data = parser.Consume<Scalar>().Value;

var deserializer = new DeserializerBuilder()
.WithNamingConvention(UnderscoredNamingConvention.Instance)
.Build();

strategies = deserializer.Deserialize<List<VersionStrategies>>(data);
}

return strategies.ToArray();
}

public void WriteYaml(IEmitter emitter, object? value, Type type, ObjectSerializer serializer)
{
VersionStrategies[] strategies = (VersionStrategies[])value!;

var s = new SerializerBuilder()
.JsonCompatible()
.Build();
var data = s.Serialize(strategies);

emitter.Emit(new Scalar(data));
}
}