diff --git a/build.ps1 b/build.ps1 index 65007bc6be..6c85e9e8c9 100644 --- a/build.ps1 +++ b/build.ps1 @@ -43,13 +43,30 @@ $Arguments = @{ exclusive=$Exclusive; nuget_useinprocessclient=$true; }.GetEnumerator() | ForEach-Object { - if ($_.value -ne "") { "--{0}=`"{1}`"" -f $_.key, $_.value } + if ($($_.Key -ceq "dryrun") -or ($_.Key -ceq "exclusive")) { + if ($_.Value -eq $true) { + # switches must not be assigned true or false, but must be passed to indicate true. + "--{0}" -f $_.Key + } + } + else { + if ($_.Value -cne "") { + if ($_.Value -as [string] -contains " ") { + $_.Value = "$($_.Value)" # if it contains spaces, enclose it. + } + "--{0}={1}" -f $_.Key, $_.Value + } + } }; +$Arguments | Join-String -Separator " " | Write-Verbose + # Start Cake Write-Host "Running build stage $Stage..." -& dotnet run --project build/$Stage/$Stage.csproj -- $Arguments $ScriptArgs +$cmdline = "& dotnet run --project build/$Stage/$Stage.csproj -- $Arguments $ScriptArgs" +Write-Verbose $cmdline +Invoke-Command -ScriptBlock ([scriptblock]::Create($cmdline)) if ($env:APPVEYOR) { $host.SetShouldExit($LASTEXITCODE) diff --git a/build/common/Lifetime/BuildLifetimeBase.cs b/build/common/Lifetime/BuildLifetimeBase.cs index ec4a52be57..32552961d8 100644 --- a/build/common/Lifetime/BuildLifetimeBase.cs +++ b/build/common/Lifetime/BuildLifetimeBase.cs @@ -30,12 +30,11 @@ public override void Setup(T context, ISetupContext info) context.Information("Running BuildPrepare..."); return; } - var gitVersionTool = context.GetGitVersionDotnetToolLocation(); var gitVersionSettings = new GitVersionSettings { OutputTypes = new() { GitVersionOutput.Json, GitVersionOutput.BuildServer }, ToolPath = context.Tools.Resolve(new[] { "dotnet.exe", "dotnet" }), - ArgumentCustomization = args => args.Prepend(gitVersionTool!.FullPath) + ArgumentCustomization = args => args.Prepend(context.GetGitVersionDotnetToolLocation()?.FullPath ?? throw new FileNotFoundException("Failed to locate the Release build of gitversion.dll in ./tools/gitversion. Try running \"./build.ps1 -Stage build -Target BuildPrepare\"")) }; var gitVersion = context.GitVersion(gitVersionSettings); diff --git a/schemas/6.0/GitVersion.configuration.json b/schemas/6.0/GitVersion.configuration.json index f5ba56ef05..13029c7d44 100644 --- a/schemas/6.0/GitVersion.configuration.json +++ b/schemas/6.0/GitVersion.configuration.json @@ -10,7 +10,8 @@ "type": "string" }, "assembly-file-versioning-scheme": { - "description": "The scheme to use when setting AssemblyFileVersion attribute. Can be \u0027MajorMinorPatchTag\u0027, \u0027MajorMinorPatch\u0027, \u0027MajorMinor\u0027, \u0027Major\u0027, \u0027None\u0027.", + "description": "The scheme to use when setting AssemblyFileVersion attribute. Can be 'MajorMinorPatchTag', 'MajorMinorPatch', 'MajorMinor', 'Major', 'None'. Defaults to 'MajorMinorPatch'.", + "default": "MajorMinorPatch", "enum": [ "MajorMinorPatchTag", "MajorMinorPatch", @@ -20,7 +21,8 @@ ] }, "assembly-informational-format": { - "description": "Specifies the format of AssemblyInformationalVersion. The default value is {InformationalVersion}.", + "description": "Specifies the format of AssemblyInformationalVersion. Defaults to '{InformationalVersion}'.", + "default": "'{InformationalVersion}'", "type": "string" }, "assembly-versioning-format": { @@ -28,7 +30,8 @@ "type": "string" }, "assembly-versioning-scheme": { - "description": "The scheme to use when setting AssemblyVersion attribute. Can be \u0027MajorMinorPatchTag\u0027, \u0027MajorMinorPatch\u0027, \u0027MajorMinor\u0027, \u0027Major\u0027, \u0027None\u0027.", + "description": "The scheme to use when setting AssemblyVersion attribute. Can be 'MajorMinorPatchTag', 'MajorMinorPatch', 'MajorMinor', 'Major', 'None'. Defaults to 'MajorMinorPatch'.", + "default": "MajorMinorPatch", "enum": [ "MajorMinorPatchTag", "MajorMinorPatch", @@ -45,9 +48,8 @@ } }, "commit-date-format": { - "format": "date-time", - "pattern": "\u0027yyyy-MM-dd\u0027", - "description": "The format to use when calculating the commit date. Defaults to \u0027yyyy-MM-dd\u0027.", + "description": "The format to use when calculating the commit date. Defaults to 'yyyy-MM-dd'. 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).", + "default": "yyyy-MM-dd", "type": "string" }, "commit-message-incrementing": { @@ -58,7 +60,7 @@ "type": "object", "properties": { "commits-before": { - "$ref": "#/$defs/nullableOfDateTimeOffset" + "$ref": "#/$defs/string3" }, "sha": { "$ref": "#/$defs/hashSetOfString2" @@ -85,8 +87,8 @@ }, "major-version-bump-message": { "format": "regex", - "pattern": "\u0027\\\u002Bsemver:\\s?(breaking|major)\u0027", - "description": "The regular expression to match commit messages with to perform a major version increment. Default set to \u0027\\\u002Bsemver:\\s?(breaking|major)\u0027", + "description": "The regular expression to match commit messages with to perform a major version increment. Defaults to '\\+semver:\\s?(breaking|major)'", + "default": "\\+semver:\\s?(breaking|major)", "type": "string" }, "merge-message-formats": { @@ -98,8 +100,8 @@ }, "minor-version-bump-message": { "format": "regex", - "pattern": "\u0027\\\u002Bsemver:\\s?(feature|minor)\u0027", - "description": "The regular expression to match commit messages with to perform a minor version increment. Default set to \u0027\\\u002Bsemver:\\s?(feature|minor)\u0027", + "description": "The regular expression to match commit messages with to perform a minor version increment. Defaults to '\\+semver:\\s?(feature|minor)'", + "default": "\\+semver:\\s?(feature|minor)", "type": "string" }, "next-version": { @@ -108,14 +110,14 @@ }, "no-bump-message": { "format": "regex", - "pattern": "\u0027\\\u002Bsemver:\\s?(none|skip)\u0027", - "description": "Used to tell GitVersion not to increment when in Mainline development mode. . Default set to \u0027\\\u002Bsemver:\\s?(none|skip)\u0027", + "description": "Used to tell GitVersion not to increment when in Mainline development mode. Defaults to '\\+semver:\\s?(none|skip)'", + "default": "\\+semver:\\s?(none|skip)", "type": "string" }, "patch-version-bump-message": { "format": "regex", - "pattern": "\u0027\\\u002Bsemver:\\s?(fix|patch)\u0027", - "description": "The regular expression to match commit messages with to perform a patch version increment. Default set to \u0027\\\u002Bsemver:\\s?(fix|patch)\u0027", + "description": "The regular expression to match commit messages with to perform a patch version increment. Defaults to '\\+semver:\\s?(fix|patch)'", + "default": "\\+semver:\\s?(fix|patch)", "type": "string" }, "pre-release-weight": { @@ -128,7 +130,8 @@ "$ref": "#/$defs/string2" }, "semantic-version-format": { - "description": "Specifies the semantic version format that is used when parsing the string. Can be \u0027Strict\u0027 or \u0027Loose\u0027.", + "description": "Specifies the semantic version format that is used when parsing the string. Can be 'Strict' or 'Loose'. Defaults to 'Strict'.", + "default": "Strict", "enum": [ "Strict", "Loose" @@ -138,7 +141,9 @@ "$ref": "#/$defs/hashSetOfString1" }, "tag-prefix": { - "description": "A regular expression which is used to trim Git tags before processing. Defaults to [vV]?", + "format": "regex", + "description": "A regular expression which is used to trim Git tags before processing. Defaults to '[vV]?'", + "default": "[vV]?", "type": "string" }, "tag-pre-release-weight": { @@ -159,17 +164,20 @@ }, "update-build-number": { "description": "Whether to update the build number in the project file. Defaults to true.", + "default": "true", "type": "boolean" }, "version-in-branch-pattern": { - "description": "A regular expression which is used to determine the version number in the branch name or commit message (e.g., v1.0.0-LTS). The default value is \u0027(?\u003Cversion\u003E[vV]?\\d\u002B(\\.\\d\u002B)?(\\.\\d\u002B)?).*\u0027.", + "format": "regex", + "description": "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 '(?[vV]?\\d+(\\.\\d+)?(\\.\\d+)?).*'.", + "default": "(?[vV]?\\d+(\\.\\d+)?(\\.\\d+)?).*", "type": "string" }, "mode": { "$ref": "#/$defs/nullableOfVersioningMode" }, "workflow": { - "description": "The base template of the configuration to use. Possible values are: GitFlow/v1 or GitHubFlow/v1", + "description": "The base template of the configuration to use. Possible values are: 'GitFlow/v1' or 'GitHubFlow/v1'", "type": "string" } }, @@ -225,7 +233,7 @@ } }, "nullableOfCommitMessageIncrementMode": { - "description": "Sets whether it should be possible to increment the version with special syntax in the commit message. Can be \u0027Disabled\u0027, \u0027Enabled\u0027 or \u0027MergeMessageOnly\u0027.", + "description": "Sets whether it should be possible to increment the version with special syntax in the commit message. Can be 'Disabled', 'Enabled' or 'MergeMessageOnly'.", "enum": [ "Enabled", "Disabled", @@ -233,7 +241,7 @@ ] }, "incrementStrategy": { - "description": "The increment strategy for this branch. Can be \u0027Inherit\u0027, \u0027Patch\u0027, \u0027Minor\u0027, \u0027Major\u0027, \u0027None\u0027.", + "description": "The increment strategy for this branch. Can be 'Inherit', 'Patch', 'Minor', 'Major', 'None'.", "enum": [ "None", "Major", @@ -270,8 +278,8 @@ }, "string1": { "format": "regex", - "pattern": "[/-](?\u003Cnumber\u003E\\d\u002B)[-/]", - "description": "The regular expression pattern to use to extract the number from the branch name. Defaults to \u0027[/-](?\u003Cnumber\u003E\\d\u002B)[-/]\u0027.", + "description": "The regular expression pattern to use to extract the number from the branch name. Defaults to '[/-](?\\d+)'.", + "default": "[/-](?\\d+)", "type": "string" }, "nullableOfInt32": { @@ -289,6 +297,7 @@ ] }, "string2": { + "format": "regex", "description": "The regular expression pattern to use to match this branch.", "type": "string" }, @@ -322,231 +331,17 @@ ] }, "nullableOfVersioningMode": { - "description": "The versioning mode for this branch. Can be \u0027ContinuousDelivery\u0027, \u0027ContinuousDeployment\u0027, \u0027Mainline\u0027.", + "description": "The versioning mode for this branch. Can be 'ContinuousDelivery', 'ContinuousDeployment', 'Mainline'.", "enum": [ "ContinuousDelivery", "ContinuousDeployment", "Mainline" ] }, - "nullableOfDateTimeOffset": { + "string3": { "format": "date-time", - "pattern": "\u0027yyyy-MM-ddTHH:mm:ss\u0027", "description": "Commits before this date will be ignored. Format: yyyy-MM-ddTHH:mm:ss.", - "type": [ - "object", - "null" - ], - "properties": { - "date": { - "$ref": "#/$defs/dateTime" - }, - "date-time": { - "$ref": "#/$defs/dateTime" - }, - "day": { - "$ref": "#/$defs/integer" - }, - "day-of-week": { - "enum": [ - "Sunday", - "Monday", - "Tuesday", - "Wednesday", - "Thursday", - "Friday", - "Saturday" - ], - "readOnly": true - }, - "day-of-year": { - "$ref": "#/$defs/integer" - }, - "hour": { - "$ref": "#/$defs/integer" - }, - "local-date-time": { - "$ref": "#/$defs/dateTime" - }, - "microsecond": { - "$ref": "#/$defs/integer" - }, - "millisecond": { - "$ref": "#/$defs/integer" - }, - "minute": { - "$ref": "#/$defs/integer" - }, - "month": { - "$ref": "#/$defs/integer" - }, - "nanosecond": { - "$ref": "#/$defs/integer" - }, - "offset": { - "$ref": "#/$defs/timeSpan" - }, - "second": { - "$ref": "#/$defs/integer" - }, - "ticks": { - "$ref": "#/$defs/integer1" - }, - "time-of-day": { - "$ref": "#/$defs/timeSpan" - }, - "utc-date-time": { - "$ref": "#/$defs/dateTime" - }, - "utc-ticks": { - "$ref": "#/$defs/integer1" - }, - "year": { - "$ref": "#/$defs/integer" - } - } - }, - "dateTimeOffset": { - "type": [ - "object", - "null" - ], - "properties": { - "date": { - "$ref": "#/$defs/dateTime" - }, - "date-time": { - "$ref": "#/$defs/dateTime" - }, - "day": { - "$ref": "#/$defs/integer" - }, - "day-of-week": { - "enum": [ - "Sunday", - "Monday", - "Tuesday", - "Wednesday", - "Thursday", - "Friday", - "Saturday" - ], - "readOnly": true - }, - "day-of-year": { - "$ref": "#/$defs/integer" - }, - "hour": { - "$ref": "#/$defs/integer" - }, - "local-date-time": { - "$ref": "#/$defs/dateTime" - }, - "microsecond": { - "$ref": "#/$defs/integer" - }, - "millisecond": { - "$ref": "#/$defs/integer" - }, - "minute": { - "$ref": "#/$defs/integer" - }, - "month": { - "$ref": "#/$defs/integer" - }, - "nanosecond": { - "$ref": "#/$defs/integer" - }, - "offset": { - "$ref": "#/$defs/timeSpan" - }, - "second": { - "$ref": "#/$defs/integer" - }, - "ticks": { - "$ref": "#/$defs/integer1" - }, - "time-of-day": { - "$ref": "#/$defs/timeSpan" - }, - "utc-date-time": { - "$ref": "#/$defs/dateTime" - }, - "utc-ticks": { - "$ref": "#/$defs/integer1" - }, - "year": { - "$ref": "#/$defs/integer" - } - } - }, - "dateTime": { - "type": "string", - "format": "date-time", - "readOnly": true - }, - "integer": { - "type": "integer", - "readOnly": true - }, - "timeSpan": { - "type": "object", - "properties": { - "days": { - "$ref": "#/$defs/integer" - }, - "hours": { - "$ref": "#/$defs/integer" - }, - "microseconds": { - "$ref": "#/$defs/integer" - }, - "milliseconds": { - "$ref": "#/$defs/integer" - }, - "minutes": { - "$ref": "#/$defs/integer" - }, - "nanoseconds": { - "$ref": "#/$defs/integer" - }, - "seconds": { - "$ref": "#/$defs/integer" - }, - "ticks": { - "$ref": "#/$defs/integer1" - }, - "total-days": { - "$ref": "#/$defs/number" - }, - "total-hours": { - "$ref": "#/$defs/number" - }, - "total-microseconds": { - "$ref": "#/$defs/number" - }, - "total-milliseconds": { - "$ref": "#/$defs/number" - }, - "total-minutes": { - "$ref": "#/$defs/number" - }, - "total-nanoseconds": { - "$ref": "#/$defs/number" - }, - "total-seconds": { - "$ref": "#/$defs/number" - } - }, - "readOnly": true - }, - "integer1": { - "type": "integer", - "readOnly": true - }, - "number": { - "type": "number", - "readOnly": true + "type": "string" }, "hashSetOfString2": { "description": "A sequence of SHAs to be excluded from the version calculations.", diff --git a/schemas/6.0/GitVersion.json b/schemas/6.0/GitVersion.json index a9efbf4725..ef663864a3 100644 --- a/schemas/6.0/GitVersion.json +++ b/schemas/6.0/GitVersion.json @@ -59,7 +59,7 @@ ] }, "MajorMinorPatch": { - "description": "Major, Minor and Patch joined together, separated by \u0027.\u0027.", + "description": "Major, Minor and Patch joined together, separated by '.'.", "type": "string" }, "Minor": { diff --git a/src/GitVersion.Configuration/BranchConfiguration.cs b/src/GitVersion.Configuration/BranchConfiguration.cs index 19cfa26714..f17ad061f8 100644 --- a/src/GitVersion.Configuration/BranchConfiguration.cs +++ b/src/GitVersion.Configuration/BranchConfiguration.cs @@ -23,8 +23,9 @@ internal record BranchConfiguration : IBranchConfiguration public bool? PreventIncrementOfMergedBranchVersion { get; internal set; } [JsonPropertyName("label-number-pattern")] - [JsonPropertyDescription(@"The regular expression pattern to use to extract the number from the branch name. Defaults to '[/-](?\d+)[-/]'.")] - [JsonPropertyPattern(@"[/-](?\d+)[-/]")] + [JsonPropertyDescription($"The regular expression pattern to use to extract the number from the branch name. Defaults to '{ConfigurationConstants.DefaultLabelNumberPattern}'.")] + [JsonPropertyDefault(ConfigurationConstants.DefaultLabelNumberPattern)] + [JsonPropertyFormat(Format.Regex)] public string? LabelNumberPattern { get; internal set; } [JsonPropertyName("track-merge-target")] @@ -41,6 +42,7 @@ internal record BranchConfiguration : IBranchConfiguration [JsonPropertyName("regex")] [JsonPropertyDescription("The regular expression pattern to use to match this branch.")] + [JsonPropertyFormat(Format.Regex)] public string? RegularExpression { get; internal set; } [JsonIgnore] diff --git a/src/GitVersion.Configuration/ConfigurationSerializer.cs b/src/GitVersion.Configuration/ConfigurationSerializer.cs index f29a19a1b3..69aeecef8b 100644 --- a/src/GitVersion.Configuration/ConfigurationSerializer.cs +++ b/src/GitVersion.Configuration/ConfigurationSerializer.cs @@ -43,7 +43,7 @@ public override IEnumerable GetProperties(Type type, object { var descriptor = new PropertyDescriptor(p); var member = p.GetCustomAttribute(); - if (member is { Name: { } }) + if (member is { Name: not null }) { descriptor.Name = member.Name; } diff --git a/src/GitVersion.Configuration/GitFlowConfigurationBuilder.cs b/src/GitVersion.Configuration/GitFlowConfigurationBuilder.cs index 5338e45ec1..2cd2be716f 100644 --- a/src/GitVersion.Configuration/GitFlowConfigurationBuilder.cs +++ b/src/GitVersion.Configuration/GitFlowConfigurationBuilder.cs @@ -1,4 +1,3 @@ -using GitVersion.Extensions; using GitVersion.VersionCalculation; namespace GitVersion.Configuration; @@ -11,18 +10,18 @@ private GitFlowConfigurationBuilder() { WithConfiguration(new GitVersionConfiguration { - AssemblyFileVersioningScheme = AssemblyFileVersioningScheme.MajorMinorPatch, - AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinorPatch, - CommitDateFormat = "yyyy-MM-dd", + AssemblyFileVersioningScheme = ConfigurationConstants.DefaultAssemblyFileVersioningScheme, + AssemblyVersioningScheme = ConfigurationConstants.DefaultAssemblyVersioningScheme, + CommitDateFormat = ConfigurationConstants.DefaultCommitDateFormat, MajorVersionBumpMessage = IncrementStrategyFinder.DefaultMajorPattern, MinorVersionBumpMessage = IncrementStrategyFinder.DefaultMinorPattern, NoBumpMessage = IncrementStrategyFinder.DefaultNoBumpPattern, PatchVersionBumpMessage = IncrementStrategyFinder.DefaultPatchPattern, - SemanticVersionFormat = SemanticVersionFormat.Strict, + SemanticVersionFormat = ConfigurationConstants.DefaultSemanticVersionFormat, TagPrefix = ConfigurationConstants.DefaultTagPrefix, VersionInBranchPattern = ConfigurationConstants.DefaultVersionInBranchPattern, - TagPreReleaseWeight = 60000, - UpdateBuildNumber = true, + TagPreReleaseWeight = ConfigurationConstants.DefaultTagPreReleaseWeight, + UpdateBuildNumber = ConfigurationConstants.DefaultUpdateBuildNumber, VersioningMode = VersioningMode.ContinuousDeployment, RegularExpression = string.Empty, Label = ConfigurationConstants.BranchNamePlaceholder, @@ -118,7 +117,7 @@ private GitFlowConfigurationBuilder() HotfixBranch.Name }, Label = "PullRequest", - LabelNumberPattern = @"[/-](?\d+)", + LabelNumberPattern = ConfigurationConstants.DefaultLabelNumberPattern, PreReleaseWeight = 30000 }); diff --git a/src/GitVersion.Configuration/GitHubFlowConfigurationBuilder.cs b/src/GitVersion.Configuration/GitHubFlowConfigurationBuilder.cs index a56a638e5c..24684b21ad 100644 --- a/src/GitVersion.Configuration/GitHubFlowConfigurationBuilder.cs +++ b/src/GitVersion.Configuration/GitHubFlowConfigurationBuilder.cs @@ -1,4 +1,3 @@ -using GitVersion.Extensions; using GitVersion.VersionCalculation; namespace GitVersion.Configuration; @@ -11,18 +10,18 @@ private GitHubFlowConfigurationBuilder() { WithConfiguration(new GitVersionConfiguration { - AssemblyFileVersioningScheme = AssemblyFileVersioningScheme.MajorMinorPatch, - AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinorPatch, - CommitDateFormat = "yyyy-MM-dd", + AssemblyFileVersioningScheme = ConfigurationConstants.DefaultAssemblyFileVersioningScheme, + AssemblyVersioningScheme = ConfigurationConstants.DefaultAssemblyVersioningScheme, + CommitDateFormat = ConfigurationConstants.DefaultCommitDateFormat, MajorVersionBumpMessage = IncrementStrategyFinder.DefaultMajorPattern, MinorVersionBumpMessage = IncrementStrategyFinder.DefaultMinorPattern, NoBumpMessage = IncrementStrategyFinder.DefaultNoBumpPattern, PatchVersionBumpMessage = IncrementStrategyFinder.DefaultPatchPattern, - SemanticVersionFormat = SemanticVersionFormat.Strict, + SemanticVersionFormat = ConfigurationConstants.DefaultSemanticVersionFormat, TagPrefix = ConfigurationConstants.DefaultTagPrefix, VersionInBranchPattern = ConfigurationConstants.DefaultVersionInBranchPattern, - TagPreReleaseWeight = 60000, - UpdateBuildNumber = true, + TagPreReleaseWeight = ConfigurationConstants.DefaultTagPreReleaseWeight, + UpdateBuildNumber = ConfigurationConstants.DefaultUpdateBuildNumber, VersioningMode = VersioningMode.ContinuousDeployment, RegularExpression = string.Empty, Label = ConfigurationConstants.BranchNamePlaceholder, @@ -95,7 +94,7 @@ private GitHubFlowConfigurationBuilder() FeatureBranch.Name }, Label = "PullRequest", - LabelNumberPattern = @"[/-](?\d+)", + LabelNumberPattern = ConfigurationConstants.DefaultLabelNumberPattern, PreReleaseWeight = 30000 }); diff --git a/src/GitVersion.Configuration/GitVersionConfiguration.cs b/src/GitVersion.Configuration/GitVersionConfiguration.cs index 3d27c0decc..a87959a8d9 100644 --- a/src/GitVersion.Configuration/GitVersionConfiguration.cs +++ b/src/GitVersion.Configuration/GitVersionConfiguration.cs @@ -2,25 +2,30 @@ 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")] + [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'.")] + [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'.")] + [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. The default value is {InformationalVersion}.")] + [JsonPropertyDescription($"Specifies the format of AssemblyInformationalVersion. Defaults to '{DefaultAssemblyInformationalFormat}'.")] + [JsonPropertyDefault($"'{DefaultAssemblyInformationalFormat}'")] public string? AssemblyInformationalFormat { get; internal set; } [JsonPropertyName("assembly-versioning-format")] @@ -32,11 +37,15 @@ internal sealed record GitVersionConfiguration : BranchConfiguration, IGitVersio public string? AssemblyFileVersioningFormat { get; internal set; } [JsonPropertyName("tag-prefix")] - [JsonPropertyDescription($"A regular expression which is used to trim Git tags before processing. Defaults to {ConfigurationConstants.DefaultTagPrefix}")] + [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). The default value is '{ConfigurationConstants.DefaultVersionInBranchPattern}'.")] + [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] @@ -46,7 +55,7 @@ internal sealed record GitVersionConfiguration : BranchConfiguration, IGitVersio private string GetVersionInBranchPattern() { var versionInBranchPattern = VersionInBranchPattern; - if (versionInBranchPattern.IsNullOrEmpty()) versionInBranchPattern = ConfigurationConstants.DefaultVersionInBranchPattern; + if (versionInBranchPattern.IsNullOrEmpty()) versionInBranchPattern = DefaultVersionInBranchPattern; return $"^{versionInBranchPattern.TrimStart('^')}"; } @@ -63,32 +72,39 @@ public string? NextVersion private string? nextVersion; [JsonPropertyName("major-version-bump-message")] - [JsonPropertyDescription(@"The regular expression to match commit messages with to perform a major version increment. Default set to '\+semver:\s?(breaking|major)'")] - [JsonPropertyPattern(@"'\+semver:\s?(breaking|major)'")] + [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. Default set to '\+semver:\s?(feature|minor)'")] - [JsonPropertyPattern(@"'\+semver:\s?(feature|minor)'")] + [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. Default set to '\+semver:\s?(fix|patch)'")] - [JsonPropertyPattern(@"'\+semver:\s?(fix|patch)'")] + [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. . Default set to '\+semver:\s?(none|skip)'")] - [JsonPropertyPattern(@"'\+semver:\s?(none|skip)'")] + [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 60000.")] + [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 'yyyy-MM-dd'.")] - [JsonPropertyPattern("'yyyy-MM-dd'", PatternFormat.DateTime)] + [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")] @@ -99,11 +115,13 @@ public string? NextVersion IReadOnlyDictionary IGitVersionConfiguration.MergeMessageFormats => MergeMessageFormats; [JsonPropertyName("update-build-number")] - [JsonPropertyDescription("Whether to update the build number in the project file. Defaults to true.")] - public bool UpdateBuildNumber { get; internal set; } = true; + [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'.")] + [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] diff --git a/src/GitVersion.Configuration/IgnoreConfiguration.cs b/src/GitVersion.Configuration/IgnoreConfiguration.cs index 92c02db4f9..4f1796d7a7 100644 --- a/src/GitVersion.Configuration/IgnoreConfiguration.cs +++ b/src/GitVersion.Configuration/IgnoreConfiguration.cs @@ -4,10 +4,17 @@ namespace GitVersion.Configuration; internal record IgnoreConfiguration : IIgnoreConfiguration { + [JsonIgnore] + public DateTimeOffset? Before { get; init; } + [JsonPropertyName("commits-before")] [JsonPropertyDescription("Commits before this date will be ignored. Format: yyyy-MM-ddTHH:mm:ss.")] - [JsonPropertyPattern("'yyyy-MM-ddTHH:mm:ss'", PatternFormat.DateTime)] - public DateTimeOffset? Before { get; init; } + [JsonPropertyFormat(Format.DateTime)] + public string? BeforeString + { + get => Before?.ToString("yyyy-MM-ddTHH:mm:ssZ"); + init => Before = value is null ? null : DateTimeOffset.Parse(value); + } [JsonIgnore] IReadOnlyCollection IIgnoreConfiguration.Shas => Shas; diff --git a/src/GitVersion.Core/Configuration/ConfigurationConstants.cs b/src/GitVersion.Core/Configuration/ConfigurationConstants.cs index 80593a9b74..c0296ee261 100644 --- a/src/GitVersion.Core/Configuration/ConfigurationConstants.cs +++ b/src/GitVersion.Core/Configuration/ConfigurationConstants.cs @@ -1,10 +1,26 @@ +using GitVersion.Extensions; + namespace GitVersion.Configuration; internal static class ConfigurationConstants { + internal const string NameOfDefaultAssemblyVersioningScheme = nameof(AssemblyVersioningScheme.MajorMinorPatch); + internal const string NameOfDefaultAssemblyFileVersioningScheme = nameof(AssemblyFileVersioningScheme.MajorMinorPatch); + internal const string StringDefaultSemanticVersionFormat = nameof(SemanticVersionFormat.Strict); + internal const string StringDefaultTagPreReleaseWeight = "60000"; + internal const string StringDefaultUpdateBuildNumber = "true"; + + public const AssemblyVersioningScheme DefaultAssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinorPatch; + public const AssemblyFileVersioningScheme DefaultAssemblyFileVersioningScheme = AssemblyFileVersioningScheme.MajorMinorPatch; + public const SemanticVersionFormat DefaultSemanticVersionFormat = SemanticVersionFormat.Strict; + public const string DefaultAssemblyInformationalFormat = "{InformationalVersion}"; public const string DefaultTagPrefix = "[vV]?"; public const string DefaultVersionInBranchPattern = @"(?[vV]?\d+(\.\d+)?(\.\d+)?).*"; + public const string DefaultCommitDateFormat = "yyyy-MM-dd"; public const string BranchNamePlaceholder = "{BranchName}"; + public const string DefaultLabelNumberPattern = @"[/-](?\d+)"; + public const bool DefaultUpdateBuildNumber = true; + public const int DefaultTagPreReleaseWeight = 60000; public const string MainBranchKey = "main"; public const string MasterBranchKey = "master"; diff --git a/src/GitVersion.Core/Core/Attributes/JsonPropertyDefaultAttribute.cs b/src/GitVersion.Core/Core/Attributes/JsonPropertyDefaultAttribute.cs new file mode 100644 index 0000000000..f2a8f01fd6 --- /dev/null +++ b/src/GitVersion.Core/Core/Attributes/JsonPropertyDefaultAttribute.cs @@ -0,0 +1,47 @@ +using GitVersion.Extensions; + +namespace GitVersion.Attributes; + +[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)] +public sealed class JsonPropertyDefaultAttribute : JsonAttribute +{ + /// + /// Initializes a new instance of with the specified default property value. + /// + /// The default value of the property. + public JsonPropertyDefaultAttribute(string? value) => Value = value ?? "null"; + + /// + public JsonPropertyDefaultAttribute(bool value) : this(value ? "true" : "false") { } + + /// + /// The Enum value is converted to string, preferring the symbol name over the numeral if possible. + public JsonPropertyDefaultAttribute(SemanticVersionFormat value) : this(value.ToString()) { } + /// + public JsonPropertyDefaultAttribute(AssemblyVersioningScheme value) : this(value.ToString()) { } + /// + public JsonPropertyDefaultAttribute(AssemblyFileVersioningScheme value) : this(value.ToString()) { } + + /// + /// Depending on the Type of the boxed value, the resulting string will be automatically enclosed with single-quotes. If the boxed value is NOT a string and is converted to a string from a numeric , object, array, boolean, or null-only type, then it will NOT be enclosed with single-quotes. + public JsonPropertyDefaultAttribute(object? boxedValue) + { + if (boxedValue is not null) + { + var type = boxedValue.GetType(); + var typedObj = Convert.ChangeType(boxedValue, type); + Value = typedObj.ToString() ?? string.Empty; + if (Value == type.ToString()) + Value = JsonSerializer.Serialize(typedObj, type); + } + else + { + Value = "null"; + } + } + + /// + /// The description of the property. + /// + public string Value { get; } +} diff --git a/src/GitVersion.Core/Core/Attributes/JsonPropertyFormatAttribute.cs b/src/GitVersion.Core/Core/Attributes/JsonPropertyFormatAttribute.cs new file mode 100644 index 0000000000..9ce8825a39 --- /dev/null +++ b/src/GitVersion.Core/Core/Attributes/JsonPropertyFormatAttribute.cs @@ -0,0 +1,47 @@ +namespace GitVersion.Attributes; + +/// +/// The format keyword allows for basic semantic identification of certain kinds of string values that are commonly used. For example, because JSON doesn't have a "DateTime" type, dates need to be encoded as strings. format allows the schema author to indicate that the string value should be interpreted as a date. By default, format is just an annotation and does not effect validation. +/// Optionally, validator implementations can [...] enable format to function as an assertion rather than just an annotation. +/// +/// +[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)] +public sealed class JsonPropertyFormatAttribute : JsonAttribute +{ + /// + /// Initializes a new instance of with the specified format for string-encoded property values. JSON validators may use this annotation to constrain properties to certain pre-define, string-encoded types. + /// + /// The string format. + public JsonPropertyFormatAttribute(Format format) => Format = format; + + /// + /// The format of the string. + /// + public Format Format { get; } +} + +/// +/// Enum bindings for Json.Schema.Formats of JsonSchema.Net 5.2.7 +/// +public enum Format +{ + Date, + DateTime, + Duration, + Email, + Hostname, + IdnEmail, + IdnHostname, + Ipv4, + Ipv6, + Iri, + IriReference, + JsonPointer, + Regex, + RelativeJsonPointer, + Time, + Uri, + UriReference, + UriTemplate, + Uuid +} diff --git a/src/GitVersion.Core/Core/Attributes/JsonPropertyPatternAttribute.cs b/src/GitVersion.Core/Core/Attributes/JsonPropertyPatternAttribute.cs deleted file mode 100644 index 3375f4fb37..0000000000 --- a/src/GitVersion.Core/Core/Attributes/JsonPropertyPatternAttribute.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace GitVersion.Attributes; - -[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)] -public sealed class JsonPropertyPatternAttribute : JsonAttribute -{ - /// - /// Initializes a new instance of with the specified property pattern. - /// - /// The pattern of the property. - /// The pattern format - public JsonPropertyPatternAttribute(string pattern, PatternFormat format = PatternFormat.Regex) - { - Pattern = pattern; - Format = format; - } - - /// - /// The pattern of the property. - /// - public string Pattern { get; } - - /// - /// The format of the pattern. - /// - public PatternFormat Format { get; } -} - -public enum PatternFormat -{ - /// - /// The pattern is a regular expression. - /// - Regex, - - /// - /// The pattern is a datetime pattern. - /// - DateTime -} diff --git a/src/GitVersion.Core/PublicAPI.Unshipped.txt b/src/GitVersion.Core/PublicAPI.Unshipped.txt index a13a12c8a0..9bf862ff13 100644 --- a/src/GitVersion.Core/PublicAPI.Unshipped.txt +++ b/src/GitVersion.Core/PublicAPI.Unshipped.txt @@ -19,16 +19,40 @@ GitVersion.AssemblySettingsInfo.EnsureAssemblyInfo -> bool GitVersion.AssemblySettingsInfo.Files -> System.Collections.Generic.ISet! GitVersion.AssemblySettingsInfo.UpdateAssemblyInfo -> bool GitVersion.AssemblySettingsInfo.UpdateProjectFiles -> bool +GitVersion.Attributes.Format +GitVersion.Attributes.Format.Date = 0 -> GitVersion.Attributes.Format +GitVersion.Attributes.Format.DateTime = 1 -> GitVersion.Attributes.Format +GitVersion.Attributes.Format.Duration = 2 -> GitVersion.Attributes.Format +GitVersion.Attributes.Format.Email = 3 -> GitVersion.Attributes.Format +GitVersion.Attributes.Format.Hostname = 4 -> GitVersion.Attributes.Format +GitVersion.Attributes.Format.IdnEmail = 5 -> GitVersion.Attributes.Format +GitVersion.Attributes.Format.IdnHostname = 6 -> GitVersion.Attributes.Format +GitVersion.Attributes.Format.Ipv4 = 7 -> GitVersion.Attributes.Format +GitVersion.Attributes.Format.Ipv6 = 8 -> GitVersion.Attributes.Format +GitVersion.Attributes.Format.Iri = 9 -> GitVersion.Attributes.Format +GitVersion.Attributes.Format.IriReference = 10 -> GitVersion.Attributes.Format +GitVersion.Attributes.Format.JsonPointer = 11 -> GitVersion.Attributes.Format +GitVersion.Attributes.Format.Regex = 12 -> GitVersion.Attributes.Format +GitVersion.Attributes.Format.RelativeJsonPointer = 13 -> GitVersion.Attributes.Format +GitVersion.Attributes.Format.Time = 14 -> GitVersion.Attributes.Format +GitVersion.Attributes.Format.Uri = 15 -> GitVersion.Attributes.Format +GitVersion.Attributes.Format.UriReference = 16 -> GitVersion.Attributes.Format +GitVersion.Attributes.Format.UriTemplate = 17 -> GitVersion.Attributes.Format +GitVersion.Attributes.Format.Uuid = 18 -> GitVersion.Attributes.Format +GitVersion.Attributes.JsonPropertyDefaultAttribute +GitVersion.Attributes.JsonPropertyDefaultAttribute.JsonPropertyDefaultAttribute(object? boxedValue) -> void +GitVersion.Attributes.JsonPropertyDefaultAttribute.Value.get -> string! +GitVersion.Attributes.JsonPropertyDefaultAttribute.JsonPropertyDefaultAttribute(bool value) -> void +GitVersion.Attributes.JsonPropertyDefaultAttribute.JsonPropertyDefaultAttribute(string? value) -> void +GitVersion.Attributes.JsonPropertyDefaultAttribute.JsonPropertyDefaultAttribute(GitVersion.Extensions.AssemblyFileVersioningScheme value) -> void +GitVersion.Attributes.JsonPropertyDefaultAttribute.JsonPropertyDefaultAttribute(GitVersion.Extensions.AssemblyVersioningScheme value) -> void +GitVersion.Attributes.JsonPropertyDefaultAttribute.JsonPropertyDefaultAttribute(GitVersion.SemanticVersionFormat value) -> void GitVersion.Attributes.JsonPropertyDescriptionAttribute GitVersion.Attributes.JsonPropertyDescriptionAttribute.Description.get -> string! GitVersion.Attributes.JsonPropertyDescriptionAttribute.JsonPropertyDescriptionAttribute(string! description) -> void -GitVersion.Attributes.JsonPropertyPatternAttribute -GitVersion.Attributes.JsonPropertyPatternAttribute.Format.get -> GitVersion.Attributes.PatternFormat -GitVersion.Attributes.JsonPropertyPatternAttribute.JsonPropertyPatternAttribute(string! pattern, GitVersion.Attributes.PatternFormat format = GitVersion.Attributes.PatternFormat.Regex) -> void -GitVersion.Attributes.JsonPropertyPatternAttribute.Pattern.get -> string! -GitVersion.Attributes.PatternFormat -GitVersion.Attributes.PatternFormat.DateTime = 1 -> GitVersion.Attributes.PatternFormat -GitVersion.Attributes.PatternFormat.Regex = 0 -> GitVersion.Attributes.PatternFormat +GitVersion.Attributes.JsonPropertyFormatAttribute +GitVersion.Attributes.JsonPropertyFormatAttribute.Format.get -> GitVersion.Attributes.Format +GitVersion.Attributes.JsonPropertyFormatAttribute.JsonPropertyFormatAttribute(GitVersion.Attributes.Format format) -> void GitVersion.AuthenticationInfo GitVersion.AuthenticationInfo.AuthenticationInfo() -> void GitVersion.AuthenticationInfo.Password.get -> string? @@ -655,7 +679,7 @@ GitVersion.VersionCalculation.IEffectiveBranchConfigurationFinder GitVersion.VersionCalculation.IEffectiveBranchConfigurationFinder.GetConfigurations(GitVersion.IBranch! branch, GitVersion.Configuration.IGitVersionConfiguration! configuration) -> System.Collections.Generic.IEnumerable! GitVersion.VersionCalculation.IIncrementStrategyFinder GitVersion.VersionCalculation.IIncrementStrategyFinder.DetermineIncrementedField(GitVersion.ICommit? currentCommit, GitVersion.VersionCalculation.BaseVersion! baseVersion, GitVersion.Configuration.EffectiveConfiguration! configuration) -> GitVersion.VersionField -GitVersion.VersionCalculation.IIncrementStrategyFinder.GetIncrementForCommits(string? majorVersionBumpMessage, string? minorVersionBumpMessage, string? patchVersionBumpMessage, string? noBumpMessage, System.Collections.Generic.IEnumerable! commits) -> GitVersion.VersionField? +GitVersion.VersionCalculation.IIncrementStrategyFinder.GetIncrementForCommits(string? majorVersionBumpMessage, string? minorVersionBumpMessage, string? patchVersionBumpMessage, string? noBumpMessage, GitVersion.ICommit![]! commits) -> GitVersion.VersionField? GitVersion.VersionCalculation.INextVersionCalculator GitVersion.VersionCalculation.INextVersionCalculator.FindVersion() -> GitVersion.VersionCalculation.NextVersion! GitVersion.VersionCalculation.IVariableProvider diff --git a/src/GitVersion.Core/VersionCalculation/Abstractions/IIncrementStrategyFinder.cs b/src/GitVersion.Core/VersionCalculation/Abstractions/IIncrementStrategyFinder.cs index 92ea4a1338..c7d0c9b576 100644 --- a/src/GitVersion.Core/VersionCalculation/Abstractions/IIncrementStrategyFinder.cs +++ b/src/GitVersion.Core/VersionCalculation/Abstractions/IIncrementStrategyFinder.cs @@ -8,6 +8,6 @@ public interface IIncrementStrategyFinder VersionField? GetIncrementForCommits( string? majorVersionBumpMessage, string? minorVersionBumpMessage, string? patchVersionBumpMessage, string? noBumpMessage, - IEnumerable commits + ICommit[] commits ); } diff --git a/src/GitVersion.Core/VersionCalculation/IncrementStrategyFinder.cs b/src/GitVersion.Core/VersionCalculation/IncrementStrategyFinder.cs index dd8e02fc2b..42849f1f9f 100644 --- a/src/GitVersion.Core/VersionCalculation/IncrementStrategyFinder.cs +++ b/src/GitVersion.Core/VersionCalculation/IncrementStrategyFinder.cs @@ -57,7 +57,7 @@ public VersionField DetermineIncrementedField(ICommit? currentCommit, BaseVersio } public VersionField? GetIncrementForCommits(string? majorVersionBumpMessage, string? minorVersionBumpMessage, - string? patchVersionBumpMessage, string? noBumpMessage, IEnumerable commits) + string? patchVersionBumpMessage, string? noBumpMessage, ICommit[] commits) { commits.NotNull(); @@ -71,7 +71,7 @@ public VersionField DetermineIncrementedField(ICommit? currentCommit, BaseVersio .Where(v => v != null) .ToList(); - return increments.Any() + return increments.Count != 0 ? increments.Max() : null; } @@ -100,7 +100,7 @@ public VersionField DetermineIncrementedField(ICommit? currentCommit, BaseVersio minorVersionBumpMessage: configuration.MinorVersionBumpMessage, patchVersionBumpMessage: configuration.PatchVersionBumpMessage, noBumpMessage: configuration.NoBumpMessage, - commits: commits + commits: commits.ToArray() ); } diff --git a/src/GitVersion.Core/VersionCalculation/VersionCalculators/MainlineVersionCalculator.cs b/src/GitVersion.Core/VersionCalculation/VersionCalculators/MainlineVersionCalculator.cs index a13a9bd2cf..5fe8d8ca58 100644 --- a/src/GitVersion.Core/VersionCalculation/VersionCalculators/MainlineVersionCalculator.cs +++ b/src/GitVersion.Core/VersionCalculation/VersionCalculators/MainlineVersionCalculator.cs @@ -316,7 +316,7 @@ private VersionField FindMessageIncrement(ICommit? mergeCommit, ICommit? mergedH minorVersionBumpMessage: Context.Configuration.MinorVersionBumpMessage, patchVersionBumpMessage: Context.Configuration.PatchVersionBumpMessage, noBumpMessage: Context.Configuration.NoBumpMessage, - commits: commits + commits: commits.ToArray() ); return messageIncrement ?? TryFindIncrementFromMergeMessage(mergeCommit); } diff --git a/src/GitVersion.Schema/DefaultAttributeHandler.cs b/src/GitVersion.Schema/DefaultAttributeHandler.cs new file mode 100644 index 0000000000..8ffa5c5b5a --- /dev/null +++ b/src/GitVersion.Schema/DefaultAttributeHandler.cs @@ -0,0 +1,16 @@ +using GitVersion.Attributes; +using Json.Schema.Generation; +using Json.Schema.Generation.Intents; + +namespace GitVersion.Schema; + +internal class DefaultAttributeHandler : IAttributeHandler +{ + void IAttributeHandler.AddConstraints(SchemaGenerationContextBase context, Attribute attribute) + { + if (attribute is JsonPropertyDefaultAttribute defaultAttribute) + { + context.Intents.Insert(0, new DefaultIntent(defaultAttribute.Value)); + } + } +} diff --git a/src/GitVersion.Schema/Extensions.cs b/src/GitVersion.Schema/Extensions.cs index ef801b74c4..dac09a46c1 100644 --- a/src/GitVersion.Schema/Extensions.cs +++ b/src/GitVersion.Schema/Extensions.cs @@ -1,3 +1,4 @@ +using System.Text.Encodings.Web; using Json.More; using Json.Schema; @@ -9,8 +10,8 @@ public static void WriteToFile(this JsonSchema jsonSchema, string outputFileName { var jsonDocument = jsonSchema.ToJsonDocument(); - using FileStream fs = File.Create(outputFileName); - using var writer = new Utf8JsonWriter(fs, new JsonWriterOptions { Indented = true }); + using var fs = File.Create(outputFileName); + using var writer = new Utf8JsonWriter(fs, new() { Indented = true, Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping }); jsonDocument.WriteTo(writer); writer.Flush(); fs.Flush(); diff --git a/src/GitVersion.Schema/FormatAttributeHandler.cs b/src/GitVersion.Schema/FormatAttributeHandler.cs new file mode 100644 index 0000000000..bd49aa4bba --- /dev/null +++ b/src/GitVersion.Schema/FormatAttributeHandler.cs @@ -0,0 +1,42 @@ +using GitVersion.Attributes; +using Json.Schema; +using Json.Schema.Generation; +using Json.Schema.Generation.Intents; +using Format = GitVersion.Attributes.Format; + +namespace GitVersion.Schema; +internal class FormatAttributeHandler : IAttributeHandler +{ + void IAttributeHandler.AddConstraints(SchemaGenerationContextBase context, Attribute attribute) + { + if (attribute is JsonPropertyFormatAttribute formatAttribute) + { + Json.Schema.Format? format = formatAttribute.Format switch + { + Format.Date => Formats.Date, + Format.DateTime => Formats.DateTime, + Format.Duration => Formats.Duration, + Format.Email => Formats.Email, + Format.Hostname => Formats.Hostname, + Format.IdnEmail => Formats.IdnEmail, + Format.IdnHostname => Formats.IdnHostname, + Format.Ipv4 => Formats.Ipv4, + Format.Ipv6 => Formats.Ipv6, + Format.Iri => Formats.Iri, + Format.IriReference => Formats.IriReference, + Format.JsonPointer => Formats.JsonPointer, + Format.Regex => Formats.Regex, + Format.RelativeJsonPointer => Formats.RelativeJsonPointer, + Format.Time => Formats.Time, + Format.Uri => Formats.Uri, + Format.UriReference => Formats.UriReference, + Format.UriTemplate => Formats.UriTemplate, + Format.Uuid => Formats.Uuid, + _ => null // in case new formats are added. + }; + + if (format != null) + context.Intents.Insert(0, new FormatIntent(format)); + } + } +} diff --git a/src/GitVersion.Schema/PatternAttributeHandler.cs b/src/GitVersion.Schema/PatternAttributeHandler.cs deleted file mode 100644 index f4ec4fd084..0000000000 --- a/src/GitVersion.Schema/PatternAttributeHandler.cs +++ /dev/null @@ -1,24 +0,0 @@ -using GitVersion.Attributes; -using Json.Schema; -using Json.Schema.Generation; -using Json.Schema.Generation.Intents; - -namespace GitVersion.Schema; -internal class PatternAttributeHandler : IAttributeHandler -{ - void IAttributeHandler.AddConstraints(SchemaGenerationContextBase context, Attribute attribute) - { - if (attribute is JsonPropertyPatternAttribute patternAttribute) - { - var format = patternAttribute.Format switch - { - PatternFormat.Regex => Formats.Regex, - PatternFormat.DateTime => Formats.DateTime, - _ => Formats.Regex - }; - - context.Intents.Insert(0, new PatternIntent(patternAttribute.Pattern)); - context.Intents.Insert(0, new FormatIntent(format)); - } - } -} diff --git a/src/GitVersion.Schema/Program.cs b/src/GitVersion.Schema/Program.cs index f7cb4a7f84..25e30bbfac 100644 --- a/src/GitVersion.Schema/Program.cs +++ b/src/GitVersion.Schema/Program.cs @@ -16,8 +16,9 @@ PropertyOrder = PropertyOrder.ByName, }; +AttributeHandler.AddHandler(); AttributeHandler.AddHandler(); -AttributeHandler.AddHandler(); +AttributeHandler.AddHandler(); var builder = new JsonSchemaBuilder(); builder.Schema("http://json-schema.org/draft-07/schema#");