Skip to content

Commit a5bdfb1

Browse files
Copilotarturcic
andcommitted
Add YamlDotNet source generator support
- Added Vecc.YamlDotNet.Analyzers.StaticGenerator package - Changed init properties to set properties to support source generator - Created GitVersionConfigurationStaticContext for AOT compatibility - Updated ConfigurationSerializer to use static serializer/deserializer - Updated PublicAPI.Unshipped.txt with generated API surface Co-authored-by: arturcic <[email protected]>
1 parent 176384c commit a5bdfb1

9 files changed

+72
-44
lines changed

src/Directory.Packages.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
<PackageVersion Include="System.Security.Cryptography.Xml" Version="9.0.7" />
4545
<PackageVersion Include="System.Text.Json" Version="9.0.9" />
4646
<PackageVersion Include="YamlDotNet" Version="16.3.0" />
47+
<PackageVersion Include="Vecc.YamlDotNet.Analyzers.StaticGenerator" Version="16.3.0" />
4748
<PackageVersion Include="coverlet.msbuild" Version="6.0.4" />
4849
</ItemGroup>
4950
</Project>

src/GitVersion.Configuration/BranchConfiguration.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,72 +8,72 @@ internal record BranchConfiguration : IBranchConfiguration
88
{
99
[JsonPropertyName("mode")]
1010
[JsonPropertyDescription("The deployment mode for this branch. Can be 'ManualDeployment', 'ContinuousDelivery', 'ContinuousDeployment'.")]
11-
public DeploymentMode? DeploymentMode { get; internal init; }
11+
public DeploymentMode? DeploymentMode { get; internal set; }
1212

1313
[JsonPropertyName("label")]
1414
[JsonPropertyDescription("The label to use for this branch. Use the value {BranchName} or similar as a placeholder to insert a named capture group from RegularExpression (fx. the branch name).")]
15-
public string? Label { get; internal init; }
15+
public string? Label { get; internal set; }
1616

1717
[JsonPropertyName("increment")]
1818
[JsonPropertyDescription("The increment strategy for this branch. Can be 'Inherit', 'Patch', 'Minor', 'Major', 'None'.")]
19-
public IncrementStrategy Increment { get; internal init; }
19+
public IncrementStrategy Increment { get; internal set; }
2020

2121
[JsonIgnore]
2222
IPreventIncrementConfiguration IBranchConfiguration.PreventIncrement => PreventIncrement;
2323

2424
[JsonPropertyName("prevent-increment")]
2525
[JsonPropertyDescription("The prevent increment configuration section.")]
26-
public PreventIncrementConfiguration PreventIncrement { get; internal init; } = new();
26+
public PreventIncrementConfiguration PreventIncrement { get; internal set; } = new();
2727

2828
[JsonPropertyName("track-merge-target")]
2929
[JsonPropertyDescription("Strategy which will look for tagged merge commits directly off the current branch.")]
30-
public bool? TrackMergeTarget { get; internal init; }
30+
public bool? TrackMergeTarget { get; internal set; }
3131

3232
[JsonPropertyName("track-merge-message")]
3333
[JsonPropertyDescription("This property is a branch related property and gives the user the possibility to control the behavior of whether the merge commit message will be interpreted as a next version or not.")]
34-
public bool? TrackMergeMessage { get; internal init; }
34+
public bool? TrackMergeMessage { get; internal set; }
3535

3636
[JsonPropertyName("commit-message-incrementing")]
3737
[JsonPropertyDescription("Sets whether it should be possible to increment the version with special syntax in the commit message. Can be 'Disabled', 'Enabled' or 'MergeMessageOnly'.")]
38-
public CommitMessageIncrementMode? CommitMessageIncrementing { get; internal init; }
38+
public CommitMessageIncrementMode? CommitMessageIncrementing { get; internal set; }
3939

4040
[JsonPropertyName("regex")]
4141
[JsonPropertyDescription("The regular expression pattern to use to match this branch.")]
4242
[JsonPropertyFormat(Format.Regex)]
43-
public string? RegularExpression { get; internal init; }
43+
public string? RegularExpression { get; internal set; }
4444

4545
[JsonIgnore]
4646
string? IBranchConfiguration.RegularExpression => RegularExpression;
4747

4848
[JsonPropertyName("source-branches")]
4949
[JsonPropertyDescription("The source branches for this branch.")]
50-
public HashSet<string> SourceBranches { get; internal init; } = [];
50+
public HashSet<string> SourceBranches { get; internal set; } = [];
5151

5252
[JsonIgnore]
5353
IReadOnlyCollection<string> IBranchConfiguration.SourceBranches => SourceBranches;
5454

5555
[JsonPropertyName("is-source-branch-for")]
5656
[JsonPropertyDescription("The branches that this branch is a source branch.")]
57-
public HashSet<string> IsSourceBranchFor { get; internal init; } = [];
57+
public HashSet<string> IsSourceBranchFor { get; internal set; } = [];
5858

5959
[JsonIgnore]
6060
IReadOnlyCollection<string> IBranchConfiguration.IsSourceBranchFor => IsSourceBranchFor;
6161

6262
[JsonPropertyName("tracks-release-branches")]
6363
[JsonPropertyDescription("Indicates this branch configuration represents develop in GitFlow.")]
64-
public bool? TracksReleaseBranches { get; internal init; }
64+
public bool? TracksReleaseBranches { get; internal set; }
6565

6666
[JsonPropertyName("is-release-branch")]
6767
[JsonPropertyDescription("Indicates this branch configuration represents a release branch in GitFlow.")]
68-
public bool? IsReleaseBranch { get; internal init; }
68+
public bool? IsReleaseBranch { get; internal set; }
6969

7070
[JsonPropertyName("is-main-branch")]
7171
[JsonPropertyDescription("When using Mainline mode, this indicates that this branch is a mainline. By default main and support/* are mainlines.")]
72-
public bool? IsMainBranch { get; internal init; }
72+
public bool? IsMainBranch { get; internal set; }
7373

7474
[JsonPropertyName("pre-release-weight")]
7575
[JsonPropertyDescription("Provides a way to translate the PreReleaseLabel to a number.")]
76-
public int? PreReleaseWeight { get; internal init; }
76+
public int? PreReleaseWeight { get; internal set; }
7777

7878
public virtual IBranchConfiguration Inherit(IBranchConfiguration configuration)
7979
{

src/GitVersion.Configuration/ConfigurationSerializer.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ namespace GitVersion.Configuration;
66

77
internal class ConfigurationSerializer : IConfigurationSerializer
88
{
9-
private static IDeserializer Deserializer => new DeserializerBuilder()
9+
private static readonly GitVersionConfigurationStaticContext staticContext = new();
10+
11+
private static IDeserializer Deserializer => new StaticDeserializerBuilder(staticContext)
1012
.WithNamingConvention(HyphenatedNamingConvention.Instance)
1113
.WithTypeConverter(VersionStrategiesConverter.Instance)
1214
.WithTypeInspector(inspector => new JsonPropertyNameInspector(inspector))
1315
.Build();
1416

15-
private static ISerializer Serializer => new SerializerBuilder()
17+
private static ISerializer Serializer => new StaticSerializerBuilder(staticContext)
1618
.ConfigureDefaultValuesHandling(DefaultValuesHandling.OmitNull)
1719
.WithTypeInspector(inspector => new JsonPropertyNameInspector(inspector))
1820
.WithNamingConvention(HyphenatedNamingConvention.Instance).Build();

src/GitVersion.Configuration/GitVersion.Configuration.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
<ItemGroup>
1212
<PackageReference Include="YamlDotNet" />
13+
<PackageReference Include="Vecc.YamlDotNet.Analyzers.StaticGenerator" PrivateAssets="all" />
1314
</ItemGroup>
1415

1516
<ItemGroup>

src/GitVersion.Configuration/GitVersionConfiguration.cs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,49 +10,49 @@ internal sealed record GitVersionConfiguration : BranchConfiguration, IGitVersio
1010
{
1111
[JsonPropertyName("workflow")]
1212
[JsonPropertyDescription("The base template of the configuration to use. Possible values are: 'GitFlow/v1' or 'GitHubFlow/v1'")]
13-
public string? Workflow { get; internal init; }
13+
public string? Workflow { get; internal set; }
1414

1515
[JsonPropertyName("assembly-versioning-scheme")]
1616
[JsonPropertyDescription($"The scheme to use when setting AssemblyVersion attribute. Can be 'MajorMinorPatchTag', 'MajorMinorPatch', 'MajorMinor', 'Major', 'None'. Defaults to '{NameOfDefaultAssemblyVersioningScheme}'.")]
1717
[JsonPropertyDefault(DefaultAssemblyVersioningScheme)]
18-
public AssemblyVersioningScheme? AssemblyVersioningScheme { get; internal init; }
18+
public AssemblyVersioningScheme? AssemblyVersioningScheme { get; internal set; }
1919

2020
[JsonPropertyName("assembly-file-versioning-scheme")]
2121
[JsonPropertyDescription($"The scheme to use when setting AssemblyFileVersion attribute. Can be 'MajorMinorPatchTag', 'MajorMinorPatch', 'MajorMinor', 'Major', 'None'. Defaults to '{NameOfDefaultAssemblyFileVersioningScheme}'.")]
2222
[JsonPropertyDefault(DefaultAssemblyFileVersioningScheme)]
23-
public AssemblyFileVersioningScheme? AssemblyFileVersioningScheme { get; internal init; }
23+
public AssemblyFileVersioningScheme? AssemblyFileVersioningScheme { get; internal set; }
2424

2525
[JsonPropertyName("assembly-informational-format")]
2626
[JsonPropertyDescription($"Specifies the format of AssemblyInformationalVersion. Defaults to '{DefaultAssemblyInformationalFormat}'.")]
2727
[JsonPropertyDefault($"'{DefaultAssemblyInformationalFormat}'")]
28-
public string? AssemblyInformationalFormat { get; internal init; }
28+
public string? AssemblyInformationalFormat { get; internal set; }
2929

3030
[JsonPropertyName("assembly-versioning-format")]
3131
[JsonPropertyDescription("Specifies the format of AssemblyVersion and overwrites the value of assembly-versioning-scheme.")]
32-
public string? AssemblyVersioningFormat { get; internal init; }
32+
public string? AssemblyVersioningFormat { get; internal set; }
3333

3434
[JsonPropertyName("assembly-file-versioning-format")]
3535
[JsonPropertyDescription("Specifies the format of AssemblyFileVersion and overwrites the value of assembly-file-versioning-scheme.")]
36-
public string? AssemblyFileVersioningFormat { get; internal init; }
36+
public string? AssemblyFileVersioningFormat { get; internal set; }
3737

3838
[JsonPropertyName("tag-prefix")]
3939
[JsonPropertyDescription($"A regular expression which is used to trim Git tags before processing. Defaults to '{RegexPatterns.Configuration.DefaultTagPrefixRegexPattern}'")]
4040
[JsonPropertyDefault(RegexPatterns.Configuration.DefaultTagPrefixRegexPattern)]
4141
[JsonPropertyFormat(Format.Regex)]
42-
public string? TagPrefixPattern { get; internal init; }
42+
public string? TagPrefixPattern { get; internal set; }
4343

4444
[JsonPropertyName("version-in-branch-pattern")]
4545
[JsonPropertyDescription($"A regular expression which is used to determine the version number in the branch name or commit message (e.g., v1.0.0-LTS). Defaults to '{RegexPatterns.Configuration.DefaultVersionInBranchRegexPattern}'.")]
4646
[JsonPropertyDefault(RegexPatterns.Configuration.DefaultVersionInBranchRegexPattern)]
4747
[JsonPropertyFormat(Format.Regex)]
48-
public string? VersionInBranchPattern { get; internal init; }
48+
public string? VersionInBranchPattern { get; internal set; }
4949

5050
[JsonPropertyName("next-version")]
5151
[JsonPropertyDescription("Allows you to bump the next version explicitly. Useful for bumping main or a feature branch with breaking changes")]
5252
public string? NextVersion
5353
{
5454
get => nextVersion;
55-
internal init =>
55+
internal set =>
5656
nextVersion = int.TryParse(value, NumberStyles.Any, NumberFormatInfo.InvariantInfo, out var major)
5757
? $"{major}.0"
5858
: value;
@@ -63,75 +63,75 @@ public string? NextVersion
6363
[JsonPropertyDescription($"The regular expression to match commit messages with to perform a major version increment. Defaults to '{RegexPatterns.VersionCalculation.DefaultMajorRegexPattern}'")]
6464
[JsonPropertyDefault(RegexPatterns.VersionCalculation.DefaultMajorRegexPattern)]
6565
[JsonPropertyFormat(Format.Regex)]
66-
public string? MajorVersionBumpMessage { get; internal init; }
66+
public string? MajorVersionBumpMessage { get; internal set; }
6767

6868
[JsonPropertyName("minor-version-bump-message")]
6969
[JsonPropertyDescription($"The regular expression to match commit messages with to perform a minor version increment. Defaults to '{RegexPatterns.VersionCalculation.DefaultMinorRegexPattern}'")]
7070
[JsonPropertyDefault(RegexPatterns.VersionCalculation.DefaultMinorRegexPattern)]
7171
[JsonPropertyFormat(Format.Regex)]
72-
public string? MinorVersionBumpMessage { get; internal init; }
72+
public string? MinorVersionBumpMessage { get; internal set; }
7373

7474
[JsonPropertyName("patch-version-bump-message")]
7575
[JsonPropertyDescription($"The regular expression to match commit messages with to perform a patch version increment. Defaults to '{RegexPatterns.VersionCalculation.DefaultPatchRegexPattern}'")]
7676
[JsonPropertyDefault(RegexPatterns.VersionCalculation.DefaultPatchRegexPattern)]
7777
[JsonPropertyFormat(Format.Regex)]
78-
public string? PatchVersionBumpMessage { get; internal init; }
78+
public string? PatchVersionBumpMessage { get; internal set; }
7979

8080
[JsonPropertyName("no-bump-message")]
8181
[JsonPropertyDescription($"Used to tell GitVersion not to increment when in Mainline development mode. Defaults to '{RegexPatterns.VersionCalculation.DefaultNoBumpRegexPattern}'")]
8282
[JsonPropertyDefault(RegexPatterns.VersionCalculation.DefaultNoBumpRegexPattern)]
8383
[JsonPropertyFormat(Format.Regex)]
84-
public string? NoBumpMessage { get; internal init; }
84+
public string? NoBumpMessage { get; internal set; }
8585

8686
[JsonPropertyName("tag-pre-release-weight")]
8787
[JsonPropertyDescription($"The pre-release weight in case of tagged commits. Defaults to {StringDefaultTagPreReleaseWeight}.")]
88-
public int? TagPreReleaseWeight { get; internal init; }
88+
public int? TagPreReleaseWeight { get; internal set; }
8989

9090
[JsonPropertyName("commit-date-format")]
9191
[JsonPropertyDescription($"The format to use when calculating the commit date. Defaults to '{DefaultCommitDateFormat}'. See [Standard Date and Time Format Strings](https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings) and [Custom Date and Time Format Strings](https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings).")]
9292
[JsonPropertyDefault(DefaultCommitDateFormat)]
9393
[System.Diagnostics.CodeAnalysis.StringSyntax("DateTimeFormat")]
94-
public string? CommitDateFormat { get; internal init; }
94+
public string? CommitDateFormat { get; internal set; }
9595

9696
[JsonPropertyName("merge-message-formats")]
9797
[JsonPropertyDescription("Custom merge message formats to enable identification of merge messages that do not follow the built-in conventions.")]
98-
public Dictionary<string, string> MergeMessageFormats { get; internal init; } = [];
98+
public Dictionary<string, string> MergeMessageFormats { get; internal set; } = [];
9999

100100
[JsonIgnore]
101101
IReadOnlyDictionary<string, string> IGitVersionConfiguration.MergeMessageFormats => MergeMessageFormats;
102102

103103
[JsonPropertyName("update-build-number")]
104104
[JsonPropertyDescription($"Whether to update the build number in the project file. Defaults to {StringDefaultUpdateBuildNumber}.")]
105105
[JsonPropertyDefault(DefaultUpdateBuildNumber)]
106-
public bool UpdateBuildNumber { get; internal init; } = DefaultUpdateBuildNumber;
106+
public bool UpdateBuildNumber { get; internal set; } = DefaultUpdateBuildNumber;
107107

108108
[JsonPropertyName("semantic-version-format")]
109109
[JsonPropertyDescription($"Specifies the semantic version format that is used when parsing the string. Can be 'Strict' or 'Loose'. Defaults to '{StringDefaultSemanticVersionFormat}'.")]
110110
[JsonPropertyDefault(DefaultSemanticVersionFormat)]
111-
public SemanticVersionFormat SemanticVersionFormat { get; internal init; }
111+
public SemanticVersionFormat SemanticVersionFormat { get; internal set; }
112112

113113
[JsonIgnore]
114114
VersionStrategies IGitVersionConfiguration.VersionStrategy => VersionStrategies.Length == 0
115115
? VersionCalculation.VersionStrategies.None : VersionStrategies.Aggregate((one, another) => one | another);
116116

117117
[JsonPropertyName("strategies")]
118118
[JsonPropertyDescription($"Specifies which version strategies (one or more) will be used to determine the next version. Following values are available: '{nameof(VersionCalculation.VersionStrategies.ConfiguredNextVersion)}', '{nameof(VersionCalculation.VersionStrategies.MergeMessage)}', '{nameof(VersionCalculation.VersionStrategies.TaggedCommit)}', '{nameof(VersionCalculation.VersionStrategies.TrackReleaseBranches)}', '{nameof(VersionCalculation.VersionStrategies.VersionInBranchName)}' and '{nameof(VersionCalculation.VersionStrategies.Mainline)}'.")]
119-
public VersionStrategies[] VersionStrategies { get; internal init; } = [];
119+
public VersionStrategies[] VersionStrategies { get; internal set; } = [];
120120

121121
[JsonIgnore]
122122
IReadOnlyDictionary<string, IBranchConfiguration> IGitVersionConfiguration.Branches
123123
=> Branches.ToDictionary(element => element.Key, IBranchConfiguration (element) => element.Value);
124124

125125
[JsonPropertyName("branches")]
126126
[JsonPropertyDescription("The header for all the individual branch configuration.")]
127-
public Dictionary<string, BranchConfiguration> Branches { get; internal init; } = [];
127+
public Dictionary<string, BranchConfiguration> Branches { get; internal set; } = [];
128128

129129
[JsonIgnore]
130130
IIgnoreConfiguration IGitVersionConfiguration.Ignore => Ignore;
131131

132132
[JsonPropertyName("ignore")]
133133
[JsonPropertyDescription("The header property for the ignore configuration.")]
134-
public IgnoreConfiguration Ignore { get; internal init; } = new();
134+
public IgnoreConfiguration Ignore { get; internal set; } = new();
135135

136136
public override IBranchConfiguration Inherit(IBranchConfiguration configuration) => throw new NotSupportedException();
137137

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using YamlDotNet.Serialization;
2+
3+
namespace GitVersion.Configuration;
4+
5+
[YamlStaticContext]
6+
[YamlSerializable(typeof(GitVersionConfiguration))]
7+
[YamlSerializable(typeof(BranchConfiguration))]
8+
[YamlSerializable(typeof(IgnoreConfiguration))]
9+
[YamlSerializable(typeof(PreventIncrementConfiguration))]
10+
public partial class GitVersionConfigurationStaticContext
11+
{
12+
}

src/GitVersion.Configuration/IgnoreConfiguration.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,29 @@ namespace GitVersion.Configuration;
66
internal record IgnoreConfiguration : IIgnoreConfiguration
77
{
88
[JsonIgnore]
9-
public DateTimeOffset? Before { get; init; }
9+
public DateTimeOffset? Before { get; set; }
1010

1111
[JsonPropertyName("commits-before")]
1212
[JsonPropertyDescription("Commits before this date will be ignored. Format: yyyy-MM-ddTHH:mm:ss.")]
1313
[JsonPropertyFormat(Format.DateTime)]
1414
public string? BeforeString
1515
{
1616
get => Before?.ToString("yyyy-MM-ddTHH:mm:ssZ");
17-
init => Before = value is null ? null : DateTimeOffset.Parse(value);
17+
set => Before = value is null ? null : DateTimeOffset.Parse(value);
1818
}
1919

2020
[JsonIgnore]
2121
IReadOnlySet<string> IIgnoreConfiguration.Shas => Shas;
2222

2323
[JsonPropertyName("sha")]
2424
[JsonPropertyDescription("A sequence of SHAs to be excluded from the version calculations.")]
25-
public HashSet<string> Shas { get; init; } = [];
25+
public HashSet<string> Shas { get; set; } = [];
2626

2727
IReadOnlyCollection<string> IIgnoreConfiguration.Paths => Paths;
2828

2929
[JsonPropertyName("paths")]
3030
[JsonPropertyDescription("A sequence of file paths to be excluded from the version calculations.")]
31-
public Collection<string> Paths { get; init; } = [];
31+
public Collection<string> Paths { get; set; } = [];
3232

3333
[JsonIgnore]
3434
public bool IsEmpty => Before == null && Shas.Count == 0 && Paths.Count == 0;

src/GitVersion.Configuration/PreventIncrementConfiguration.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ internal class PreventIncrementConfiguration : IPreventIncrementConfiguration
66
{
77
[JsonPropertyName("of-merged-branch")]
88
[JsonPropertyDescription("Prevent increment when branch merged.")]
9-
public bool? OfMergedBranch { get; internal init; }
9+
public bool? OfMergedBranch { get; internal set; }
1010

1111
[JsonPropertyName("when-branch-merged")]
1212
[JsonPropertyDescription("Prevent increment when branch merged.")]
13-
public bool? WhenBranchMerged { get; internal init; }
13+
public bool? WhenBranchMerged { get; internal set; }
1414

1515
[JsonPropertyName("when-current-commit-tagged")]
1616
[JsonPropertyDescription("This branch related property controls the behavior whether to use the tagged (value set to true) or the incremented (value set to false) semantic version. Defaults to true.")]
17-
public bool? WhenCurrentCommitTagged { get; internal init; }
17+
public bool? WhenCurrentCommitTagged { get; internal set; }
1818
}

0 commit comments

Comments
 (0)