forked from GitTools/GitVersion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGitVersionConfiguration.cs
160 lines (130 loc) · 9.44 KB
/
GitVersionConfiguration.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
using System.Globalization;
using System.Text.RegularExpressions;
using GitVersion.Attributes;
using GitVersion.Extensions;
using GitVersion.VersionCalculation;
using static GitVersion.Configuration.ConfigurationConstants;
namespace GitVersion.Configuration;
internal sealed record GitVersionConfiguration : BranchConfiguration, IGitVersionConfiguration
{
[JsonPropertyName("workflow")]
[JsonPropertyDescription("The base template of the configuration to use. Possible values are: 'GitFlow/v1' or 'GitHubFlow/v1'")]
public string? Workflow { get; internal set; }
[JsonPropertyName("assembly-versioning-scheme")]
[JsonPropertyDescription($"The scheme to use when setting AssemblyVersion attribute. Can be 'MajorMinorPatchTag', 'MajorMinorPatch', 'MajorMinor', 'Major', 'None'. Defaults to '{NameOfDefaultAssemblyVersioningScheme}'.")]
[JsonPropertyDefault(DefaultAssemblyVersioningScheme)]
public AssemblyVersioningScheme? AssemblyVersioningScheme { get; internal set; }
[JsonPropertyName("assembly-file-versioning-scheme")]
[JsonPropertyDescription($"The scheme to use when setting AssemblyFileVersion attribute. Can be 'MajorMinorPatchTag', 'MajorMinorPatch', 'MajorMinor', 'Major', 'None'. Defaults to '{NameOfDefaultAssemblyFileVersioningScheme}'.")]
[JsonPropertyDefault(DefaultAssemblyFileVersioningScheme)]
public AssemblyFileVersioningScheme? AssemblyFileVersioningScheme { get; internal set; }
[JsonPropertyName("assembly-informational-format")]
[JsonPropertyDescription($"Specifies the format of AssemblyInformationalVersion. Defaults to '{DefaultAssemblyInformationalFormat}'.")]
[JsonPropertyDefault($"'{DefaultAssemblyInformationalFormat}'")]
public string? AssemblyInformationalFormat { get; internal set; }
[JsonPropertyName("assembly-versioning-format")]
[JsonPropertyDescription("Specifies the format of AssemblyVersion and overwrites the value of assembly-versioning-scheme.")]
public string? AssemblyVersioningFormat { get; internal set; }
[JsonPropertyName("assembly-file-versioning-format")]
[JsonPropertyDescription("Specifies the format of AssemblyFileVersion and overwrites the value of assembly-file-versioning-scheme.")]
public string? AssemblyFileVersioningFormat { get; internal set; }
[JsonPropertyName("tag-prefix")]
[JsonPropertyDescription($"A regular expression which is used to trim Git tags before processing. Defaults to '{DefaultTagPrefix}'")]
[JsonPropertyDefault(DefaultTagPrefix)]
[JsonPropertyFormat(Format.Regex)]
public string? TagPrefix { get; internal set; }
[JsonPropertyName("version-in-branch-pattern")]
[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 '{DefaultVersionInBranchPattern}'.")]
[JsonPropertyDefault(DefaultVersionInBranchPattern)]
[JsonPropertyFormat(Format.Regex)]
public string? VersionInBranchPattern { get; internal set; }
[JsonIgnore]
public Regex VersionInBranchRegex => versionInBranchRegex ??= new Regex(GetVersionInBranchPattern(), RegexOptions.Compiled);
private Regex? versionInBranchRegex;
private string GetVersionInBranchPattern()
{
var versionInBranchPattern = VersionInBranchPattern;
if (versionInBranchPattern.IsNullOrEmpty()) versionInBranchPattern = DefaultVersionInBranchPattern;
return $"^{versionInBranchPattern.TrimStart('^')}";
}
[JsonPropertyName("next-version")]
[JsonPropertyDescription("Allows you to bump the next version explicitly. Useful for bumping main or a feature branch with breaking changes")]
public string? NextVersion
{
get => nextVersion;
internal set =>
nextVersion = int.TryParse(value, NumberStyles.Any, NumberFormatInfo.InvariantInfo, out var major)
? $"{major}.0"
: value;
}
private string? nextVersion;
[JsonPropertyName("major-version-bump-message")]
[JsonPropertyDescription($"The regular expression to match commit messages with to perform a major version increment. Defaults to '{IncrementStrategyFinder.DefaultMajorPattern}'")]
[JsonPropertyDefault(IncrementStrategyFinder.DefaultMajorPattern)]
[JsonPropertyFormat(Format.Regex)]
public string? MajorVersionBumpMessage { get; internal set; }
[JsonPropertyName("minor-version-bump-message")]
[JsonPropertyDescription($"The regular expression to match commit messages with to perform a minor version increment. Defaults to '{IncrementStrategyFinder.DefaultMinorPattern}'")]
[JsonPropertyDefault(IncrementStrategyFinder.DefaultMinorPattern)]
[JsonPropertyFormat(Format.Regex)]
public string? MinorVersionBumpMessage { get; internal set; }
[JsonPropertyName("patch-version-bump-message")]
[JsonPropertyDescription($"The regular expression to match commit messages with to perform a patch version increment. Defaults to '{IncrementStrategyFinder.DefaultPatchPattern}'")]
[JsonPropertyDefault(IncrementStrategyFinder.DefaultPatchPattern)]
[JsonPropertyFormat(Format.Regex)]
public string? PatchVersionBumpMessage { get; internal set; }
[JsonPropertyName("no-bump-message")]
[JsonPropertyDescription($"Used to tell GitVersion not to increment when in Mainline development mode. Defaults to '{IncrementStrategyFinder.DefaultNoBumpPattern}'")]
[JsonPropertyDefault(IncrementStrategyFinder.DefaultNoBumpPattern)]
[JsonPropertyFormat(Format.Regex)]
public string? NoBumpMessage { get; internal set; }
[JsonPropertyName("tag-pre-release-weight")]
[JsonPropertyDescription($"The pre-release weight in case of tagged commits. Defaults to {StringDefaultTagPreReleaseWeight}.")]
public int? TagPreReleaseWeight { get; internal set; }
[JsonPropertyName("commit-date-format")]
[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).")]
[JsonPropertyDefault(DefaultCommitDateFormat)]
#if NET7_0_OR_GREATER
[System.Diagnostics.CodeAnalysis.StringSyntax("DateTimeFormat")] // See https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.codeanalysis.stringsyntaxattribute, https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.codeanalysis.stringsyntaxattribute.datetimeformat?view=net-7.0#system-diagnostics-codeanalysis-stringsyntaxattribute-datetimeformat
#endif
public string? CommitDateFormat { get; internal set; }
[JsonPropertyName("merge-message-formats")]
[JsonPropertyDescription("Custom merge message formats to enable identification of merge messages that do not follow the built-in conventions.")]
public Dictionary<string, string> MergeMessageFormats { get; internal set; } = new();
[JsonIgnore]
IReadOnlyDictionary<string, string> IGitVersionConfiguration.MergeMessageFormats => MergeMessageFormats;
[JsonPropertyName("update-build-number")]
[JsonPropertyDescription($"Whether to update the build number in the project file. Defaults to {StringDefaultUpdateBuildNumber}.")]
[JsonPropertyDefault(DefaultUpdateBuildNumber)]
public bool UpdateBuildNumber { get; internal set; } = DefaultUpdateBuildNumber;
[JsonPropertyName("semantic-version-format")]
[JsonPropertyDescription($"Specifies the semantic version format that is used when parsing the string. Can be 'Strict' or 'Loose'. Defaults to '{StringDefaultSemanticVersionFormat}'.")]
[JsonPropertyDefault(DefaultSemanticVersionFormat)]
public SemanticVersionFormat SemanticVersionFormat { get; internal set; }
[JsonIgnore]
VersionStrategies IGitVersionConfiguration.VersionStrategy => VersionStrategies.Length == 0
? VersionCalculation.VersionStrategies.None : VersionStrategies.Aggregate((one, another) => one | another);
[JsonPropertyName("strategies")]
[JsonPropertyDescription($"Specifies which version strategies (one or more) will be used to determine the next version. Following values are available: 'ConfiguredNextVersion', 'MergeMessage', 'TaggedCommit', 'TrackReleaseBranches', 'VersionInBranchName' and 'TrunkBased'.")]
public VersionStrategies[] VersionStrategies { get; internal set; } = [];
[JsonIgnore]
IReadOnlyDictionary<string, IBranchConfiguration> IGitVersionConfiguration.Branches
=> Branches.ToDictionary(element => element.Key, element => (IBranchConfiguration)element.Value);
[JsonPropertyName("branches")]
[JsonPropertyDescription("The header for all the individual branch configuration.")]
public Dictionary<string, BranchConfiguration> Branches { get; internal set; } = new();
[JsonIgnore]
IIgnoreConfiguration IGitVersionConfiguration.Ignore => Ignore;
[JsonPropertyName("ignore")]
[JsonPropertyDescription("The header property for the ignore configuration.")]
public IgnoreConfiguration Ignore { get; internal set; } = new();
public override IBranchConfiguration Inherit(IBranchConfiguration configuration) => throw new NotSupportedException();
public string ToJsonString()
{
var stringBuilder = new StringBuilder();
using var stream = new StringWriter(stringBuilder);
ConfigurationSerializer.Write(this, stream);
stream.Flush();
return stringBuilder.ToString();
}
}