From 330c155e3db19756bf513ed955d63e63145b4469 Mon Sep 17 00:00:00 2001 From: Artur Stolear Date: Wed, 13 Nov 2024 01:11:00 +0100 Subject: [PATCH 01/37] (build) - fix dockerhub readme publish (#4281) --- build/docker/Tasks/DockerHubReadmePublish.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/docker/Tasks/DockerHubReadmePublish.cs b/build/docker/Tasks/DockerHubReadmePublish.cs index 9245683370..36a3b3390f 100644 --- a/build/docker/Tasks/DockerHubReadmePublish.cs +++ b/build/docker/Tasks/DockerHubReadmePublish.cs @@ -15,7 +15,7 @@ public class DockerHubReadmePublishInternal : AsyncFrostingTask { public override bool ShouldRun(BuildContext context) { - var shouldRun = false; + var shouldRun = true; if (context.DockerRegistry == DockerRegistry.DockerHub) { shouldRun &= context.ShouldRun(context.IsStableRelease, $"{nameof(DockerHubReadmePublish)} works only for tagged releases."); From bd688a91115eb893b7298c64c1da1c94855166d5 Mon Sep 17 00:00:00 2001 From: Artur Stolear Date: Mon, 22 Jul 2024 10:09:01 +0200 Subject: [PATCH 02/37] Sunset .net 6.0 +semver: minor --- build/.run/UnitTest (6.0).run.xml | 23 ------------------- build/common/Utilities/Constants.cs | 3 +-- .../build-servers/bitbucket-pipelines.md | 4 ++-- src/Directory.Build.props | 2 +- .../GitVersion.MsBuild.csproj | 1 - 5 files changed, 4 insertions(+), 29 deletions(-) delete mode 100644 build/.run/UnitTest (6.0).run.xml diff --git a/build/.run/UnitTest (6.0).run.xml b/build/.run/UnitTest (6.0).run.xml deleted file mode 100644 index 4f2f55e0a6..0000000000 --- a/build/.run/UnitTest (6.0).run.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - \ No newline at end of file diff --git a/build/common/Utilities/Constants.cs b/build/common/Utilities/Constants.cs index 0af521392e..d8817cccc8 100644 --- a/build/common/Utilities/Constants.cs +++ b/build/common/Utilities/Constants.cs @@ -6,9 +6,8 @@ public static class Constants public const string RepoOwner = "GitTools"; public const string Repository = "GitVersion"; - public const string VersionCurrent = "6.0"; public const string VersionLatest = "8.0"; - public static readonly string[] DotnetVersions = [VersionCurrent, VersionLatest]; + public static readonly string[] DotnetVersions = [VersionLatest]; public const string DefaultBranch = "main"; public const string DefaultConfiguration = "Release"; diff --git a/docs/input/docs/reference/build-servers/bitbucket-pipelines.md b/docs/input/docs/reference/build-servers/bitbucket-pipelines.md index 8218605144..f2e91f83db 100644 --- a/docs/input/docs/reference/build-servers/bitbucket-pipelines.md +++ b/docs/input/docs/reference/build-servers/bitbucket-pipelines.md @@ -16,7 +16,7 @@ in your build step. An example pipeline is shown below: ```yml -image: mcr.microsoft.com/dotnet/sdk:6.0 +image: mcr.microsoft.com/dotnet/sdk:8.0 clone: depth: full @@ -50,7 +50,7 @@ If you want to share the text file across multiple build steps, then you will ne is shown below: ```yml -image: mcr.microsoft.com/dotnet/sdk:6.0 +image: mcr.microsoft.com/dotnet/sdk:8.0 clone: depth: full diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 27dfc49416..6224b2b353 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -1,6 +1,6 @@ - net6.0;net8.0 + net8.0 $([System.DateTime]::Today.Year) GitTools and Contributors diff --git a/src/GitVersion.MsBuild/GitVersion.MsBuild.csproj b/src/GitVersion.MsBuild/GitVersion.MsBuild.csproj index cd922f14c1..61aed5a2d4 100644 --- a/src/GitVersion.MsBuild/GitVersion.MsBuild.csproj +++ b/src/GitVersion.MsBuild/GitVersion.MsBuild.csproj @@ -38,7 +38,6 @@ - From 3b3c7e00ae5a06618acf9be3beb876f4c33d4921 Mon Sep 17 00:00:00 2001 From: Artur Date: Wed, 13 Nov 2024 02:25:09 +0100 Subject: [PATCH 03/37] Update issue-report.yml --- .github/ISSUE_TEMPLATE/issue-report.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/issue-report.yml b/.github/ISSUE_TEMPLATE/issue-report.yml index 373596a764..5e174295a5 100644 --- a/.github/ISSUE_TEMPLATE/issue-report.yml +++ b/.github/ISSUE_TEMPLATE/issue-report.yml @@ -20,6 +20,7 @@ body: - GitVersion.Portable - gittools/actions - AzureDevops task + - N/A multiple: true validations: required: true @@ -69,4 +70,4 @@ body: description: Log messages you receive when running. Make sure there is no sensitive data shared. No need for backticks here. render: shell validations: - required: false \ No newline at end of file + required: false From 4152db126032e542fd3c59340c975a928232c64c Mon Sep 17 00:00:00 2001 From: Artur Stolear Date: Wed, 13 Nov 2024 02:34:16 +0100 Subject: [PATCH 04/37] #4299 - add new schemas for 6.11.* --- schemas/6.1/GitVersion.configuration.json | 394 ++++++++++++++++++++++ schemas/6.1/GitVersion.json | 133 ++++++++ src/GitVersion.Schema/Program.cs | 9 + 3 files changed, 536 insertions(+) create mode 100644 schemas/6.1/GitVersion.configuration.json create mode 100644 schemas/6.1/GitVersion.json diff --git a/schemas/6.1/GitVersion.configuration.json b/schemas/6.1/GitVersion.configuration.json new file mode 100644 index 0000000000..affb98d33e --- /dev/null +++ b/schemas/6.1/GitVersion.configuration.json @@ -0,0 +1,394 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$id": "https://gitversion.net/schemas/6.1/GitVersion.configuration.json", + "title": "GitVersion Configuration (6.1)", + "description": "GitVersion configuration schema (6.1)", + "type": "object", + "properties": { + "assembly-file-versioning-format": { + "description": "Specifies the format of AssemblyFileVersion and overwrites the value of assembly-file-versioning-scheme.", + "type": "string" + }, + "assembly-file-versioning-scheme": { + "description": "The scheme to use when setting AssemblyFileVersion attribute. Can be 'MajorMinorPatchTag', 'MajorMinorPatch', 'MajorMinor', 'Major', 'None'. Defaults to 'MajorMinorPatch'.", + "default": "MajorMinorPatch", + "enum": [ + "MajorMinorPatchTag", + "MajorMinorPatch", + "MajorMinor", + "Major", + "None" + ] + }, + "assembly-informational-format": { + "description": "Specifies the format of AssemblyInformationalVersion. Defaults to '{InformationalVersion}'.", + "default": "'{InformationalVersion}'", + "type": "string" + }, + "assembly-versioning-format": { + "description": "Specifies the format of AssemblyVersion and overwrites the value of assembly-versioning-scheme.", + "type": "string" + }, + "assembly-versioning-scheme": { + "description": "The scheme to use when setting AssemblyVersion attribute. Can be 'MajorMinorPatchTag', 'MajorMinorPatch', 'MajorMinor', 'Major', 'None'. Defaults to 'MajorMinorPatch'.", + "default": "MajorMinorPatch", + "enum": [ + "MajorMinorPatchTag", + "MajorMinorPatch", + "MajorMinor", + "Major", + "None" + ] + }, + "branches": { + "description": "The header for all the individual branch configuration.", + "type": "object", + "additionalProperties": { + "$ref": "#/$defs/branchConfiguration" + } + }, + "commit-date-format": { + "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": { + "$ref": "#/$defs/nullableOfCommitMessageIncrementMode" + }, + "mode": { + "$ref": "#/$defs/nullableOfDeploymentMode" + }, + "ignore": { + "description": "The header property for the ignore configuration.", + "type": "object", + "properties": { + "commits-before": { + "$ref": "#/$defs/string3" + }, + "sha": { + "$ref": "#/$defs/hashSetOfString2" + } + } + }, + "increment": { + "$ref": "#/$defs/incrementStrategy" + }, + "is-main-branch": { + "$ref": "#/$defs/nullableOfBoolean" + }, + "is-release-branch": { + "$ref": "#/$defs/nullableOfBoolean1" + }, + "is-source-branch-for": { + "$ref": "#/$defs/hashSetOfString" + }, + "label": { + "$ref": "#/$defs/string" + }, + "label-number-pattern": { + "$ref": "#/$defs/string1" + }, + "major-version-bump-message": { + "format": "regex", + "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": { + "description": "Custom merge message formats to enable identification of merge messages that do not follow the built-in conventions.", + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + "minor-version-bump-message": { + "format": "regex", + "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": { + "description": "Allows you to bump the next version explicitly. Useful for bumping main or a feature branch with breaking changes", + "type": "string" + }, + "no-bump-message": { + "format": "regex", + "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", + "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": { + "$ref": "#/$defs/nullableOfInt32" + }, + "prevent-increment": { + "$ref": "#/$defs/preventIncrementConfiguration" + }, + "regex": { + "$ref": "#/$defs/string2" + }, + "semantic-version-format": { + "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" + ] + }, + "source-branches": { + "$ref": "#/$defs/hashSetOfString1" + }, + "tag-prefix": { + "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": { + "description": "The pre-release weight in case of tagged commits. Defaults to 60000.", + "type": [ + "integer", + "null" + ] + }, + "track-merge-message": { + "$ref": "#/$defs/nullableOfBoolean4" + }, + "track-merge-target": { + "$ref": "#/$defs/nullableOfBoolean5" + }, + "tracks-release-branches": { + "$ref": "#/$defs/nullableOfBoolean6" + }, + "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": { + "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" + }, + "strategies": { + "description": "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 'Mainline'.", + "type": "array", + "items": { + "description": "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 'Mainline'.", + "enum": [ + "None", + "Fallback", + "ConfiguredNextVersion", + "MergeMessage", + "TaggedCommit", + "TrackReleaseBranches", + "VersionInBranchName", + "Mainline" + ] + } + }, + "workflow": { + "description": "The base template of the configuration to use. Possible values are: 'GitFlow/v1' or 'GitHubFlow/v1'", + "type": "string" + } + }, + "$defs": { + "branchConfiguration": { + "type": "object", + "properties": { + "commit-message-incrementing": { + "$ref": "#/$defs/nullableOfCommitMessageIncrementMode" + }, + "mode": { + "$ref": "#/$defs/nullableOfDeploymentMode" + }, + "increment": { + "$ref": "#/$defs/incrementStrategy" + }, + "is-main-branch": { + "$ref": "#/$defs/nullableOfBoolean" + }, + "is-release-branch": { + "$ref": "#/$defs/nullableOfBoolean1" + }, + "is-source-branch-for": { + "$ref": "#/$defs/hashSetOfString" + }, + "label": { + "$ref": "#/$defs/string" + }, + "label-number-pattern": { + "$ref": "#/$defs/string1" + }, + "pre-release-weight": { + "$ref": "#/$defs/nullableOfInt32" + }, + "prevent-increment": { + "$ref": "#/$defs/preventIncrementConfiguration" + }, + "regex": { + "$ref": "#/$defs/string2" + }, + "source-branches": { + "$ref": "#/$defs/hashSetOfString1" + }, + "track-merge-message": { + "$ref": "#/$defs/nullableOfBoolean4" + }, + "track-merge-target": { + "$ref": "#/$defs/nullableOfBoolean5" + }, + "tracks-release-branches": { + "$ref": "#/$defs/nullableOfBoolean6" + } + } + }, + "nullableOfCommitMessageIncrementMode": { + "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", + "MergeMessageOnly" + ] + }, + "nullableOfDeploymentMode": { + "description": "The deployment mode for this branch. Can be 'ManualDeployment', 'ContinuousDelivery', 'ContinuousDeployment'.", + "enum": [ + "ManualDeployment", + "ContinuousDelivery", + "ContinuousDeployment" + ] + }, + "incrementStrategy": { + "description": "The increment strategy for this branch. Can be 'Inherit', 'Patch', 'Minor', 'Major', 'None'.", + "enum": [ + "None", + "Major", + "Minor", + "Patch", + "Inherit" + ] + }, + "nullableOfBoolean": { + "description": "When using Mainline mode, this indicates that this branch is a mainline. By default main and support/* are mainlines.", + "type": [ + "boolean", + "null" + ] + }, + "nullableOfBoolean1": { + "description": "Indicates this branch configuration represents a release branch in GitFlow.", + "type": [ + "boolean", + "null" + ] + }, + "hashSetOfString": { + "description": "The branches that this branch is a source branch.", + "type": "array", + "items": { + "description": "The branches that this branch is a source branch.", + "type": "string" + } + }, + "string": { + "description": "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).", + "type": "string" + }, + "string1": { + "format": "regex", + "description": "The regular expression pattern to use to extract the number from the branch name. Defaults to '[/-](?\\d+)'.", + "default": "[/-](?\\d+)", + "type": "string" + }, + "nullableOfInt32": { + "description": "Provides a way to translate the PreReleaseLabel to a number.", + "type": [ + "integer", + "null" + ] + }, + "preventIncrementConfiguration": { + "description": "The prevent increment configuration section.", + "type": "object", + "properties": { + "of-merged-branch": { + "$ref": "#/$defs/nullableOfBoolean2" + }, + "when-branch-merged": { + "$ref": "#/$defs/nullableOfBoolean2" + }, + "when-current-commit-tagged": { + "$ref": "#/$defs/nullableOfBoolean3" + } + } + }, + "nullableOfBoolean2": { + "description": "Prevent increment when branch merged.", + "type": [ + "boolean", + "null" + ] + }, + "nullableOfBoolean3": { + "description": "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.", + "type": [ + "boolean", + "null" + ] + }, + "string2": { + "format": "regex", + "description": "The regular expression pattern to use to match this branch.", + "type": "string" + }, + "hashSetOfString1": { + "description": "The source branches for this branch.", + "type": "array", + "items": { + "description": "The source branches for this branch.", + "type": "string" + } + }, + "nullableOfBoolean4": { + "description": "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.", + "type": [ + "boolean", + "null" + ] + }, + "nullableOfBoolean5": { + "description": "Strategy which will look for tagged merge commits directly off the current branch.", + "type": [ + "boolean", + "null" + ] + }, + "nullableOfBoolean6": { + "description": "Indicates this branch configuration represents develop in GitFlow.", + "type": [ + "boolean", + "null" + ] + }, + "string3": { + "format": "date-time", + "description": "Commits before this date will be ignored. Format: yyyy-MM-ddTHH:mm:ss.", + "type": "string" + }, + "hashSetOfString2": { + "description": "A sequence of SHAs to be excluded from the version calculations.", + "type": "array", + "items": { + "description": "A sequence of SHAs to be excluded from the version calculations.", + "type": "string" + } + } + } +} \ No newline at end of file diff --git a/schemas/6.1/GitVersion.json b/schemas/6.1/GitVersion.json new file mode 100644 index 0000000000..037e6acbf4 --- /dev/null +++ b/schemas/6.1/GitVersion.json @@ -0,0 +1,133 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$id": "https://gitversion.net/schemas/6.1/GitVersion.json", + "title": "GitVersion version variables output", + "description": "GitVersion output schema", + "type": "object", + "properties": { + "AssemblySemFileVer": { + "description": "Suitable for .NET AssemblyFileVersion. Defaults to Major.Minor.Patch.0.", + "type": "string" + }, + "AssemblySemVer": { + "description": "Suitable for .NET AssemblyVersion. Defaults to Major.Minor.0.0", + "type": "string" + }, + "BranchName": { + "description": "The name of the checked out Git branch.", + "type": "string" + }, + "BuildMetaData": { + "description": "The build metadata, usually representing number of commits since the VersionSourceSha.", + "type": [ + "integer", + "null" + ] + }, + "CommitDate": { + "description": "The ISO-8601 formatted date of the commit identified by Sha.", + "type": "string" + }, + "CommitsSinceVersionSource": { + "description": "The number of commits since the version source.", + "type": [ + "integer", + "null" + ] + }, + "EscapedBranchName": { + "description": "Equal to BranchName, but with / replaced with -.", + "type": "string" + }, + "FullBuildMetaData": { + "description": "The BuildMetaData suffixed with BranchName and Sha.", + "type": "string" + }, + "FullSemVer": { + "description": "The full, SemVer 2.0 compliant version number.", + "type": "string" + }, + "InformationalVersion": { + "description": "Suitable for .NET AssemblyInformationalVersion. Defaults to FullSemVer suffixed by FullBuildMetaData.", + "type": "string" + }, + "Major": { + "description": "The major version. Should be incremented on breaking changes.", + "type": [ + "integer", + "null" + ] + }, + "MajorMinorPatch": { + "description": "Major, Minor and Patch joined together, separated by '.'.", + "type": "string" + }, + "Minor": { + "description": "The minor version. Should be incremented on new features.", + "type": [ + "integer", + "null" + ] + }, + "Patch": { + "description": "The patch version. Should be incremented on bug fixes.", + "type": [ + "integer", + "null" + ] + }, + "PreReleaseLabel": { + "description": "The pre-release label is the name of the pre-release.", + "type": "string" + }, + "PreReleaseLabelWithDash": { + "description": "The pre-release label prefixed with a dash.", + "type": "string" + }, + "PreReleaseNumber": { + "description": "The pre-release number is the number of commits since the last version bump.", + "type": [ + "integer", + "null" + ] + }, + "PreReleaseTag": { + "description": "The pre-release tag is the pre-release label suffixed by the PreReleaseNumber.", + "type": "string" + }, + "PreReleaseTagWithDash": { + "description": "The pre-release tag prefixed with a dash.", + "type": "string" + }, + "SemVer": { + "description": "The semantic version number, including PreReleaseTagWithDash for pre-release version numbers.", + "type": "string" + }, + "Sha": { + "description": "The SHA of the Git commit.", + "type": "string" + }, + "ShortSha": { + "description": "The Sha limited to 7 characters.", + "type": "string" + }, + "UncommittedChanges": { + "description": "The number of uncommitted changes present in the repository.", + "type": [ + "integer", + "null" + ] + }, + "VersionSourceSha": { + "description": "The SHA of the commit used as version source.", + "type": "string" + }, + "WeightedPreReleaseNumber": { + "description": "A summation of branch specific pre-release-weight and the PreReleaseNumber. Can be used to obtain a monotonically increasing version number across the branches.", + "type": [ + "integer", + "null" + ] + } + } +} \ No newline at end of file diff --git a/src/GitVersion.Schema/Program.cs b/src/GitVersion.Schema/Program.cs index 3bed198c98..ba84aed254 100644 --- a/src/GitVersion.Schema/Program.cs +++ b/src/GitVersion.Schema/Program.cs @@ -21,6 +21,15 @@ AttributeHandler.AddHandler(); AttributeHandler.AddHandler(); +if (!Directory.Exists(schemasDirectory)) +{ + Directory.CreateDirectory(schemasDirectory); +} +if (!Directory.Exists(Path.Combine(schemasDirectory, schemaVersion))) +{ + Directory.CreateDirectory(Path.Combine(schemasDirectory, schemaVersion)); +} + var builder = new JsonSchemaBuilder(); builder.Schema("http://json-schema.org/draft-07/schema#"); builder.Id($"https://gitversion.net/schemas/{schemaVersion}/GitVersion.configuration.json"); From ca58a8883a7c6c4e2e9c563528ad774ec808f58a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 22 Oct 2024 15:35:01 +0000 Subject: [PATCH 05/37] (deps): Bump MSBuild.ProjectCreation from 13.0.0 to 14.0.0 in /src Bumps [MSBuild.ProjectCreation](https://github.com/jeffkl/MSBuildProjectCreator) from 13.0.0 to 14.0.0. - [Release notes](https://github.com/jeffkl/MSBuildProjectCreator/releases) - [Commits](https://github.com/jeffkl/MSBuildProjectCreator/compare/v13.0.0...v14.0.0) --- updated-dependencies: - dependency-name: MSBuild.ProjectCreation dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- src/Directory.Packages.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props index cc96645729..f09a883642 100644 --- a/src/Directory.Packages.props +++ b/src/Directory.Packages.props @@ -21,7 +21,7 @@ - + From 7a8aa07c5dcd89593879011e797362f9a99ad76b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 13 Nov 2024 02:02:32 +0000 Subject: [PATCH 06/37] (deps): Bump Cake.Frosting from 4.2.0 to 5.0.0 in /build Bumps [Cake.Frosting](https://github.com/cake-build/cake) from 4.2.0 to 5.0.0. - [Release notes](https://github.com/cake-build/cake/releases) - [Changelog](https://github.com/cake-build/cake/blob/develop/ReleaseNotes.md) - [Commits](https://github.com/cake-build/cake/compare/v4.2.0...v5.0.0) --- updated-dependencies: - dependency-name: Cake.Frosting dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- build/Directory.Packages.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/Directory.Packages.props b/build/Directory.Packages.props index 878f537db9..2e0ac0583c 100644 --- a/build/Directory.Packages.props +++ b/build/Directory.Packages.props @@ -6,7 +6,7 @@ - + From 67e837216e8e479d1d722c63d487d400552338ae Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 13 Nov 2024 02:03:16 +0000 Subject: [PATCH 07/37] (deps): Bump Polly from 8.4.2 to 8.5.0 in /src Bumps [Polly](https://github.com/App-vNext/Polly) from 8.4.2 to 8.5.0. - [Release notes](https://github.com/App-vNext/Polly/releases) - [Changelog](https://github.com/App-vNext/Polly/blob/main/CHANGELOG.md) - [Commits](https://github.com/App-vNext/Polly/compare/8.4.2...8.5.0) --- updated-dependencies: - dependency-name: Polly dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- src/Directory.Packages.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props index f09a883642..5fe1d766e7 100644 --- a/src/Directory.Packages.props +++ b/src/Directory.Packages.props @@ -14,7 +14,7 @@ - + From 04944bef75a5c3d4cfbe99041af9328a053f823c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 13 Nov 2024 02:02:52 +0000 Subject: [PATCH 08/37] (deps): Bump Polly from 8.4.2 to 8.5.0 in /new-cli Bumps [Polly](https://github.com/App-vNext/Polly) from 8.4.2 to 8.5.0. - [Release notes](https://github.com/App-vNext/Polly/releases) - [Changelog](https://github.com/App-vNext/Polly/blob/main/CHANGELOG.md) - [Commits](https://github.com/App-vNext/Polly/compare/8.4.2...8.5.0) --- updated-dependencies: - dependency-name: Polly dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- new-cli/Directory.Packages.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/new-cli/Directory.Packages.props b/new-cli/Directory.Packages.props index 7421cb3f91..70a981f6c4 100644 --- a/new-cli/Directory.Packages.props +++ b/new-cli/Directory.Packages.props @@ -11,7 +11,7 @@ - + From 6ff97aac7c137ed89f9b806dd23594a1db8e7cfb Mon Sep 17 00:00:00 2001 From: Artur Stolear Date: Wed, 13 Nov 2024 02:54:20 +0100 Subject: [PATCH 09/37] add .net9.0 target --- build/Directory.Build.props | 4 ++-- build/common/Utilities/Constants.cs | 2 +- new-cli/Directory.Build.props | 2 +- src/Directory.Build.props | 4 ++-- src/GitVersion.MsBuild/GitVersion.MsBuild.csproj | 1 + 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/build/Directory.Build.props b/build/Directory.Build.props index edbb8dac4d..97be940115 100644 --- a/build/Directory.Build.props +++ b/build/Directory.Build.props @@ -1,12 +1,12 @@  Exe - net8.0 + net9.0 $(MSBuildProjectDirectory) ..\..\run\ false enable - 12 + latest NU1604 enable diff --git a/build/common/Utilities/Constants.cs b/build/common/Utilities/Constants.cs index d8817cccc8..6a21c36e31 100644 --- a/build/common/Utilities/Constants.cs +++ b/build/common/Utilities/Constants.cs @@ -7,7 +7,7 @@ public static class Constants public const string Repository = "GitVersion"; public const string VersionLatest = "8.0"; - public static readonly string[] DotnetVersions = [VersionLatest]; + public static readonly string[] DotnetVersions = [VersionLatest, "9.0"]; public const string DefaultBranch = "main"; public const string DefaultConfiguration = "Release"; diff --git a/new-cli/Directory.Build.props b/new-cli/Directory.Build.props index ea7d0c9db2..88b7cf62da 100644 --- a/new-cli/Directory.Build.props +++ b/new-cli/Directory.Build.props @@ -1,6 +1,6 @@ - net8.0 + net9.0 GitVersion latest diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 6224b2b353..af1ddcba7f 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -1,6 +1,6 @@ - net8.0 + net8.0;net9.0 $([System.DateTime]::Today.Year) GitTools and Contributors @@ -22,7 +22,7 @@ $(WarningsAsErrors);RS0016;RS0017;RS0022;RS0024;RS0025;RS0026;RS0027 embedded - 12 + latest enable enable en diff --git a/src/GitVersion.MsBuild/GitVersion.MsBuild.csproj b/src/GitVersion.MsBuild/GitVersion.MsBuild.csproj index 61aed5a2d4..033f10f2b4 100644 --- a/src/GitVersion.MsBuild/GitVersion.MsBuild.csproj +++ b/src/GitVersion.MsBuild/GitVersion.MsBuild.csproj @@ -39,6 +39,7 @@ + From 75f1dfe799657076bc19c233b57e01973df2c324 Mon Sep 17 00:00:00 2001 From: Artur Stolear Date: Wed, 13 Nov 2024 02:54:38 +0100 Subject: [PATCH 10/37] updated rider run configurations --- build/.run/Artifacts DotnetTool Test.run.xml | 4 ++-- build/.run/Artifacts Executable Test.run.xml | 4 ++-- build/.run/Artifacts MsBuildCore Test.run.xml | 4 ++-- build/.run/Artifacts MsBuildFull Test.run.xml | 4 ++-- build/.run/Artifacts Native Test.run.xml | 4 ++-- build/.run/Artifacts Prepare.run.xml | 4 ++-- build/.run/Artifacts Test.run.xml | 4 ++-- build/.run/Build Docs.run.xml | 4 ++-- build/.run/Build Prepare.run.xml | 4 ++-- build/.run/Build.run.xml | 4 ++-- build/.run/Clean.run.xml | 2 +- build/.run/Code Format.run.xml | 4 ++-- build/.run/Default Artifacts.run.xml | 4 ++-- build/.run/Default Build.run.xml | 4 ++-- build/.run/Default Config.run.xml | 2 +- build/.run/Default Docker.run.xml | 4 ++-- build/.run/Default Docs.run.xml | 4 ++-- build/.run/Default Publish.run.xml | 4 ++-- build/.run/Docker Build.run.xml | 4 ++-- build/.run/Docker Manifest.run.xml | 4 ++-- build/.run/Docker Publish.run.xml | 4 ++-- build/.run/Docker Test.run.xml | 4 ++-- build/.run/DockerHub Readme Publish.run.xml | 4 ++-- build/.run/Generate Schemas.run.xml | 4 ++-- build/.run/Package Archive.run.xml | 4 ++-- build/.run/Package Chocolatey.run.xml | 4 ++-- build/.run/Package Nuget.run.xml | 4 ++-- build/.run/Package Prepare.run.xml | 4 ++-- build/.run/Package.run.xml | 4 ++-- build/.run/Preview Docs.run.xml | 4 ++-- build/.run/Publish Chocolatey.run.xml | 4 ++-- build/.run/Publish Docs.run.xml | 4 ++-- build/.run/Publish Nuget.run.xml | 6 ++--- build/.run/Publish Release.run.xml | 4 ++-- build/.run/PublishCoverage.run.xml | 4 ++-- build/.run/SetMatrix.run.xml | 2 +- build/.run/Test.run.xml | 4 ++-- build/.run/UnitTest (8.0).run.xml | 2 +- build/.run/UnitTest (9.0).run.xml | 23 +++++++++++++++++++ build/.run/Validate Version.run.xml | 4 ++-- new-cli/.run/Calculate.run.xml | 4 ++-- new-cli/.run/Config Help.run.xml | 4 ++-- new-cli/.run/Config Init.run.xml | 4 ++-- new-cli/.run/Config Show.run.xml | 4 ++-- new-cli/.run/Help.run.xml | 4 ++-- new-cli/.run/Normalize.run.xml | 4 ++-- new-cli/.run/Output AssemblyInfo.run.xml | 4 ++-- new-cli/.run/Output Help.run.xml | 4 ++-- new-cli/.run/Output Project.run.xml | 4 ++-- new-cli/.run/Output Wix.run.xml | 4 ++-- new-cli/.run/Tester.run.xml | 6 ++--- new-cli/.run/Version.run.xml | 4 ++-- src/.run/cli (help).run.xml | 4 ++-- src/.run/cli (showconfig).run.xml | 4 ++-- src/.run/cli (version).run.xml | 4 ++-- src/.run/cli.run.xml | 6 ++--- src/.run/schema.run.xml | 6 ++--- 57 files changed, 135 insertions(+), 112 deletions(-) create mode 100644 build/.run/UnitTest (9.0).run.xml diff --git a/build/.run/Artifacts DotnetTool Test.run.xml b/build/.run/Artifacts DotnetTool Test.run.xml index 5a4546c2b5..f09edd6a7e 100644 --- a/build/.run/Artifacts DotnetTool Test.run.xml +++ b/build/.run/Artifacts DotnetTool Test.run.xml @@ -1,6 +1,6 @@ - \ No newline at end of file From eaa44473c959b764a8f09936611158ed4ffdf4ac Mon Sep 17 00:00:00 2001 From: Artur Stolear Date: Fri, 15 Nov 2024 18:10:12 +0100 Subject: [PATCH 17/37] (deps): Bump the microsoft group across 1 directory with 4 updates Bumps the microsoft group with 4 updates in the /src directory: [Microsoft.Build](https://github.com/dotnet/msbuild), [Microsoft.IO.Redist](https://github.com/dotnet/runtime), [System.Text.Json](https://github.com/dotnet/runtime) and [Microsoft.Build.Utilities.Core](https://github.com/dotnet/msbuild). Updates `Microsoft.Build` from 17.11.4 to 17.12.6 - [Release notes](https://github.com/dotnet/msbuild/releases) - [Changelog](https://github.com/dotnet/msbuild/blob/main/documentation/Changelog.md) - [Commits](https://github.com/dotnet/msbuild/compare/v17.11.4...v17.12.6) Updates `Microsoft.IO.Redist` from 6.1.0 to 6.0.1 - [Release notes](https://github.com/dotnet/runtime/releases) - [Commits](https://github.com/dotnet/runtime/commits/v6.0.1) Updates `System.Text.Json` from 9.0.0 to 8.0.5 - [Release notes](https://github.com/dotnet/runtime/releases) - [Commits](https://github.com/dotnet/runtime/compare/v9.0.0...v8.0.5) Updates `Microsoft.Build.Utilities.Core` from 17.11.4 to 17.12.6 - [Release notes](https://github.com/dotnet/msbuild/releases) - [Changelog](https://github.com/dotnet/msbuild/blob/main/documentation/Changelog.md) - [Commits](https://github.com/dotnet/msbuild/compare/v17.11.4...v17.12.6) --- updated-dependencies: - dependency-name: Microsoft.Build dependency-type: direct:production update-type: version-update:semver-minor dependency-group: microsoft - dependency-name: Microsoft.IO.Redist dependency-type: direct:production update-type: version-update:semver-minor dependency-group: microsoft - dependency-name: System.Text.Json dependency-type: direct:production update-type: version-update:semver-major dependency-group: microsoft - dependency-name: Microsoft.Build.Utilities.Core dependency-type: direct:production update-type: version-update:semver-minor dependency-group: microsoft ... Signed-off-by: dependabot[bot] 1c3b09 --- .github/workflows/_unit_tests.yml | 2 +- src/Directory.Packages.props | 4 ++-- .../msbuild/tools/GitVersion.MsBuild.targets | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/_unit_tests.yml b/.github/workflows/_unit_tests.yml index 594e2a55ae..f4925b5f59 100644 --- a/.github/workflows/_unit_tests.yml +++ b/.github/workflows/_unit_tests.yml @@ -37,6 +37,6 @@ jobs: - name: Test Summary uses: test-summary/action@v2.4 - if: matrix.dotnetVersion == '8.0' + if: matrix.dotnetVersion == '9.0' with: paths: artifacts/test-results/*.results.xml diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props index e52b2266af..62986a291f 100644 --- a/src/Directory.Packages.props +++ b/src/Directory.Packages.props @@ -23,8 +23,8 @@ - - + + diff --git a/src/GitVersion.MsBuild/msbuild/tools/GitVersion.MsBuild.targets b/src/GitVersion.MsBuild/msbuild/tools/GitVersion.MsBuild.targets index 974a840d88..680bf52a1a 100644 --- a/src/GitVersion.MsBuild/msbuild/tools/GitVersion.MsBuild.targets +++ b/src/GitVersion.MsBuild/msbuild/tools/GitVersion.MsBuild.targets @@ -10,8 +10,8 @@ net8.0 - net6.0 - + net9.0 + net8.0 dotnet --roll-forward Major "$([MSBuild]::EnsureTrailingSlash($(MSBuildThisFileDirectory)$(GitVersionTargetFramework)))gitversion.dll" $([MSBuild]::EnsureTrailingSlash($(MSBuildThisFileDirectory)$(GitVersionTargetFramework)))GitVersion.MsBuild.dll From 7eb9399797a708948c65875aac5b4a2f61ea5c02 Mon Sep 17 00:00:00 2001 From: Artur Stolear Date: Sun, 17 Nov 2024 13:49:46 +0100 Subject: [PATCH 18/37] cleanup code targeting < net8.0 --- .../Polyfills/StringSyntaxAttribute.cs | 35 --------------- ...neratorTests.ShouldCreateFile.approved.txt | 16 ------- ...rlyOutputNamespaceDeclaration.approved.txt | 16 ------- ...neratorTests.ShouldCreateFile.approved.txt | 16 ------- ...rlyOutputNamespaceDeclaration.approved.txt | 41 +++++++++++++++++ ...neratorTests.ShouldCreateFile.approved.txt | 16 ------- ...rlyOutputNamespaceDeclaration.approved.txt | 45 +++++++++++++++++++ .../Output/GitVersionInfoGeneratorTests.cs | 7 +-- .../Templates/GitVersionInformation.cs | 16 ------- .../Templates/GitVersionInformation.fs | 16 ------- .../Templates/GitVersionInformation.vb | 16 ------- .../Helpers/StringBuilderExtensions.cs | 4 -- 12 files changed, 90 insertions(+), 154 deletions(-) delete mode 100644 src/GitVersion.Core/Polyfills/StringSyntaxAttribute.cs create mode 100644 src/GitVersion.Output.Tests/Output/Approved/fs/GitVersionInfoGeneratorTests.ShouldProperlyOutputNamespaceDeclaration.approved.txt create mode 100644 src/GitVersion.Output.Tests/Output/Approved/vb/GitVersionInfoGeneratorTests.ShouldProperlyOutputNamespaceDeclaration.approved.txt diff --git a/src/GitVersion.Core/Polyfills/StringSyntaxAttribute.cs b/src/GitVersion.Core/Polyfills/StringSyntaxAttribute.cs deleted file mode 100644 index f3faee9ed6..0000000000 --- a/src/GitVersion.Core/Polyfills/StringSyntaxAttribute.cs +++ /dev/null @@ -1,35 +0,0 @@ -#if !NET7_0_OR_GREATER - -// The namespace is important -namespace System.Diagnostics.CodeAnalysis; - -/// Fake version of the StringSyntaxAttribute, which was introduced in .NET 7 -[SuppressMessage("ApiDesign", "RS0016:Add public types and members to the declared API")] -[SuppressMessage("Style", "IDE0060:Remove unused parameter")] -[AttributeUsage(AttributeTargets.All)] -public sealed class StringSyntaxAttribute : Attribute -{ - /// The syntax identifier for strings containing composite formats. - public const string CompositeFormat = nameof(CompositeFormat); - - /// The syntax identifier for strings containing regular expressions. - public const string Regex = nameof(Regex); - - /// The syntax identifier for strings containing date information. - public const string DateTimeFormat = nameof(DateTimeFormat); - - /// - /// Initializes a new instance of the class. - /// - public StringSyntaxAttribute(string syntax) - { - } - - /// - /// Initializes a new instance of the class. - /// - public StringSyntaxAttribute(string syntax, params object?[] arguments) - { - } -} -#endif diff --git a/src/GitVersion.Output.Tests/Output/Approved/cs/GitVersionInfoGeneratorTests.ShouldCreateFile.approved.txt b/src/GitVersion.Output.Tests/Output/Approved/cs/GitVersionInfoGeneratorTests.ShouldCreateFile.approved.txt index 9c6b2b9a43..1289bd4dc8 100644 --- a/src/GitVersion.Output.Tests/Output/Approved/cs/GitVersionInfoGeneratorTests.ShouldCreateFile.approved.txt +++ b/src/GitVersion.Output.Tests/Output/Approved/cs/GitVersionInfoGeneratorTests.ShouldCreateFile.approved.txt @@ -8,22 +8,6 @@ // //------------------------------------------------------------------------------ -#if NET20 || NET35 || NETCOREAPP1_0 || NETCOREAPP1_1 || NETSTANDARD1_0 || NETSTANDARD1_1 || NETSTANDARD1_2 || NETSTANDARD1_3 || NETSTANDARD1_4 || NETSTANDARD1_5 || NETSTANDARD1_6 -namespace System.Diagnostics.CodeAnalysis -{ - [global::System.AttributeUsage( - global::System.AttributeTargets.Assembly | - global::System.AttributeTargets.Class | - global::System.AttributeTargets.Struct | - global::System.AttributeTargets.Constructor | - global::System.AttributeTargets.Method | - global::System.AttributeTargets.Property | - global::System.AttributeTargets.Event, - Inherited = false, AllowMultiple = false)] - internal sealed class ExcludeFromCodeCoverageAttribute : global::System.Attribute { } -} -#endif - [global::System.Runtime.CompilerServices.CompilerGenerated] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] static class GitVersionInformation diff --git a/src/GitVersion.Output.Tests/Output/Approved/cs/GitVersionInfoGeneratorTests.ShouldProperlyOutputNamespaceDeclaration.approved.txt b/src/GitVersion.Output.Tests/Output/Approved/cs/GitVersionInfoGeneratorTests.ShouldProperlyOutputNamespaceDeclaration.approved.txt index 14109e5d29..8cb6fbe737 100644 --- a/src/GitVersion.Output.Tests/Output/Approved/cs/GitVersionInfoGeneratorTests.ShouldProperlyOutputNamespaceDeclaration.approved.txt +++ b/src/GitVersion.Output.Tests/Output/Approved/cs/GitVersionInfoGeneratorTests.ShouldProperlyOutputNamespaceDeclaration.approved.txt @@ -8,22 +8,6 @@ // //------------------------------------------------------------------------------ -#if NET20 || NET35 || NETCOREAPP1_0 || NETCOREAPP1_1 || NETSTANDARD1_0 || NETSTANDARD1_1 || NETSTANDARD1_2 || NETSTANDARD1_3 || NETSTANDARD1_4 || NETSTANDARD1_5 || NETSTANDARD1_6 -namespace System.Diagnostics.CodeAnalysis -{ - [global::System.AttributeUsage( - global::System.AttributeTargets.Assembly | - global::System.AttributeTargets.Class | - global::System.AttributeTargets.Struct | - global::System.AttributeTargets.Constructor | - global::System.AttributeTargets.Method | - global::System.AttributeTargets.Property | - global::System.AttributeTargets.Event, - Inherited = false, AllowMultiple = false)] - internal sealed class ExcludeFromCodeCoverageAttribute : global::System.Attribute { } -} -#endif - namespace My.Custom.Namespace { [global::System.Runtime.CompilerServices.CompilerGenerated] diff --git a/src/GitVersion.Output.Tests/Output/Approved/fs/GitVersionInfoGeneratorTests.ShouldCreateFile.approved.txt b/src/GitVersion.Output.Tests/Output/Approved/fs/GitVersionInfoGeneratorTests.ShouldCreateFile.approved.txt index 52f2f04d87..f653c20b31 100644 --- a/src/GitVersion.Output.Tests/Output/Approved/fs/GitVersionInfoGeneratorTests.ShouldCreateFile.approved.txt +++ b/src/GitVersion.Output.Tests/Output/Approved/fs/GitVersionInfoGeneratorTests.ShouldCreateFile.approved.txt @@ -8,22 +8,6 @@ // //------------------------------------------------------------------------------ -#if NET20 || NET35 || NETCOREAPP1_0 || NETCOREAPP1_1 || NETSTANDARD1_0 || NETSTANDARD1_1 || NETSTANDARD1_2 || NETSTANDARD1_3 || NETSTANDARD1_4 || NETSTANDARD1_5 || NETSTANDARD1_6 -namespace System.Diagnostics.CodeAnalysis - -[] -[] -type ExcludeFromCodeCoverageAttribute() = inherit global.System.Attribute() -#endif - namespace global [] diff --git a/src/GitVersion.Output.Tests/Output/Approved/fs/GitVersionInfoGeneratorTests.ShouldProperlyOutputNamespaceDeclaration.approved.txt b/src/GitVersion.Output.Tests/Output/Approved/fs/GitVersionInfoGeneratorTests.ShouldProperlyOutputNamespaceDeclaration.approved.txt new file mode 100644 index 0000000000..c73ca5fba9 --- /dev/null +++ b/src/GitVersion.Output.Tests/Output/Approved/fs/GitVersionInfoGeneratorTests.ShouldProperlyOutputNamespaceDeclaration.approved.txt @@ -0,0 +1,41 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// GitVersion +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace My.Custom.Namespace + +[] +[] +[] +type GitVersionInformation = + static member AssemblySemFileVer = "1.2.3.0" + static member AssemblySemVer = "1.2.3.0" + static member BranchName = "feature1" + static member BuildMetaData = "5" + static member CommitDate = "2014-03-06" + static member CommitsSinceVersionSource = "5" + static member EscapedBranchName = "feature1" + static member FullBuildMetaData = "5.Branch.feature1.Sha.commitSha" + static member FullSemVer = "1.2.3-unstable.4+5" + static member InformationalVersion = "1.2.3-unstable.4+5.Branch.feature1.Sha.commitSha" + static member Major = "1" + static member MajorMinorPatch = "1.2.3" + static member Minor = "2" + static member Patch = "3" + static member PreReleaseLabel = "unstable" + static member PreReleaseLabelWithDash = "-unstable" + static member PreReleaseNumber = "4" + static member PreReleaseTag = "unstable.4" + static member PreReleaseTagWithDash = "-unstable.4" + static member SemVer = "1.2.3-unstable.4" + static member Sha = "commitSha" + static member ShortSha = "commitShortSha" + static member UncommittedChanges = "0" + static member VersionSourceSha = "versionSourceSha" + static member WeightedPreReleaseNumber = "4" diff --git a/src/GitVersion.Output.Tests/Output/Approved/vb/GitVersionInfoGeneratorTests.ShouldCreateFile.approved.txt b/src/GitVersion.Output.Tests/Output/Approved/vb/GitVersionInfoGeneratorTests.ShouldCreateFile.approved.txt index 200b58a1e2..91cb09fa24 100644 --- a/src/GitVersion.Output.Tests/Output/Approved/vb/GitVersionInfoGeneratorTests.ShouldCreateFile.approved.txt +++ b/src/GitVersion.Output.Tests/Output/Approved/vb/GitVersionInfoGeneratorTests.ShouldCreateFile.approved.txt @@ -8,22 +8,6 @@ ' '------------------------------------------------------------------------------ -#If NET20 OrElse NET35 OrElse NETCOREAPP1_0 OrElse NETCOREAPP1_1 OrElse NETSTANDARD1_0 OrElse NETSTANDARD1_1 OrElse NETSTANDARD1_2 OrElse NETSTANDARD1_3 OrElse NETSTANDARD1_4 OrElse NETSTANDARD1_5 OrElse NETSTANDARD1_6 Then -Namespace Global.System.Diagnostics.CodeAnalysis - - Friend NotInheritable Class ExcludeFromCodeCoverageAttribute - Inherits Global.System.Attribute - End Class -End Namespace -#End If - Namespace Global diff --git a/src/GitVersion.Output.Tests/Output/Approved/vb/GitVersionInfoGeneratorTests.ShouldProperlyOutputNamespaceDeclaration.approved.txt b/src/GitVersion.Output.Tests/Output/Approved/vb/GitVersionInfoGeneratorTests.ShouldProperlyOutputNamespaceDeclaration.approved.txt new file mode 100644 index 0000000000..153d3275fa --- /dev/null +++ b/src/GitVersion.Output.Tests/Output/Approved/vb/GitVersionInfoGeneratorTests.ShouldProperlyOutputNamespaceDeclaration.approved.txt @@ -0,0 +1,45 @@ +'------------------------------------------------------------------------------ +' +' This code was generated by a tool. +' GitVersion +' +' Changes to this file may cause incorrect behavior and will be lost if +' the code is regenerated. +' +'------------------------------------------------------------------------------ + +Namespace My.Custom.Namespace + + + + NotInheritable Class GitVersionInformation + Private Sub New() + End Sub + Public Shared AssemblySemFileVer As String = "1.2.3.0" + Public Shared AssemblySemVer As String = "1.2.3.0" + Public Shared BranchName As String = "feature1" + Public Shared BuildMetaData As String = "5" + Public Shared CommitDate As String = "2014-03-06" + Public Shared CommitsSinceVersionSource As String = "5" + Public Shared EscapedBranchName As String = "feature1" + Public Shared FullBuildMetaData As String = "5.Branch.feature1.Sha.commitSha" + Public Shared FullSemVer As String = "1.2.3-unstable.4+5" + Public Shared InformationalVersion As String = "1.2.3-unstable.4+5.Branch.feature1.Sha.commitSha" + Public Shared Major As String = "1" + Public Shared MajorMinorPatch As String = "1.2.3" + Public Shared Minor As String = "2" + Public Shared Patch As String = "3" + Public Shared PreReleaseLabel As String = "unstable" + Public Shared PreReleaseLabelWithDash As String = "-unstable" + Public Shared PreReleaseNumber As String = "4" + Public Shared PreReleaseTag As String = "unstable.4" + Public Shared PreReleaseTagWithDash As String = "-unstable.4" + Public Shared SemVer As String = "1.2.3-unstable.4" + Public Shared Sha As String = "commitSha" + Public Shared ShortSha As String = "commitShortSha" + Public Shared UncommittedChanges As String = "0" + Public Shared VersionSourceSha As String = "versionSourceSha" + Public Shared WeightedPreReleaseNumber As String = "4" + End Class + +End Namespace diff --git a/src/GitVersion.Output.Tests/Output/GitVersionInfoGeneratorTests.cs b/src/GitVersion.Output.Tests/Output/GitVersionInfoGeneratorTests.cs index 2fa8cb6a09..56ac52df1b 100644 --- a/src/GitVersion.Output.Tests/Output/GitVersionInfoGeneratorTests.cs +++ b/src/GitVersion.Output.Tests/Output/GitVersionInfoGeneratorTests.cs @@ -53,10 +53,11 @@ public void ShouldCreateFile(string fileExtension) /// /// Regression test for issue #4196 (https://github.com/GitTools/GitVersion/issues/4196) /// - [TestCase] - public void ShouldProperlyOutputNamespaceDeclaration() + [TestCase("cs")] + [TestCase("fs")] + [TestCase("vb")] + public void ShouldProperlyOutputNamespaceDeclaration(string fileExtension) { - const string fileExtension = "cs"; const string targetNamespace = "My.Custom.Namespace"; var directory = PathHelper.Combine(PathHelper.GetTempPath(), "GitVersionInfoGeneratorTests", Guid.NewGuid().ToString()); diff --git a/src/GitVersion.Output/GitVersionInfo/Templates/GitVersionInformation.cs b/src/GitVersion.Output/GitVersionInfo/Templates/GitVersionInformation.cs index 12deef9fa3..46527b8ca3 100644 --- a/src/GitVersion.Output/GitVersionInfo/Templates/GitVersionInformation.cs +++ b/src/GitVersion.Output/GitVersionInfo/Templates/GitVersionInformation.cs @@ -7,22 +7,6 @@ // the code is regenerated. // //------------------------------------------------------------------------------ - -#if NET20 || NET35 || NETCOREAPP1_0 || NETCOREAPP1_1 || NETSTANDARD1_0 || NETSTANDARD1_1 || NETSTANDARD1_2 || NETSTANDARD1_3 || NETSTANDARD1_4 || NETSTANDARD1_5 || NETSTANDARD1_6 -namespace System.Diagnostics.CodeAnalysis -{{ - [global::System.AttributeUsage( - global::System.AttributeTargets.Assembly | - global::System.AttributeTargets.Class | - global::System.AttributeTargets.Struct | - global::System.AttributeTargets.Constructor | - global::System.AttributeTargets.Method | - global::System.AttributeTargets.Property | - global::System.AttributeTargets.Event, - Inherited = false, AllowMultiple = false)] - internal sealed class ExcludeFromCodeCoverageAttribute : global::System.Attribute {{ }} -}} -#endif {1}{2} {4}[global::System.Runtime.CompilerServices.CompilerGenerated] {4}[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] diff --git a/src/GitVersion.Output/GitVersionInfo/Templates/GitVersionInformation.fs b/src/GitVersion.Output/GitVersionInfo/Templates/GitVersionInformation.fs index 0862986636..5fff544676 100644 --- a/src/GitVersion.Output/GitVersionInfo/Templates/GitVersionInformation.fs +++ b/src/GitVersion.Output/GitVersionInfo/Templates/GitVersionInformation.fs @@ -8,22 +8,6 @@ // //------------------------------------------------------------------------------ -#if NET20 || NET35 || NETCOREAPP1_0 || NETCOREAPP1_1 || NETSTANDARD1_0 || NETSTANDARD1_1 || NETSTANDARD1_2 || NETSTANDARD1_3 || NETSTANDARD1_4 || NETSTANDARD1_5 || NETSTANDARD1_6 -namespace System.Diagnostics.CodeAnalysis - -[] -[] -type ExcludeFromCodeCoverageAttribute() = inherit global.System.Attribute() -#endif - namespace {1} [] diff --git a/src/GitVersion.Output/GitVersionInfo/Templates/GitVersionInformation.vb b/src/GitVersion.Output/GitVersionInfo/Templates/GitVersionInformation.vb index b7f3b7b923..48105ab7ce 100644 --- a/src/GitVersion.Output/GitVersionInfo/Templates/GitVersionInformation.vb +++ b/src/GitVersion.Output/GitVersionInfo/Templates/GitVersionInformation.vb @@ -8,22 +8,6 @@ ' '------------------------------------------------------------------------------ -#If NET20 OrElse NET35 OrElse NETCOREAPP1_0 OrElse NETCOREAPP1_1 OrElse NETSTANDARD1_0 OrElse NETSTANDARD1_1 OrElse NETSTANDARD1_2 OrElse NETSTANDARD1_3 OrElse NETSTANDARD1_4 OrElse NETSTANDARD1_5 OrElse NETSTANDARD1_6 Then -Namespace Global.System.Diagnostics.CodeAnalysis - - Friend NotInheritable Class ExcludeFromCodeCoverageAttribute - Inherits Global.System.Attribute - End Class -End Namespace -#End If - Namespace {1} diff --git a/src/GitVersion.Testing/Helpers/StringBuilderExtensions.cs b/src/GitVersion.Testing/Helpers/StringBuilderExtensions.cs index a17c0d4e1a..2893be4336 100644 --- a/src/GitVersion.Testing/Helpers/StringBuilderExtensions.cs +++ b/src/GitVersion.Testing/Helpers/StringBuilderExtensions.cs @@ -1,15 +1,11 @@ -#if NET7_0_OR_GREATER using System.Diagnostics.CodeAnalysis; -#endif namespace GitVersion.Testing.Internal; internal static class StringBuilderExtensions { public static void AppendLineFormat(this StringBuilder stringBuilder, -#if NET7_0_OR_GREATER [StringSyntax(StringSyntaxAttribute.CompositeFormat)] -#endif string format, params object?[] args) { From c595f606a7883122c95876251bd56bc395e9833e Mon Sep 17 00:00:00 2001 From: Wendelin Niesl Date: Mon, 18 Nov 2024 13:17:40 +0100 Subject: [PATCH 19/37] fix: Typo in continuous-deployment.md --- docs/input/docs/reference/modes/continuous-deployment.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/input/docs/reference/modes/continuous-deployment.md b/docs/input/docs/reference/modes/continuous-deployment.md index d393f299ec..88d7f7887e 100644 --- a/docs/input/docs/reference/modes/continuous-deployment.md +++ b/docs/input/docs/reference/modes/continuous-deployment.md @@ -23,7 +23,7 @@ to deploy on production. This means that GitVersion will build * 1.1.0 * 1.1.1 -Tags are required in this mode to communicate when the deployement happens on production. +Tags are required in this mode to communicate when the deployment happens on production. ## Resources From deb3f51270c6a520a8400d1c725cf3ebfe8d39bc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 18 Nov 2024 16:26:17 +0000 Subject: [PATCH 20/37] (deps): Bump Microsoft.CodeAnalysis.Common, Microsoft.CodeAnalysis.CSharp, Microsoft.CodeAnalysis.VisualBasic, Buildalyzer, Microsoft.Build, Microsoft.Build.Utilities.Core, Microsoft.Extensions.DependencyInjection and System.Security.Cryptography.Xml Bumps [Microsoft.CodeAnalysis.Common](https://github.com/dotnet/roslyn), [Microsoft.CodeAnalysis.CSharp](https://github.com/dotnet/roslyn), [Microsoft.CodeAnalysis.VisualBasic](https://github.com/dotnet/roslyn), [Buildalyzer](https://github.com/phmonte/Buildalyzer), [Microsoft.Build](https://github.com/dotnet/msbuild), [Microsoft.Build.Utilities.Core](https://github.com/dotnet/msbuild), [Microsoft.Extensions.DependencyInjection](https://github.com/dotnet/runtime) and [System.Security.Cryptography.Xml](https://github.com/dotnet/runtime). These dependencies needed to be updated together. Updates `Microsoft.CodeAnalysis.Common` from 4.11.0 to 4.0.0 - [Release notes](https://github.com/dotnet/roslyn/releases) - [Changelog](https://github.com/dotnet/roslyn/blob/main/docs/Breaking%20API%20Changes.md) - [Commits](https://github.com/dotnet/roslyn/commits) Updates `Microsoft.CodeAnalysis.CSharp` from 4.11.0 to 4.0.0 - [Release notes](https://github.com/dotnet/roslyn/releases) - [Changelog](https://github.com/dotnet/roslyn/blob/main/docs/Breaking%20API%20Changes.md) - [Commits](https://github.com/dotnet/roslyn/commits) Updates `Microsoft.CodeAnalysis.VisualBasic` from 4.11.0 to 4.0.0 - [Release notes](https://github.com/dotnet/roslyn/releases) - [Changelog](https://github.com/dotnet/roslyn/blob/main/docs/Breaking%20API%20Changes.md) - [Commits](https://github.com/dotnet/roslyn/commits) Updates `Buildalyzer` from 7.0.2 to 7.1.0 - [Release notes](https://github.com/phmonte/Buildalyzer/releases) - [Changelog](https://github.com/phmonte/Buildalyzer/blob/main/RELEASE.md) - [Commits](https://github.com/phmonte/Buildalyzer/compare/7.0.2...7.1.0) Updates `Microsoft.Build` from 17.12.6 to 17.10.4 - [Release notes](https://github.com/dotnet/msbuild/releases) - [Changelog](https://github.com/dotnet/msbuild/blob/main/documentation/Changelog.md) - [Commits](https://github.com/dotnet/msbuild/compare/v17.12.6...v17.10.4) Updates `Microsoft.Build.Utilities.Core` from 17.12.6 to 17.10.4 - [Release notes](https://github.com/dotnet/msbuild/releases) - [Changelog](https://github.com/dotnet/msbuild/blob/main/documentation/Changelog.md) - [Commits](https://github.com/dotnet/msbuild/compare/v17.12.6...v17.10.4) Updates `Microsoft.Extensions.DependencyInjection` from 9.0.0 to 6.0.0 - [Release notes](https://github.com/dotnet/runtime/releases) - [Commits](https://github.com/dotnet/runtime/compare/v9.0.0...v6.0.0) Updates `System.Security.Cryptography.Xml` from 9.0.0 to 8.0.0 - [Release notes](https://github.com/dotnet/runtime/releases) - [Commits](https://github.com/dotnet/runtime/compare/v9.0.0...v8.0.0) --- updated-dependencies: - dependency-name: Microsoft.CodeAnalysis.Common dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: Microsoft.CodeAnalysis.CSharp dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: Microsoft.CodeAnalysis.VisualBasic dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: Buildalyzer dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: Microsoft.Build dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: Microsoft.Build.Utilities.Core dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: Microsoft.Extensions.DependencyInjection dependency-type: direct:production update-type: version-update:semver-major - dependency-name: System.Security.Cryptography.Xml dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- src/Directory.Packages.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props index 62986a291f..f189e7cfaa 100644 --- a/src/Directory.Packages.props +++ b/src/Directory.Packages.props @@ -18,7 +18,7 @@ - + From b069cb8aa33b32c502b2e380f9ba7096982a913d Mon Sep 17 00:00:00 2001 From: Artur Stolear Date: Tue, 19 Nov 2024 07:49:54 +0100 Subject: [PATCH 21/37] refactor null checks using ArgumentException and ArgumentNullException Simplify null and whitespace checks by using ArgumentException.ThrowIfNullOrWhiteSpace and ArgumentNullException.ThrowIfNull. This reduces repetitive code and enhances readability across various methods. --- src/GitVersion.Core.Tests/Helpers/TestConsole.cs | 3 ++- src/GitVersion.Core/Core/FileSystem.cs | 6 ++---- .../Extensions/EnumerableExtensions.cs | 14 +++++--------- src/GitVersion.Core/Helpers/PathHelper.cs | 15 +++++++++------ src/GitVersion.Core/Helpers/StringFormatWith.cs | 11 ++--------- src/GitVersion.Core/Logging/LogExtensions.cs | 5 +---- src/GitVersion.Output/TemplateManager.cs | 15 +++------------ .../Fixtures/RepositoryFixtureBase.cs | 3 ++- src/GitVersion.Testing/Helpers/ProcessHelper.cs | 6 ++---- 9 files changed, 28 insertions(+), 50 deletions(-) diff --git a/src/GitVersion.Core.Tests/Helpers/TestConsole.cs b/src/GitVersion.Core.Tests/Helpers/TestConsole.cs index 6484730db2..8a73e0e7db 100644 --- a/src/GitVersion.Core.Tests/Helpers/TestConsole.cs +++ b/src/GitVersion.Core.Tests/Helpers/TestConsole.cs @@ -1,3 +1,4 @@ +using GitVersion.Extensions; using GitVersion.Helpers; using GitVersion.Logging; @@ -12,7 +13,7 @@ public class TestConsole(params string[] responses) : IConsole public void WriteLine() => this.log.Info(PathHelper.NewLine); - public void Write(string? msg) => this.log.Info(msg ?? throw new ArgumentNullException(nameof(msg))); + public void Write(string? msg) => this.log.Info(msg.NotNull()); public string ReadLine() => this.responses.Dequeue(); diff --git a/src/GitVersion.Core/Core/FileSystem.cs b/src/GitVersion.Core/Core/FileSystem.cs index d3c41b59ea..50bd61f3a2 100644 --- a/src/GitVersion.Core/Core/FileSystem.cs +++ b/src/GitVersion.Core/Core/FileSystem.cs @@ -24,16 +24,14 @@ public void WriteAllText(string? file, string fileContents) public void WriteAllText(string? file, string fileContents, Encoding encoding) { - if (string.IsNullOrEmpty(file)) - throw new ArgumentNullException(nameof(file)); + ArgumentException.ThrowIfNullOrWhiteSpace(file); File.WriteAllText(file, fileContents, encoding); } public IEnumerable DirectoryEnumerateFiles(string? directory, string searchPattern, SearchOption searchOption) { - if (string.IsNullOrEmpty(directory)) - throw new ArgumentNullException(nameof(directory)); + ArgumentException.ThrowIfNullOrWhiteSpace(directory); return Directory.EnumerateFiles(directory, searchPattern, searchOption); } diff --git a/src/GitVersion.Core/Extensions/EnumerableExtensions.cs b/src/GitVersion.Core/Extensions/EnumerableExtensions.cs index 085de0f618..764fb89008 100644 --- a/src/GitVersion.Core/Extensions/EnumerableExtensions.cs +++ b/src/GitVersion.Core/Extensions/EnumerableExtensions.cs @@ -4,12 +4,11 @@ public static class EnumerableExtensions { public static T? OnlyOrDefault(this IEnumerable source) { - switch (source) + ArgumentNullException.ThrowIfNull(source); + + if (source is IList { Count: 1 } list) { - case null: - throw new ArgumentNullException(nameof(source)); - case IList { Count: 1 } list: - return list[0]; + return list[0]; } using var e = source.GetEnumerator(); @@ -21,10 +20,7 @@ public static class EnumerableExtensions public static T SingleOfType(this IEnumerable source) { - if (source == null) - { - throw new ArgumentNullException(nameof(source)); - } + ArgumentNullException.ThrowIfNull(source); return source.OfType().Single(); } diff --git a/src/GitVersion.Core/Helpers/PathHelper.cs b/src/GitVersion.Core/Helpers/PathHelper.cs index b89918ed75..caafb1b703 100644 --- a/src/GitVersion.Core/Helpers/PathHelper.cs +++ b/src/GitVersion.Core/Helpers/PathHelper.cs @@ -35,8 +35,8 @@ public static string GetFullPath(string? path) public static string Combine(string? path1, string? path2) { - if (path1 == null || path2 == null) - throw new ArgumentNullException((path1 == null) ? nameof(path1) : nameof(path2)); + ArgumentException.ThrowIfNullOrWhiteSpace(path1); + ArgumentException.ThrowIfNullOrWhiteSpace(path2); return Path.Combine(path1, path2); } @@ -50,16 +50,19 @@ public static string Combine(string? path1) public static string Combine(string? path1, string? path2, string? path3) { - if (path1 == null || path2 == null || path3 == null) - throw new ArgumentNullException((path1 == null) ? nameof(path1) : (path2 == null) ? nameof(path2) : nameof(path3)); + ArgumentException.ThrowIfNullOrWhiteSpace(path1); + ArgumentException.ThrowIfNullOrWhiteSpace(path2); + ArgumentException.ThrowIfNullOrWhiteSpace(path3); return Path.Combine(path1, path2, path3); } public static string Combine(string? path1, string? path2, string? path3, string? path4) { - if (path1 == null || path2 == null || path3 == null || path4 == null) - throw new ArgumentNullException((path1 == null) ? nameof(path1) : (path2 == null) ? nameof(path2) : (path3 == null) ? nameof(path3) : nameof(path4)); + ArgumentException.ThrowIfNullOrWhiteSpace(path1); + ArgumentException.ThrowIfNullOrWhiteSpace(path2); + ArgumentException.ThrowIfNullOrWhiteSpace(path3); + ArgumentException.ThrowIfNullOrWhiteSpace(path4); return Path.Combine(path1, path2, path3, path4); } diff --git a/src/GitVersion.Core/Helpers/StringFormatWith.cs b/src/GitVersion.Core/Helpers/StringFormatWith.cs index c6732c24c5..5aa51b5ae0 100644 --- a/src/GitVersion.Core/Helpers/StringFormatWith.cs +++ b/src/GitVersion.Core/Helpers/StringFormatWith.cs @@ -30,15 +30,8 @@ internal static class StringFormatWithExtension /// public static string FormatWith(this string template, T? source, IEnvironment environment) { - if (template is null) - { - throw new ArgumentNullException(nameof(template)); - } - - if (source is null) - { - throw new ArgumentNullException(nameof(source)); - } + ArgumentNullException.ThrowIfNull(template); + ArgumentNullException.ThrowIfNull(source); foreach (Match match in RegexPatterns.Common.ExpandTokensRegex.Matches(template).Cast()) { diff --git a/src/GitVersion.Core/Logging/LogExtensions.cs b/src/GitVersion.Core/Logging/LogExtensions.cs index 77dff958a6..56d83b3321 100644 --- a/src/GitVersion.Core/Logging/LogExtensions.cs +++ b/src/GitVersion.Core/Logging/LogExtensions.cs @@ -96,10 +96,7 @@ private static void Write(this ILog log, LogLevel level, LogAction? logAction) private static IDisposable WithVerbosity(this ILog log, Verbosity verbosity) { - if (log == null) - { - throw new ArgumentNullException(nameof(log)); - } + ArgumentNullException.ThrowIfNull(log); var lastVerbosity = log.Verbosity; log.Verbosity = verbosity; return Disposable.Create(() => log.Verbosity = lastVerbosity); diff --git a/src/GitVersion.Output/TemplateManager.cs b/src/GitVersion.Output/TemplateManager.cs index 8246369fc2..7eb60d3d54 100644 --- a/src/GitVersion.Output/TemplateManager.cs +++ b/src/GitVersion.Output/TemplateManager.cs @@ -15,10 +15,7 @@ internal class TemplateManager(TemplateType templateType) public string? GetTemplateFor(string fileExtension) { - if (fileExtension == null) - { - throw new ArgumentNullException(nameof(fileExtension)); - } + ArgumentNullException.ThrowIfNull(fileExtension); string? result = null; @@ -32,10 +29,7 @@ internal class TemplateManager(TemplateType templateType) public string? GetAddFormatFor(string fileExtension) { - if (fileExtension == null) - { - throw new ArgumentNullException(nameof(fileExtension)); - } + ArgumentNullException.ThrowIfNull(fileExtension); string? result = null; @@ -49,10 +43,7 @@ internal class TemplateManager(TemplateType templateType) public bool IsSupported(string fileExtension) { - if (fileExtension == null) - { - throw new ArgumentNullException(nameof(fileExtension)); - } + ArgumentNullException.ThrowIfNull(fileExtension); return this.templates.ContainsKey(fileExtension); } diff --git a/src/GitVersion.Testing/Fixtures/RepositoryFixtureBase.cs b/src/GitVersion.Testing/Fixtures/RepositoryFixtureBase.cs index 2da6a5069f..1ac92f2086 100644 --- a/src/GitVersion.Testing/Fixtures/RepositoryFixtureBase.cs +++ b/src/GitVersion.Testing/Fixtures/RepositoryFixtureBase.cs @@ -1,6 +1,7 @@ using GitVersion.Helpers; using GitVersion.Testing.Internal; using LibGit2Sharp; +using Shouldly; namespace GitVersion.Testing; @@ -17,7 +18,7 @@ protected RepositoryFixtureBase(Func repositoryBuilder) protected RepositoryFixtureBase(Repository repository) { SequenceDiagram = new(); - Repository = repository ?? throw new ArgumentNullException(nameof(repository)); + Repository = repository.ShouldNotBeNull(); Repository.Config.Set("user.name", "Test"); Repository.Config.Set("user.email", "test@email.com"); } diff --git a/src/GitVersion.Testing/Helpers/ProcessHelper.cs b/src/GitVersion.Testing/Helpers/ProcessHelper.cs index b5f269ce95..466472bd1e 100644 --- a/src/GitVersion.Testing/Helpers/ProcessHelper.cs +++ b/src/GitVersion.Testing/Helpers/ProcessHelper.cs @@ -76,10 +76,8 @@ public static class ProcessHelper // http://csharptest.net/532/using-processstart-to-capture-console-output/ public static int Run(Action output, Action errorOutput, TextReader? input, string exe, string args, string workingDirectory, params KeyValuePair[] environmentalVariables) { - if (string.IsNullOrEmpty(exe)) - throw new ArgumentNullException(nameof(exe)); - if (output == null) - throw new ArgumentNullException(nameof(output)); + ArgumentException.ThrowIfNullOrWhiteSpace(exe); + ArgumentNullException.ThrowIfNull(output); var psi = new ProcessStartInfo { From 8dc3cd1c9fc8516f1c14b7594eb3dc3ed18ff222 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 19 Nov 2024 16:12:36 +0000 Subject: [PATCH 22/37] (deps): Bump Microsoft.NET.Test.Sdk Bumps the microsoft group with 1 update in the /src directory: [Microsoft.NET.Test.Sdk](https://github.com/microsoft/vstest). Updates `Microsoft.NET.Test.Sdk` from 17.11.1 to 17.12.0 - [Release notes](https://github.com/microsoft/vstest/releases) - [Changelog](https://github.com/microsoft/vstest/blob/main/docs/releases.md) - [Commits](https://github.com/microsoft/vstest/compare/v17.11.1...v17.12.0) --- updated-dependencies: - dependency-name: Microsoft.NET.Test.Sdk dependency-type: direct:production update-type: version-update:semver-minor dependency-group: microsoft ... Signed-off-by: dependabot[bot] --- src/Directory.Packages.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props index f189e7cfaa..b16159dacf 100644 --- a/src/Directory.Packages.props +++ b/src/Directory.Packages.props @@ -29,7 +29,7 @@ - + From 6c1cfcc8c37396be3b9adbc88148280ae9c89462 Mon Sep 17 00:00:00 2001 From: Artur Stolear Date: Wed, 20 Nov 2024 07:07:12 +0100 Subject: [PATCH 23/37] (dependabot) Add .NET SDK to Dependabot configuration This commit introduces the .NET SDK to the Dependabot configuration file. By doing so, it ensures that dependencies for .NET SDK are automatically tracked and updated. Labels and commit message prefixes are also specified for consistency. --- .github/dependabot.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index ecc644fda4..60831b08ed 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,5 +1,13 @@ version: 2 updates: +- package-ecosystem: dotnet-sdk + labels: + - "dependencies" + commit-message: + prefix: "(deps)" + directory: "/" + schedule: + interval: daily - package-ecosystem: nuget labels: - "dependencies" From de3e0f4166da8b8322f018902949ca2197829065 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 2 Dec 2024 16:47:41 +0000 Subject: [PATCH 24/37] (deps): Bump YamlDotNet from 16.2.0 to 16.2.1 in /src Bumps [YamlDotNet](https://github.com/aaubry/YamlDotNet) from 16.2.0 to 16.2.1. - [Release notes](https://github.com/aaubry/YamlDotNet/releases) - [Commits](https://github.com/aaubry/YamlDotNet/compare/v16.2.0...v16.2.1) --- updated-dependencies: - dependency-name: YamlDotNet dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- src/Directory.Packages.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props index b16159dacf..b5967e536e 100644 --- a/src/Directory.Packages.props +++ b/src/Directory.Packages.props @@ -39,7 +39,7 @@ - + \ No newline at end of file From ef7f0bc1ece6fe8c1211b27ba424ade47661b75c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 2 Dec 2024 16:48:12 +0000 Subject: [PATCH 25/37] (deps): Bump JsonSchema.Net.Generation from 4.5.1 to 4.6.0 in /src Bumps [JsonSchema.Net.Generation](https://github.com/json-everything/json-everything) from 4.5.1 to 4.6.0. - [Commits](https://github.com/json-everything/json-everything/compare/schema-gen-v4.5.1...schema-gen-v4.6.0) --- updated-dependencies: - dependency-name: JsonSchema.Net.Generation dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- src/Directory.Packages.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props index b5967e536e..7b94376646 100644 --- a/src/Directory.Packages.props +++ b/src/Directory.Packages.props @@ -19,7 +19,7 @@ - + From ec820b90cedf5cf8a7512e097be41002ddd7b5dd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 3 Dec 2024 15:50:39 +0000 Subject: [PATCH 26/37] (deps): Bump LibGit2Sharp from 0.30.0 to 0.31.0 in /new-cli Bumps [LibGit2Sharp](https://github.com/libgit2/libgit2sharp) from 0.30.0 to 0.31.0. - [Release notes](https://github.com/libgit2/libgit2sharp/releases) - [Changelog](https://github.com/libgit2/libgit2sharp/blob/master/CHANGES.md) - [Commits](https://github.com/libgit2/libgit2sharp/compare/0.30.0...0.31.0) --- updated-dependencies: - dependency-name: LibGit2Sharp dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- new-cli/Directory.Packages.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/new-cli/Directory.Packages.props b/new-cli/Directory.Packages.props index 954cffd0ea..dfa00fa4e1 100644 --- a/new-cli/Directory.Packages.props +++ b/new-cli/Directory.Packages.props @@ -4,7 +4,7 @@ - + From 48161abf4762132612c7e84d20ae1977f1e4ba59 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 4 Dec 2024 15:49:57 +0000 Subject: [PATCH 27/37] (deps): Bump dotnet-sdk from 9.0.100 to 9.0.101 Bumps [dotnet-sdk](https://github.com/dotnet/sdk) from 9.0.100 to 9.0.101. - [Release notes](https://github.com/dotnet/sdk/releases) - [Commits](https://github.com/dotnet/sdk/commits) --- updated-dependencies: - dependency-name: dotnet-sdk dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- global.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/global.json b/global.json index 7806149646..7b200833ee 100644 --- a/global.json +++ b/global.json @@ -5,6 +5,6 @@ "src" ], "sdk": { - "version": "9.0.100" + "version": "9.0.101" } } From 5c84c80bf0049f2e81053decd5df2bfcd1a75b12 Mon Sep 17 00:00:00 2001 From: Artur Stolear Date: Wed, 4 Dec 2024 13:17:55 +0100 Subject: [PATCH 28/37] Simplify ArgumentBuilder and remove unused parameters Refactored the ArgumentBuilder class to reduce complexity by consolidating constructors and eliminating redundant parameters. Removed the obsolete ExecuteIn method that utilized these parameters from GitVersionHelper. Updated the test case to align with the new method signature and ensure functionality remains intact. --- .../Helpers/ArgumentBuilder.cs | 53 ++----------------- .../Helpers/GitVersionHelper.cs | 14 ----- 2 files changed, 4 insertions(+), 63 deletions(-) diff --git a/src/GitVersion.App.Tests/Helpers/ArgumentBuilder.cs b/src/GitVersion.App.Tests/Helpers/ArgumentBuilder.cs index 5b05685c41..38678c4987 100644 --- a/src/GitVersion.App.Tests/Helpers/ArgumentBuilder.cs +++ b/src/GitVersion.App.Tests/Helpers/ArgumentBuilder.cs @@ -2,30 +2,11 @@ namespace GitVersion.App.Tests; -public class ArgumentBuilder +public class ArgumentBuilder(string? workingDirectory, string? additionalArguments, string? logFile) { - public ArgumentBuilder(string? workingDirectory) => this.WorkingDirectory = workingDirectory; + public string? WorkingDirectory { get; } = workingDirectory; - public ArgumentBuilder(string? workingDirectory, string? exec, string? execArgs, string? projectFile, string? projectArgs, string? logFile) - { - this.WorkingDirectory = workingDirectory; - this.exec = exec; - this.execArgs = execArgs; - this.projectFile = projectFile; - this.projectArgs = projectArgs; - this.LogFile = logFile; - } - - public ArgumentBuilder(string? workingDirectory, string? additionalArguments, string? logFile) - { - this.WorkingDirectory = workingDirectory; - this.additionalArguments = additionalArguments; - this.LogFile = logFile; - } - - public string? WorkingDirectory { get; } - - public string? LogFile { get; } + public string? LogFile { get; } = logFile; public override string ToString() { @@ -36,39 +17,13 @@ public override string ToString() arguments.Append(" /targetpath \"").Append(this.WorkingDirectory).Append('\"'); } - if (!this.exec.IsNullOrWhiteSpace()) - { - arguments.Append(" /exec \"").Append(this.exec).Append('\"'); - } - - if (!this.execArgs.IsNullOrWhiteSpace()) - { - arguments.Append(" /execArgs \"").Append(this.execArgs).Append('\"'); - } - - if (!this.projectFile.IsNullOrWhiteSpace()) - { - arguments.Append(" /proj \"").Append(this.projectFile).Append('\"'); - } - - if (!this.projectArgs.IsNullOrWhiteSpace()) - { - arguments.Append(" /projargs \"").Append(this.projectArgs).Append('\"'); - } - if (!this.LogFile.IsNullOrWhiteSpace()) { arguments.Append(" /l \"").Append(this.LogFile).Append('\"'); } - arguments.Append(this.additionalArguments); + arguments.Append(additionalArguments); return arguments.ToString(); } - - private readonly string? additionalArguments; - private readonly string? exec; - private readonly string? execArgs; - private readonly string? projectArgs; - private readonly string? projectFile; } diff --git a/src/GitVersion.App.Tests/Helpers/GitVersionHelper.cs b/src/GitVersion.App.Tests/Helpers/GitVersionHelper.cs index 2e8aa0e3ae..6e46593bb2 100644 --- a/src/GitVersion.App.Tests/Helpers/GitVersionHelper.cs +++ b/src/GitVersion.App.Tests/Helpers/GitVersionHelper.cs @@ -7,20 +7,6 @@ namespace GitVersion.App.Tests; public static class GitVersionHelper { - public static ExecutionResults ExecuteIn(string? workingDirectory, - string? exec = null, - string? execArgs = null, - string? projectFile = null, - string? projectArgs = null, - bool logToFile = true, - params KeyValuePair[] environments - ) - { - var logFile = logToFile ? PathHelper.Combine(workingDirectory, "log.txt") : null; - var args = new ArgumentBuilder(workingDirectory, exec, execArgs, projectFile, projectArgs, logFile); - return ExecuteIn(args, environments); - } - public static ExecutionResults ExecuteIn( string? workingDirectory, string? arguments, From 1ee8ef32a1746be018463f861f502ae353e4c095 Mon Sep 17 00:00:00 2001 From: Artur Stolear Date: Wed, 4 Dec 2024 13:17:55 +0100 Subject: [PATCH 29/37] Simplify ArgumentBuilder and remove unused parameters Refactored the ArgumentBuilder class to reduce complexity by consolidating constructors and eliminating redundant parameters. Removed the obsolete ExecuteIn method that utilized these parameters from GitVersionHelper. Updated the test case to align with the new method signature and ensure functionality remains intact. --- new-cli/Directory.Packages.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/new-cli/Directory.Packages.props b/new-cli/Directory.Packages.props index dfa00fa4e1..954cffd0ea 100644 --- a/new-cli/Directory.Packages.props +++ b/new-cli/Directory.Packages.props @@ -4,7 +4,7 @@ - + From fb71e8a2444a16ca6a2f0bb7405550321f30f653 Mon Sep 17 00:00:00 2001 From: Artur Stolear Date: Wed, 4 Dec 2024 23:44:25 +0100 Subject: [PATCH 30/37] Ignore specific version of LibGit2Sharp in Dependabot This change adds an ignore rule for version 0.31.0 of the LibGit2Sharp dependency in the Dependabot configuration file. --- .github/dependabot.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 60831b08ed..f74944833f 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -32,6 +32,8 @@ updates: - "/new-cli" - "/src" - "/" + ignore: + - dependency-name: "LibGit2Sharp" schedule: interval: daily open-pull-requests-limit: 10 From 0fecafcccff25f3b06df0226e908fbe426708b42 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 6 Dec 2024 15:48:35 +0000 Subject: [PATCH 31/37] (build deps): Bump crazy-max/ghaction-setup-docker from 3 to 4 Bumps [crazy-max/ghaction-setup-docker](https://github.com/crazy-max/ghaction-setup-docker) from 3 to 4. - [Release notes](https://github.com/crazy-max/ghaction-setup-docker/releases) - [Commits](https://github.com/crazy-max/ghaction-setup-docker/compare/v3...v4) --- updated-dependencies: - dependency-name: crazy-max/ghaction-setup-docker dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/_docker.yml | 2 +- .github/workflows/_docker_manifests.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/_docker.yml b/.github/workflows/_docker.yml index dcf56d056c..8514377ad6 100644 --- a/.github/workflows/_docker.yml +++ b/.github/workflows/_docker.yml @@ -43,7 +43,7 @@ jobs: path: ${{ github.workspace }}/artifacts/packages/nuget - name: Set up Docker - uses: crazy-max/ghaction-setup-docker@v3 + uses: docker/setup-docker-action@v4 with: daemon-config: '{ "features": { "containerd-snapshotter": true } }' - diff --git a/.github/workflows/_docker_manifests.yml b/.github/workflows/_docker_manifests.yml index abb3b5cd05..2e72c53e51 100644 --- a/.github/workflows/_docker_manifests.yml +++ b/.github/workflows/_docker_manifests.yml @@ -31,7 +31,7 @@ jobs: uses: ./.github/actions/cache-restore - name: Set up Docker - uses: crazy-max/ghaction-setup-docker@v3 + uses: docker/setup-docker-action@v4 with: daemon-config: '{ "features": { "containerd-snapshotter": true } }' - From 2305b7cef270b6e248e6e123f3f33f130ee19fbd Mon Sep 17 00:00:00 2001 From: Artur Stolear Date: Mon, 18 Nov 2024 13:21:49 +0100 Subject: [PATCH 32/37] removed TestFileSystem and usage --- .../GitVersion.App.Tests.csproj | 2 - .../ConfigurationProviderTests.cs | 3 +- .../Configuration/Extensions.cs | 6 ++ .../Core/DynamicRepositoryTests.cs | 6 +- .../Helpers/GitVersionCoreTestModule.cs | 2 +- .../Helpers/TestFileSystem.cs | 96 ------------------- .../Helpers/TestStream.cs | 38 -------- src/GitVersion.Core/Helpers/PathHelper.cs | 7 ++ .../Caching/GitVersionCacheKeyFactory.cs | 2 +- .../GitVersion.MsBuild.Tests.csproj | 2 - .../Output/AssemblyInfoFileUpdaterTests.cs | 4 +- .../Output/WixFileTests.cs | 4 + .../WixUpdater/WixVersionFileUpdater.cs | 10 +- src/GitVersion.sln.DotSettings | 13 +-- 14 files changed, 39 insertions(+), 156 deletions(-) delete mode 100644 src/GitVersion.Core.Tests/Helpers/TestFileSystem.cs delete mode 100644 src/GitVersion.Core.Tests/Helpers/TestStream.cs diff --git a/src/GitVersion.App.Tests/GitVersion.App.Tests.csproj b/src/GitVersion.App.Tests/GitVersion.App.Tests.csproj index 0d2f6f3e71..111e288a9f 100644 --- a/src/GitVersion.App.Tests/GitVersion.App.Tests.csproj +++ b/src/GitVersion.App.Tests/GitVersion.App.Tests.csproj @@ -19,9 +19,7 @@ - - diff --git a/src/GitVersion.Configuration.Tests/Configuration/ConfigurationProviderTests.cs b/src/GitVersion.Configuration.Tests/Configuration/ConfigurationProviderTests.cs index 9ece53a3f5..f693649640 100644 --- a/src/GitVersion.Configuration.Tests/Configuration/ConfigurationProviderTests.cs +++ b/src/GitVersion.Configuration.Tests/Configuration/ConfigurationProviderTests.cs @@ -285,7 +285,8 @@ public void NoWarnOnGitVersionYmlFile() this.configurationProvider.ProvideForDirectory(this.repoPath); - stringLogger.Length.ShouldBe(0); + var filePath = PathHelper.Combine(this.repoPath, ConfigurationFileLocator.DefaultFileName); + stringLogger.ShouldContain($"Found configuration file at '{filePath}'"); } [Test] diff --git a/src/GitVersion.Configuration.Tests/Configuration/Extensions.cs b/src/GitVersion.Configuration.Tests/Configuration/Extensions.cs index 96db0f145c..6000db6c6c 100644 --- a/src/GitVersion.Configuration.Tests/Configuration/Extensions.cs +++ b/src/GitVersion.Configuration.Tests/Configuration/Extensions.cs @@ -13,6 +13,12 @@ public static IDisposable SetupConfigFile(this IFileSystem fileSystem, s } var fullPath = PathHelper.Combine(path, fileName); + var directory = PathHelper.GetDirectoryName(fullPath); + if (!fileSystem.DirectoryExists(directory)) + { + fileSystem.CreateDirectory(directory); + } + fileSystem.WriteAllText(fullPath, text); return Disposable.Create(fullPath, () => fileSystem.Delete(fullPath)); diff --git a/src/GitVersion.Core.Tests/Core/DynamicRepositoryTests.cs b/src/GitVersion.Core.Tests/Core/DynamicRepositoryTests.cs index 0535fc714e..ff6db85e6e 100644 --- a/src/GitVersion.Core.Tests/Core/DynamicRepositoryTests.cs +++ b/src/GitVersion.Core.Tests/Core/DynamicRepositoryTests.cs @@ -23,7 +23,7 @@ private static void ClearReadOnly(DirectoryInfo parentDirectory) } } - [OneTimeSetUp] + [SetUp] public void CreateTemporaryRepository() { // Note: we can't use guid because paths will be too long @@ -41,15 +41,15 @@ public void CreateTemporaryRepository() Directory.CreateDirectory(this.workDirectory); } - [OneTimeTearDown] + [TearDown] public void Cleanup() { } // Note: use same name twice to see if changing commits works on same (cached) repository [NonParallelizable] - [TestCase("GV_main", "https://github.com/GitTools/GitVersion", MainBranch, "efddf2f92c539a9c27f1904d952dcab8fb955f0e", "5.8.2-56")] [TestCase("GV_main", "https://github.com/GitTools/GitVersion", MainBranch, "2dc142a4a4df77db61a00d9fb7510b18b3c2c85a", "5.8.2-47")] + [TestCase("GV_main", "https://github.com/GitTools/GitVersion", MainBranch, "efddf2f92c539a9c27f1904d952dcab8fb955f0e", "5.8.2-56")] public void FindsVersionInDynamicRepo(string name, string url, string targetBranch, string commitId, string expectedFullSemVer) { var root = PathHelper.Combine(this.workDirectory, name); diff --git a/src/GitVersion.Core.Tests/Helpers/GitVersionCoreTestModule.cs b/src/GitVersion.Core.Tests/Helpers/GitVersionCoreTestModule.cs index e6410ceb26..755287a94d 100644 --- a/src/GitVersion.Core.Tests/Helpers/GitVersionCoreTestModule.cs +++ b/src/GitVersion.Core.Tests/Helpers/GitVersionCoreTestModule.cs @@ -17,7 +17,7 @@ public void RegisterTypes(IServiceCollection services) services.AddModule(new GitVersionConfigurationModule()); services.AddModule(new GitVersionCoreModule()); - services.AddSingleton(); + services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); } diff --git a/src/GitVersion.Core.Tests/Helpers/TestFileSystem.cs b/src/GitVersion.Core.Tests/Helpers/TestFileSystem.cs deleted file mode 100644 index 06a4f74ee4..0000000000 --- a/src/GitVersion.Core.Tests/Helpers/TestFileSystem.cs +++ /dev/null @@ -1,96 +0,0 @@ -using GitVersion.Helpers; - -namespace GitVersion.Core.Tests.Helpers; - -public class TestFileSystem : IFileSystem -{ - private readonly Dictionary fileSystem = new(SysEnv.OSVersion.Platform == PlatformID.Unix ? StringComparer.Ordinal : StringComparer.OrdinalIgnoreCase); - - public void Copy(string from, string to, bool overwrite) - { - var fromPath = Path.GetFullPath(from); - var toPath = Path.GetFullPath(to); - if (this.fileSystem.ContainsKey(toPath)) - { - if (overwrite) - this.fileSystem.Remove(toPath); - else - throw new IOException("File already exists"); - } - - if (!this.fileSystem.TryGetValue(fromPath, out var source)) - throw new FileNotFoundException($"The source file '{fromPath}' was not found", from); - - this.fileSystem.Add(toPath, source); - } - - public void Move(string from, string to) - { - var fromPath = Path.GetFullPath(from); - Copy(from, to, false); - this.fileSystem.Remove(fromPath); - } - - public bool Exists(string file) - { - var path = Path.GetFullPath(file); - return this.fileSystem.ContainsKey(path); - } - - public void Delete(string path) - { - var fullPath = Path.GetFullPath(path); - this.fileSystem.Remove(fullPath); - } - - public string ReadAllText(string path) - { - var fullPath = Path.GetFullPath(path); - if (!this.fileSystem.TryGetValue(fullPath, out var content)) - throw new FileNotFoundException($"The file '{fullPath}' was not found", fullPath); - - var encoding = EncodingHelper.DetectEncoding(content) ?? Encoding.UTF8; - return encoding.GetString(content); - } - - public void WriteAllText(string? file, string fileContents) - { - var path = Path.GetFullPath(file ?? throw new ArgumentNullException(nameof(file))); - var encoding = fileSystem.TryGetValue(path, out var value) ? EncodingHelper.DetectEncoding(value) ?? Encoding.UTF8 - : Encoding.UTF8; - WriteAllText(path, fileContents, encoding); - } - - public void WriteAllText(string? file, string fileContents, Encoding encoding) - { - var path = Path.GetFullPath(file ?? throw new ArgumentNullException(nameof(file))); - this.fileSystem[path] = encoding.GetBytes(fileContents); - } - - public IEnumerable DirectoryEnumerateFiles(string? directory, string searchPattern, SearchOption searchOption) => throw new NotImplementedException(); - - public Stream OpenWrite(string path) => new TestStream(path, this); - - public Stream OpenRead(string path) - { - var fullPath = Path.GetFullPath(path); - if (!this.fileSystem.TryGetValue(fullPath, out var content)) - throw new FileNotFoundException("File not found.", fullPath); - - return new MemoryStream(content); - } - - public void CreateDirectory(string path) - { - var fullPath = Path.GetFullPath(path); - this.fileSystem[fullPath] = []; - } - - public bool DirectoryExists(string path) - { - var fullPath = Path.GetFullPath(path); - return this.fileSystem.ContainsKey(fullPath); - } - - public long GetLastDirectoryWrite(string path) => 1; -} diff --git a/src/GitVersion.Core.Tests/Helpers/TestStream.cs b/src/GitVersion.Core.Tests/Helpers/TestStream.cs deleted file mode 100644 index 836a45474f..0000000000 --- a/src/GitVersion.Core.Tests/Helpers/TestStream.cs +++ /dev/null @@ -1,38 +0,0 @@ -namespace GitVersion.Core.Tests.Helpers; - -public class TestStream(string path, IFileSystem testFileSystem) : Stream -{ - private readonly MemoryStream underlying = new(); - - protected override void Dispose(bool disposing) - { - Flush(); - base.Dispose(disposing); - } - - public override void Flush() - { - this.underlying.Position = 0; - var readToEnd = new StreamReader(this.underlying).ReadToEnd(); - testFileSystem.WriteAllText(path, readToEnd); - } - - public override long Seek(long offset, SeekOrigin origin) => this.underlying.Seek(offset, origin); - - public override void SetLength(long value) => this.underlying.SetLength(value); - - public override int Read(byte[] buffer, int offset, int count) => this.underlying.Read(buffer, offset, count); - - public override void Write(byte[] buffer, int offset, int count) => this.underlying.Write(buffer, offset, count); - - public override bool CanRead => this.underlying.CanRead; - public override bool CanSeek => this.underlying.CanSeek; - public override bool CanWrite => this.underlying.CanWrite; - public override long Length => this.underlying.Length; - - public override long Position - { - get => this.underlying.Position; - set => this.underlying.Position = value; - } -} diff --git a/src/GitVersion.Core/Helpers/PathHelper.cs b/src/GitVersion.Core/Helpers/PathHelper.cs index caafb1b703..3c9d853a1d 100644 --- a/src/GitVersion.Core/Helpers/PathHelper.cs +++ b/src/GitVersion.Core/Helpers/PathHelper.cs @@ -26,6 +26,13 @@ public static string GetTempPath() public static string GetRepositoryTempPath() => Combine(GetTempPath(), "TestRepositories", Guid.NewGuid().ToString()); + public static string GetDirectoryName(string? path) + { + ArgumentNullException.ThrowIfNull(path, nameof(path)); + + return Path.GetDirectoryName(path)!; + } + public static string GetFullPath(string? path) { ArgumentNullException.ThrowIfNull(path, nameof(path)); diff --git a/src/GitVersion.Core/VersionCalculation/Caching/GitVersionCacheKeyFactory.cs b/src/GitVersion.Core/VersionCalculation/Caching/GitVersionCacheKeyFactory.cs index f2cd6919a1..c24047a798 100644 --- a/src/GitVersion.Core/VersionCalculation/Caching/GitVersionCacheKeyFactory.cs +++ b/src/GitVersion.Core/VersionCalculation/Caching/GitVersionCacheKeyFactory.cs @@ -118,7 +118,7 @@ private List CalculateDirectoryContents(string root) { var fi = new FileInfo(file); result.Add(fi.Name); - result.Add(File.ReadAllText(file)); + result.Add(this.fileSystem.ReadAllText(file)); } catch (IOException e) { diff --git a/src/GitVersion.MsBuild.Tests/GitVersion.MsBuild.Tests.csproj b/src/GitVersion.MsBuild.Tests/GitVersion.MsBuild.Tests.csproj index b7677e977d..428b5be4a2 100644 --- a/src/GitVersion.MsBuild.Tests/GitVersion.MsBuild.Tests.csproj +++ b/src/GitVersion.MsBuild.Tests/GitVersion.MsBuild.Tests.csproj @@ -31,9 +31,7 @@ - - diff --git a/src/GitVersion.Output.Tests/Output/AssemblyInfoFileUpdaterTests.cs b/src/GitVersion.Output.Tests/Output/AssemblyInfoFileUpdaterTests.cs index 8ce95285be..557d7d1abd 100644 --- a/src/GitVersion.Output.Tests/Output/AssemblyInfoFileUpdaterTests.cs +++ b/src/GitVersion.Output.Tests/Output/AssemblyInfoFileUpdaterTests.cs @@ -19,7 +19,7 @@ public class AssemblyInfoFileUpdaterTests : TestBase private string workingDir; [OneTimeSetUp] - public void OneTimeSetUp() => workingDir = PathHelper.Combine(PathHelper.GetTempPath(), "AssemblyInfoFileUpdaterTests"); + public void OneTimeSetUp() => workingDir = PathHelper.Combine(PathHelper.GetTempPath(), nameof(AssemblyInfoFileUpdaterTests)); [OneTimeTearDown] public void OneTimeTearDown() => DirectoryHelper.DeleteDirectory(workingDir); @@ -93,7 +93,7 @@ public void ShouldCreateAssemblyInfoFilesAtPathWhenNotExistsAndEnsureAssemblyInf [TestCase("vb")] public void ShouldNotCreateAssemblyInfoFileWhenNotExistsAndNotEnsureAssemblyInfo(string fileExtension) { - var assemblyInfoFile = "VersionAssemblyInfo." + fileExtension; + var assemblyInfoFile = "NoVersionAssemblyInfo." + fileExtension; var fullPath = PathHelper.Combine(workingDir, assemblyInfoFile); var variables = this.variableProvider.GetVariablesFor( SemanticVersion.Parse("1.0.0", RegexPatterns.Configuration.DefaultTagPrefixPattern), EmptyConfigurationBuilder.New.Build(), 0 diff --git a/src/GitVersion.Output.Tests/Output/WixFileTests.cs b/src/GitVersion.Output.Tests/Output/WixFileTests.cs index 4d41fec15b..ebd91284f2 100644 --- a/src/GitVersion.Output.Tests/Output/WixFileTests.cs +++ b/src/GitVersion.Output.Tests/Output/WixFileTests.cs @@ -95,6 +95,10 @@ public void UpdateWixVersionFileWhenFileAlreadyExists() // fake an already existing file var file = PathHelper.Combine(workingDir, WixVersionFileUpdater.WixVersionFileName); + if (!fileSystem.DirectoryExists(workingDir)) + { + fileSystem.CreateDirectory(workingDir); + } fileSystem.WriteAllText(file, new('x', 1024 * 1024)); wixVersionFileUpdater.Execute(versionVariables, new(workingDir)); diff --git a/src/GitVersion.Output/WixUpdater/WixVersionFileUpdater.cs b/src/GitVersion.Output/WixUpdater/WixVersionFileUpdater.cs index 3d2dfe0104..4f76e347ac 100644 --- a/src/GitVersion.Output/WixUpdater/WixVersionFileUpdater.cs +++ b/src/GitVersion.Output/WixUpdater/WixVersionFileUpdater.cs @@ -25,7 +25,15 @@ public void Execute(GitVersionVariables variables, WixVersionContext context) var root = doc.DocumentElement; doc.InsertBefore(xmlDecl, root); - this.fileSystem.Delete(this.wixVersionFile); + if (this.fileSystem.Exists(this.wixVersionFile)) + { + this.fileSystem.Delete(this.wixVersionFile); + } + + if (!this.fileSystem.DirectoryExists(context.WorkingDirectory)) + { + this.fileSystem.CreateDirectory(context.WorkingDirectory); + } using var fs = this.fileSystem.OpenWrite(this.wixVersionFile); doc.Save(fs); } diff --git a/src/GitVersion.sln.DotSettings b/src/GitVersion.sln.DotSettings index 9d9eae6664..970fd59ec8 100644 --- a/src/GitVersion.sln.DotSettings +++ b/src/GitVersion.sln.DotSettings @@ -707,16 +707,11 @@ II.2.12 <HandlesEvent /> True True True - - - True + True False - - - - - <data /> + <data /> <data><IncludeFilters /><ExcludeFilters /></data> True True - True + True + True From 62f782fa39603f0a32c304889eaa6b0df19cc1ca Mon Sep 17 00:00:00 2001 From: Artur Stolear Date: Wed, 27 Nov 2024 05:28:23 +0100 Subject: [PATCH 33/37] Fix repo setup logic in DynamicRepositoryTests code cleanup --- .../Core/DynamicRepositoryTests.cs | 31 ++++--------------- 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/src/GitVersion.Core.Tests/Core/DynamicRepositoryTests.cs b/src/GitVersion.Core.Tests/Core/DynamicRepositoryTests.cs index ff6db85e6e..3a97ddbe3b 100644 --- a/src/GitVersion.Core.Tests/Core/DynamicRepositoryTests.cs +++ b/src/GitVersion.Core.Tests/Core/DynamicRepositoryTests.cs @@ -10,39 +10,20 @@ public class DynamicRepositoryTests : TestBase { private string? workDirectory; - private static void ClearReadOnly(DirectoryInfo parentDirectory) - { - parentDirectory.Attributes = FileAttributes.Normal; - foreach (var fi in parentDirectory.GetFiles()) - { - fi.Attributes = FileAttributes.Normal; - } - foreach (var di in parentDirectory.GetDirectories()) - { - ClearReadOnly(di); - } - } - [SetUp] - public void CreateTemporaryRepository() + public void SetUp() { - // Note: we can't use guid because paths will be too long + // // Note: we can't use guid because paths will be too long this.workDirectory = PathHelper.Combine(Path.GetTempPath(), "GV"); - // Clean directory upfront, some build agents are having troubles - if (Directory.Exists(this.workDirectory)) + if (!Directory.Exists(this.workDirectory)) { - var di = new DirectoryInfo(this.workDirectory); - ClearReadOnly(di); - - Directory.Delete(this.workDirectory, true); + Directory.CreateDirectory(this.workDirectory); } - - Directory.CreateDirectory(this.workDirectory); } [TearDown] - public void Cleanup() + public void TearDown() { } @@ -64,7 +45,7 @@ public void FindsVersionInDynamicRepo(string name, string url, string targetBran TargetBranch = targetBranch, CommitId = commitId }, - Settings = { NoFetch = false }, + Settings = { NoFetch = false, NoCache = true }, WorkingDirectory = workingDirectory }; var options = Options.Create(gitVersionOptions); From 5147e957b93a1a1dfce8c45a7f4a9bfd28d19854 Mon Sep 17 00:00:00 2001 From: Artur Stolear Date: Wed, 27 Nov 2024 08:52:30 +0100 Subject: [PATCH 34/37] Refactor file system operations to use IFileSystem interface Replaced direct file and directory operations with IFileSystem methods. This change standardizes file system interactions and simplifies dependency injection across the codebase. --- .../ArgumentParserTests.cs | 7 +++-- src/GitVersion.App/ArgumentParser.cs | 15 ++++++--- src/GitVersion.App/GitVersionExecutor.cs | 4 ++- .../ConfigurationProvider.cs | 2 +- .../Core/DynamicRepositoryTests.cs | 18 +++-------- .../Core/GitVersionExecutorTests.cs | 12 +++++-- .../Core/Abstractions/IFileSystem.cs | 4 ++- src/GitVersion.Core/Core/FileSystem.cs | 18 ++++++----- src/GitVersion.Core/Core/GitPreparer.cs | 4 ++- .../Extensions/ConfigurationExtensions.cs | 8 ++--- src/GitVersion.Core/PublicAPI.Unshipped.txt | 2 ++ .../Caching/GitVersionCacheKeyFactory.cs | 6 ++-- .../GitVersionTaskExecutor.cs | 24 +++++++++++++- src/GitVersion.MsBuild/Helpers/FileHelper.cs | 31 +++---------------- .../Output/GitVersionInfoGeneratorTests.cs | 30 +++++++++--------- 15 files changed, 102 insertions(+), 83 deletions(-) diff --git a/src/GitVersion.App.Tests/ArgumentParserTests.cs b/src/GitVersion.App.Tests/ArgumentParserTests.cs index b8650499c8..6569742bb3 100644 --- a/src/GitVersion.App.Tests/ArgumentParserTests.cs +++ b/src/GitVersion.App.Tests/ArgumentParserTests.cs @@ -12,6 +12,7 @@ public class ArgumentParserTests : TestBase { private IEnvironment environment; private IArgumentParser argumentParser; + private IFileSystem fileSystem; [SetUp] public void SetUp() @@ -23,6 +24,7 @@ public void SetUp() }); this.environment = sp.GetRequiredService(); this.argumentParser = sp.GetRequiredService(); + this.fileSystem = sp.GetRequiredService(); } [Test] @@ -337,7 +339,8 @@ public void UpdateAssemblyInfoWithMultipleFilenamesMatchingGlobbing() using var file2 = File.Create(assemblyFile2); var subdir = PathHelper.Combine(repo.RepositoryPath, "subdir"); - Directory.CreateDirectory(subdir); + + this.fileSystem.CreateDirectory(subdir); var assemblyFile3 = PathHelper.Combine(subdir, "LocalAssemblyInfo.cs"); using var file3 = File.Create(assemblyFile3); @@ -358,7 +361,7 @@ public void UpdateAssemblyInfoWithRelativeFilename() using var file = File.Create(assemblyFile); var targetPath = PathHelper.Combine(repo.RepositoryPath, "subdir1", "subdir2"); - Directory.CreateDirectory(targetPath); + this.fileSystem.CreateDirectory(targetPath); var arguments = this.argumentParser.ParseArguments($"-targetpath {targetPath} -updateAssemblyInfo ..\\..\\CommonAssemblyInfo.cs"); arguments.UpdateAssemblyInfo.ShouldBe(true); diff --git a/src/GitVersion.App/ArgumentParser.cs b/src/GitVersion.App/ArgumentParser.cs index dc16d9d7ca..11f4a4ac37 100644 --- a/src/GitVersion.App/ArgumentParser.cs +++ b/src/GitVersion.App/ArgumentParser.cs @@ -6,10 +6,15 @@ namespace GitVersion; -internal class ArgumentParser(IEnvironment environment, ICurrentBuildAgent buildAgent, IConsole console, IGlobbingResolver globbingResolver) +internal class ArgumentParser(IEnvironment environment, + IFileSystem fileSystem, + ICurrentBuildAgent buildAgent, + IConsole console, + IGlobbingResolver globbingResolver) : IArgumentParser { private readonly IEnvironment environment = environment.NotNull(); + private readonly IFileSystem fileSystem = fileSystem.NotNull(); private readonly ICurrentBuildAgent buildAgent = buildAgent.NotNull(); private readonly IConsole console = console.NotNull(); private readonly IGlobbingResolver globbingResolver = globbingResolver.NotNull(); @@ -97,19 +102,19 @@ public Arguments ParseArguments(string[] commandLineArguments) return arguments; } - private static void ValidateConfigurationFile(Arguments arguments) + private void ValidateConfigurationFile(Arguments arguments) { if (arguments.ConfigurationFile.IsNullOrWhiteSpace()) return; if (Path.IsPathRooted(arguments.ConfigurationFile)) { - if (!File.Exists(arguments.ConfigurationFile)) throw new WarningException($"Could not find config file at '{arguments.ConfigurationFile}'"); + if (!this.fileSystem.Exists(arguments.ConfigurationFile)) throw new WarningException($"Could not find config file at '{arguments.ConfigurationFile}'"); arguments.ConfigurationFile = Path.GetFullPath(arguments.ConfigurationFile); } else { var configFilePath = Path.GetFullPath(PathHelper.Combine(arguments.TargetPath, arguments.ConfigurationFile)); - if (!File.Exists(configFilePath)) throw new WarningException($"Could not find config file at '{configFilePath}'"); + if (!this.fileSystem.Exists(configFilePath)) throw new WarningException($"Could not find config file at '{configFilePath}'"); arguments.ConfigurationFile = configFilePath; } } @@ -161,7 +166,7 @@ private void ParseTargetPath(Arguments arguments, string? name, IReadOnlyList this.log.Info(logMessage)); } - if (!Directory.Exists(workingDirectory)) + if (!this.fileSystem.DirectoryExists(workingDirectory)) { this.log.Warning($"The working directory '{workingDirectory}' does not exist."); } diff --git a/src/GitVersion.Configuration/ConfigurationProvider.cs b/src/GitVersion.Configuration/ConfigurationProvider.cs index daf2fc1a28..cf1a89a74f 100644 --- a/src/GitVersion.Configuration/ConfigurationProvider.cs +++ b/src/GitVersion.Configuration/ConfigurationProvider.cs @@ -21,7 +21,7 @@ public IGitVersionConfiguration Provide(IReadOnlyDictionary? ov { var gitVersionOptions = this.options.Value; var workingDirectory = gitVersionOptions.WorkingDirectory; - var projectRootDirectory = workingDirectory.FindGitDir()?.WorkingTreeDirectory; + var projectRootDirectory = this.fileSystem.FindGitDir(workingDirectory)?.WorkingTreeDirectory; var configurationFile = this.configFileLocator.GetConfigurationFile(workingDirectory) ?? this.configFileLocator.GetConfigurationFile(projectRootDirectory); diff --git a/src/GitVersion.Core.Tests/Core/DynamicRepositoryTests.cs b/src/GitVersion.Core.Tests/Core/DynamicRepositoryTests.cs index 3a97ddbe3b..9fe51feda9 100644 --- a/src/GitVersion.Core.Tests/Core/DynamicRepositoryTests.cs +++ b/src/GitVersion.Core.Tests/Core/DynamicRepositoryTests.cs @@ -11,16 +11,7 @@ public class DynamicRepositoryTests : TestBase private string? workDirectory; [SetUp] - public void SetUp() - { - // // Note: we can't use guid because paths will be too long - this.workDirectory = PathHelper.Combine(Path.GetTempPath(), "GV"); - - if (!Directory.Exists(this.workDirectory)) - { - Directory.CreateDirectory(this.workDirectory); - } - } + public void SetUp() => this.workDirectory = PathHelper.Combine(Path.GetTempPath(), "GV"); [TearDown] public void TearDown() @@ -50,9 +41,6 @@ public void FindsVersionInDynamicRepo(string name, string url, string targetBran }; var options = Options.Create(gitVersionOptions); - Directory.CreateDirectory(dynamicDirectory); - Directory.CreateDirectory(workingDirectory); - var sp = ConfigureServices(services => services.AddSingleton(options)); sp.DiscoverRepository(); @@ -60,6 +48,10 @@ public void FindsVersionInDynamicRepo(string name, string url, string targetBran var gitPreparer = sp.GetRequiredService(); gitPreparer.Prepare(); + var fileSystem = sp.GetRequiredService(); + fileSystem.CreateDirectory(dynamicDirectory); + fileSystem.CreateDirectory(workingDirectory); + var gitVersionCalculator = sp.GetRequiredService(); var versionVariables = gitVersionCalculator.CalculateVersionVariables(); diff --git a/src/GitVersion.Core.Tests/Core/GitVersionExecutorTests.cs b/src/GitVersion.Core.Tests/Core/GitVersionExecutorTests.cs index ebd81f0957..2fea817d8f 100644 --- a/src/GitVersion.Core.Tests/Core/GitVersionExecutorTests.cs +++ b/src/GitVersion.Core.Tests/Core/GitVersionExecutorTests.cs @@ -67,7 +67,7 @@ public void CacheKeyForWorktree() { using var fixture = new EmptyRepositoryFixture(); fixture.Repository.MakeACommit(); - var worktreePath = PathHelper.Combine(Directory.GetParent(fixture.RepositoryPath)?.FullName, Guid.NewGuid().ToString()); + var worktreePath = GetWorktreePath(fixture); try { // create a branch and a new worktree for it @@ -395,7 +395,7 @@ public void GetProjectRootDirectoryWorkingDirectoryWithWorktree() using var fixture = new EmptyRepositoryFixture(); fixture.Repository.MakeACommit(); - var worktreePath = PathHelper.Combine(Directory.GetParent(fixture.RepositoryPath)?.FullName, Guid.NewGuid().ToString()); + var worktreePath = GetWorktreePath(fixture); try { // create a branch and a new worktree for it @@ -451,7 +451,7 @@ public void GetDotGitDirectoryWorktree() using var fixture = new EmptyRepositoryFixture(); fixture.Repository.MakeACommit(); - var worktreePath = PathHelper.Combine(Directory.GetParent(fixture.RepositoryPath)?.FullName, Guid.NewGuid().ToString()); + var worktreePath = GetWorktreePath(fixture); try { // create a branch and a new worktree for it @@ -588,6 +588,12 @@ public void CalculateVersionVariables_ShallowFetch_ThrowException() exception?.Message.ShouldBe("Repository is a shallow clone. Git repositories must contain the full history. See https://gitversion.net/docs/reference/requirements#unshallow for more info."); } + private static string GetWorktreePath(EmptyRepositoryFixture fixture) + { + var worktreePath = PathHelper.Combine(Directory.GetParent(fixture.RepositoryPath)?.FullName, Guid.NewGuid().ToString()); + return worktreePath; + } + private IGitVersionCalculateTool GetGitVersionCalculator(GitVersionOptions gitVersionOptions, ILog? logger = null, IGitRepository? repository = null, IFileSystem? fs = null) { this.sp = GetServiceProvider(gitVersionOptions, logger, repository, fs); diff --git a/src/GitVersion.Core/Core/Abstractions/IFileSystem.cs b/src/GitVersion.Core/Core/Abstractions/IFileSystem.cs index 32e4646809..eadb410d9a 100644 --- a/src/GitVersion.Core/Core/Abstractions/IFileSystem.cs +++ b/src/GitVersion.Core/Core/Abstractions/IFileSystem.cs @@ -9,10 +9,12 @@ public interface IFileSystem string ReadAllText(string path); void WriteAllText(string? file, string fileContents); void WriteAllText(string? file, string fileContents, Encoding encoding); - IEnumerable DirectoryEnumerateFiles(string? directory, string searchPattern, SearchOption searchOption); Stream OpenWrite(string path); Stream OpenRead(string path); void CreateDirectory(string path); bool DirectoryExists(string path); + string[] GetFiles(string path); + string[] GetDirectories(string path); + IEnumerable DirectoryEnumerateFiles(string? directory, string searchPattern, SearchOption searchOption); long GetLastDirectoryWrite(string path); } diff --git a/src/GitVersion.Core/Core/FileSystem.cs b/src/GitVersion.Core/Core/FileSystem.cs index 50bd61f3a2..7da239b288 100644 --- a/src/GitVersion.Core/Core/FileSystem.cs +++ b/src/GitVersion.Core/Core/FileSystem.cs @@ -29,13 +29,6 @@ public void WriteAllText(string? file, string fileContents, Encoding encoding) File.WriteAllText(file, fileContents, encoding); } - public IEnumerable DirectoryEnumerateFiles(string? directory, string searchPattern, SearchOption searchOption) - { - ArgumentException.ThrowIfNullOrWhiteSpace(directory); - - return Directory.EnumerateFiles(directory, searchPattern, searchOption); - } - public Stream OpenWrite(string path) => File.OpenWrite(path); public Stream OpenRead(string path) => File.OpenRead(path); @@ -44,6 +37,17 @@ public IEnumerable DirectoryEnumerateFiles(string? directory, string sea public bool DirectoryExists(string path) => Directory.Exists(path); + public string[] GetFiles(string path) => Directory.GetFiles(path); + + public string[] GetDirectories(string path) => Directory.GetDirectories(path); + + public IEnumerable DirectoryEnumerateFiles(string? directory, string searchPattern, SearchOption searchOption) + { + ArgumentException.ThrowIfNullOrWhiteSpace(directory); + + return Directory.EnumerateFiles(directory, searchPattern, searchOption); + } + public long GetLastDirectoryWrite(string path) => new DirectoryInfo(path) .GetDirectories("*.*", SearchOption.AllDirectories) .Select(d => d.LastWriteTimeUtc) diff --git a/src/GitVersion.Core/Core/GitPreparer.cs b/src/GitVersion.Core/Core/GitPreparer.cs index e33d236d4d..e48aa1f8cc 100644 --- a/src/GitVersion.Core/Core/GitPreparer.cs +++ b/src/GitVersion.Core/Core/GitPreparer.cs @@ -10,6 +10,7 @@ namespace GitVersion; internal class GitPreparer( ILog log, + IFileSystem fileSystem, IEnvironment environment, ICurrentBuildAgent buildAgent, IOptions options, @@ -19,6 +20,7 @@ internal class GitPreparer( : IGitPreparer { private readonly ILog log = log.NotNull(); + private readonly IFileSystem fileSystem = fileSystem.NotNull(); private readonly IEnvironment environment = environment.NotNull(); private readonly IMutatingGitRepository repository = repository.NotNull(); private readonly IOptions options = options.NotNull(); @@ -112,7 +114,7 @@ private void CreateDynamicRepository(string? targetBranch) { var gitVersionOptions = this.options.Value; var authentication = gitVersionOptions.AuthenticationInfo; - if (!Directory.Exists(gitDirectory)) + if (!this.fileSystem.DirectoryExists(gitDirectory)) { CloneRepository(gitVersionOptions.RepositoryInfo.TargetUrl, gitDirectory, authentication); } diff --git a/src/GitVersion.Core/Extensions/ConfigurationExtensions.cs b/src/GitVersion.Core/Extensions/ConfigurationExtensions.cs index caa4032bdd..b10b2b9ae8 100644 --- a/src/GitVersion.Core/Extensions/ConfigurationExtensions.cs +++ b/src/GitVersion.Core/Extensions/ConfigurationExtensions.cs @@ -123,24 +123,24 @@ public static bool IsReleaseBranch(this IGitVersionConfiguration configuration, return label; } - public static (string GitDirectory, string WorkingTreeDirectory)? FindGitDir(this string path) + public static (string GitDirectory, string WorkingTreeDirectory)? FindGitDir(this IFileSystem fileSystem, string path) { string? startingDir = path; while (startingDir is not null) { var dirOrFilePath = PathHelper.Combine(startingDir, ".git"); - if (Directory.Exists(dirOrFilePath)) + if (fileSystem.DirectoryExists(dirOrFilePath)) { return (dirOrFilePath, Path.GetDirectoryName(dirOrFilePath)!); } - if (File.Exists(dirOrFilePath)) + if (fileSystem.Exists(dirOrFilePath)) { string? relativeGitDirPath = ReadGitDirFromFile(dirOrFilePath); if (!string.IsNullOrWhiteSpace(relativeGitDirPath)) { var fullGitDirPath = Path.GetFullPath(PathHelper.Combine(startingDir, relativeGitDirPath)); - if (Directory.Exists(fullGitDirPath)) + if (fileSystem.DirectoryExists(fullGitDirPath)) { return (fullGitDirPath, Path.GetDirectoryName(dirOrFilePath)!); } diff --git a/src/GitVersion.Core/PublicAPI.Unshipped.txt b/src/GitVersion.Core/PublicAPI.Unshipped.txt index 7dc5c58110..d86fbfefd4 100644 --- a/src/GitVersion.Core/PublicAPI.Unshipped.txt +++ b/src/GitVersion.Core/PublicAPI.Unshipped.txt @@ -1 +1,3 @@ #nullable enable +GitVersion.IFileSystem.GetDirectories(string! path) -> string![]! +GitVersion.IFileSystem.GetFiles(string! path) -> string![]! diff --git a/src/GitVersion.Core/VersionCalculation/Caching/GitVersionCacheKeyFactory.cs b/src/GitVersion.Core/VersionCalculation/Caching/GitVersionCacheKeyFactory.cs index c24047a798..70609d9250 100644 --- a/src/GitVersion.Core/VersionCalculation/Caching/GitVersionCacheKeyFactory.cs +++ b/src/GitVersion.Core/VersionCalculation/Caching/GitVersionCacheKeyFactory.cs @@ -57,7 +57,7 @@ private List CalculateDirectoryContents(string root) // examined for files. var dirs = new Stack(); - if (!Directory.Exists(root)) + if (!this.fileSystem.DirectoryExists(root)) { throw new DirectoryNotFoundException($"Root directory does not exist: {root}"); } @@ -74,7 +74,7 @@ private List CalculateDirectoryContents(string root) string[] subDirs; try { - subDirs = Directory.GetDirectories(currentDir); + subDirs = this.fileSystem.GetDirectories(currentDir); } // An UnauthorizedAccessException exception will be thrown if we do not have // discovery permission on a folder or file. It may or may not be acceptable @@ -99,7 +99,7 @@ private List CalculateDirectoryContents(string root) string[] files; try { - files = Directory.GetFiles(currentDir); + files = this.fileSystem.GetFiles(currentDir); } catch (UnauthorizedAccessException e) { diff --git a/src/GitVersion.MsBuild/GitVersionTaskExecutor.cs b/src/GitVersion.MsBuild/GitVersionTaskExecutor.cs index 9252d5a6b5..ccff9b9549 100644 --- a/src/GitVersion.MsBuild/GitVersionTaskExecutor.cs +++ b/src/GitVersion.MsBuild/GitVersionTaskExecutor.cs @@ -34,7 +34,7 @@ public void GetVersion(GetVersion task) public void UpdateAssemblyInfo(UpdateAssemblyInfo task) { var versionVariables = GitVersionVariables(task); - FileHelper.DeleteTempFiles(); + DeleteTempFiles(); FileHelper.CheckForInvalidFiles(task.CompileFiles, task.ProjectFile); if (!string.IsNullOrEmpty(task.IntermediateOutputPath)) @@ -100,5 +100,27 @@ public void WriteVersionInfoToBuildLog(WriteVersionInfoToBuildLog task) gitVersionOutputTool.OutputVariables(versionVariables, configuration.UpdateBuildNumber); } + private void DeleteTempFiles() + { + if (!this.fileSystem.DirectoryExists(FileHelper.TempPath)) + { + return; + } + + foreach (var file in this.fileSystem.GetFiles(FileHelper.TempPath)) + { + if (File.GetLastWriteTime(file) >= DateTime.Now.AddDays(-1)) + continue; + try + { + File.Delete(file); + } + catch (UnauthorizedAccessException) + { + //ignore contention + } + } + } + private GitVersionVariables GitVersionVariables(GitVersionTaskBase task) => serializer.FromFile(task.VersionFile); } diff --git a/src/GitVersion.MsBuild/Helpers/FileHelper.cs b/src/GitVersion.MsBuild/Helpers/FileHelper.cs index e8b478ee42..e8a4479af6 100644 --- a/src/GitVersion.MsBuild/Helpers/FileHelper.cs +++ b/src/GitVersion.MsBuild/Helpers/FileHelper.cs @@ -1,8 +1,9 @@ using System.Text.RegularExpressions; -using GitVersion.Core; using GitVersion.Helpers; using Microsoft.Build.Framework; +using static GitVersion.Core.RegexPatterns.AssemblyVersion; + namespace GitVersion.MsBuild; internal static class FileHelper @@ -16,28 +17,6 @@ private static string MakeAndGetTempPath() return tempPath; } - public static void DeleteTempFiles() - { - if (!Directory.Exists(TempPath)) - { - return; - } - - foreach (var file in Directory.GetFiles(TempPath)) - { - if (File.GetLastWriteTime(file) >= DateTime.Now.AddDays(-1)) - continue; - try - { - File.Delete(file); - } - catch (UnauthorizedAccessException) - { - //ignore contention - } - } - } - public static string GetFileExtension(string language) => language switch { "C#" => "cs", @@ -69,9 +48,9 @@ private static bool FileContainsVersionAttribute(string compileFile, string proj var (attributeRegex, triviaRegex) = compileFileExtension switch { - ".cs" => (RegexPatterns.AssemblyVersion.CSharp.AttributeRegex, RegexPatterns.AssemblyVersion.CSharp.TriviaRegex), - ".fs" => (RegexPatterns.AssemblyVersion.FSharp.AttributeRegex, RegexPatterns.AssemblyVersion.FSharp.TriviaRegex), - ".vb" => (RegexPatterns.AssemblyVersion.VisualBasic.AttributeRegex, RegexPatterns.AssemblyVersion.VisualBasic.TriviaRegex), + ".cs" => (CSharp.AttributeRegex, CSharp.TriviaRegex), + ".fs" => (FSharp.AttributeRegex, FSharp.TriviaRegex), + ".vb" => (VisualBasic.AttributeRegex, VisualBasic.TriviaRegex), _ => throw new WarningException("File with name containing AssemblyInfo could not be checked for assembly version attributes which conflict with the attributes generated by GitVersion " + compileFile) }; diff --git a/src/GitVersion.Output.Tests/Output/GitVersionInfoGeneratorTests.cs b/src/GitVersion.Output.Tests/Output/GitVersionInfoGeneratorTests.cs index 56ac52df1b..284f3d6b65 100644 --- a/src/GitVersion.Output.Tests/Output/GitVersionInfoGeneratorTests.cs +++ b/src/GitVersion.Output.Tests/Output/GitVersionInfoGeneratorTests.cs @@ -19,12 +19,6 @@ public class GitVersionInfoGeneratorTests : TestBase [TestCase("vb")] public void ShouldCreateFile(string fileExtension) { - var directory = PathHelper.Combine(PathHelper.GetTempPath(), "GitVersionInfoGeneratorTests", Guid.NewGuid().ToString()); - if (!Directory.Exists(directory)) - Directory.CreateDirectory(directory); - var fileName = "GitVersionInformation.g." + fileExtension; - var fullPath = PathHelper.Combine(directory, fileName); - var semanticVersion = new SemanticVersion { Major = 1, @@ -32,14 +26,20 @@ public void ShouldCreateFile(string fileExtension) Patch = 3, PreReleaseTag = "unstable4", BuildMetaData = new("versionSourceSha", 5, - "feature1", "commitSha", "commitShortSha", DateTimeOffset.Parse("2014-03-06 23:59:59Z"), 0) + "feature1", "commitSha", "commitShortSha", DateTimeOffset.Parse("2014-03-06 23:59:59Z"), 0) }; var sp = ConfigureServices(); var fileSystem = sp.GetRequiredService(); - var variableProvider = sp.GetRequiredService(); + var directory = PathHelper.Combine(PathHelper.GetTempPath(), "GitVersionInfoGeneratorTests", Guid.NewGuid().ToString()); + if (!fileSystem.DirectoryExists(directory)) + fileSystem.CreateDirectory(directory); + var fileName = "GitVersionInformation.g." + fileExtension; + var fullPath = PathHelper.Combine(directory, fileName); + + var variableProvider = sp.GetRequiredService(); var variables = variableProvider.GetVariablesFor(semanticVersion, EmptyConfigurationBuilder.New.Build(), 0); using var generator = sp.GetRequiredService(); @@ -60,12 +60,6 @@ public void ShouldProperlyOutputNamespaceDeclaration(string fileExtension) { const string targetNamespace = "My.Custom.Namespace"; - var directory = PathHelper.Combine(PathHelper.GetTempPath(), "GitVersionInfoGeneratorTests", Guid.NewGuid().ToString()); - if (!Directory.Exists(directory)) - Directory.CreateDirectory(directory); - var fileName = "GitVersionInformation.g." + fileExtension; - var fullPath = PathHelper.Combine(directory, fileName); - var semanticVersion = new SemanticVersion { Major = 1, @@ -79,8 +73,14 @@ public void ShouldProperlyOutputNamespaceDeclaration(string fileExtension) var sp = ConfigureServices(); var fileSystem = sp.GetRequiredService(); - var variableProvider = sp.GetRequiredService(); + var directory = PathHelper.Combine(PathHelper.GetTempPath(), "GitVersionInfoGeneratorTests", Guid.NewGuid().ToString()); + if (!fileSystem.DirectoryExists(directory)) + fileSystem.CreateDirectory(directory); + var fileName = "GitVersionInformation.g." + fileExtension; + var fullPath = PathHelper.Combine(directory, fileName); + + var variableProvider = sp.GetRequiredService(); var variables = variableProvider.GetVariablesFor(semanticVersion, EmptyConfigurationBuilder.New.Build(), 0); using var generator = sp.GetRequiredService(); From 012c377970db3d9fc144b36e04c8ce3828564dc9 Mon Sep 17 00:00:00 2001 From: Artur Stolear Date: Wed, 27 Nov 2024 17:15:31 +0100 Subject: [PATCH 35/37] Refactor MakeAndGetTempPath to use expression-bodied member Simplified the MakeAndGetTempPath method by converting it to an expression-bodied member. --- .../Core/Abstractions/IFileSystem.cs | 1 + src/GitVersion.Core/Core/FileSystem.cs | 2 ++ src/GitVersion.Core/PublicAPI.Unshipped.txt | 1 + .../Caching/GitVersionCacheKeyFactory.cs | 4 ++-- .../GitVersionTaskExecutor.cs | 17 +++++++++++++---- src/GitVersion.MsBuild/Helpers/FileHelper.cs | 7 +------ 6 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/GitVersion.Core/Core/Abstractions/IFileSystem.cs b/src/GitVersion.Core/Core/Abstractions/IFileSystem.cs index eadb410d9a..7678d8c373 100644 --- a/src/GitVersion.Core/Core/Abstractions/IFileSystem.cs +++ b/src/GitVersion.Core/Core/Abstractions/IFileSystem.cs @@ -17,4 +17,5 @@ public interface IFileSystem string[] GetDirectories(string path); IEnumerable DirectoryEnumerateFiles(string? directory, string searchPattern, SearchOption searchOption); long GetLastDirectoryWrite(string path); + long GetLastWriteTime(string path); } diff --git a/src/GitVersion.Core/Core/FileSystem.cs b/src/GitVersion.Core/Core/FileSystem.cs index 7da239b288..1187b06528 100644 --- a/src/GitVersion.Core/Core/FileSystem.cs +++ b/src/GitVersion.Core/Core/FileSystem.cs @@ -48,6 +48,8 @@ public IEnumerable DirectoryEnumerateFiles(string? directory, string sea return Directory.EnumerateFiles(directory, searchPattern, searchOption); } + public long GetLastWriteTime(string path) => File.GetLastWriteTime(path).Ticks; + public long GetLastDirectoryWrite(string path) => new DirectoryInfo(path) .GetDirectories("*.*", SearchOption.AllDirectories) .Select(d => d.LastWriteTimeUtc) diff --git a/src/GitVersion.Core/PublicAPI.Unshipped.txt b/src/GitVersion.Core/PublicAPI.Unshipped.txt index d86fbfefd4..b5c8a9949f 100644 --- a/src/GitVersion.Core/PublicAPI.Unshipped.txt +++ b/src/GitVersion.Core/PublicAPI.Unshipped.txt @@ -1,3 +1,4 @@ #nullable enable GitVersion.IFileSystem.GetDirectories(string! path) -> string![]! GitVersion.IFileSystem.GetFiles(string! path) -> string![]! +GitVersion.IFileSystem.GetLastWriteTime(string! path) -> long diff --git a/src/GitVersion.Core/VersionCalculation/Caching/GitVersionCacheKeyFactory.cs b/src/GitVersion.Core/VersionCalculation/Caching/GitVersionCacheKeyFactory.cs index 70609d9250..c91350e733 100644 --- a/src/GitVersion.Core/VersionCalculation/Caching/GitVersionCacheKeyFactory.cs +++ b/src/GitVersion.Core/VersionCalculation/Caching/GitVersionCacheKeyFactory.cs @@ -116,8 +116,8 @@ private List CalculateDirectoryContents(string root) { try { - var fi = new FileInfo(file); - result.Add(fi.Name); + if (!this.fileSystem.Exists(file)) continue; + result.Add(Path.GetFileName(file)); result.Add(this.fileSystem.ReadAllText(file)); } catch (IOException e) diff --git a/src/GitVersion.MsBuild/GitVersionTaskExecutor.cs b/src/GitVersion.MsBuild/GitVersionTaskExecutor.cs index ccff9b9549..d51d364d95 100644 --- a/src/GitVersion.MsBuild/GitVersionTaskExecutor.cs +++ b/src/GitVersion.MsBuild/GitVersionTaskExecutor.cs @@ -46,6 +46,10 @@ public void UpdateAssemblyInfo(UpdateAssemblyInfo task) var fileWriteInfo = task.IntermediateOutputPath.GetFileWriteInfo(task.Language, task.ProjectFile, "AssemblyInfo"); task.AssemblyInfoTempFilePath = PathHelper.Combine(fileWriteInfo.WorkingDirectory, fileWriteInfo.FileName); + if (!this.fileSystem.DirectoryExists(fileWriteInfo.WorkingDirectory)) + { + this.fileSystem.CreateDirectory(fileWriteInfo.WorkingDirectory); + } var gitVersionOptions = this.options.Value; gitVersionOptions.WorkingDirectory = fileWriteInfo.WorkingDirectory; gitVersionOptions.AssemblySettingsInfo.UpdateAssemblyInfo = true; @@ -68,6 +72,10 @@ public void GenerateGitVersionInformation(GenerateGitVersionInformation task) var fileWriteInfo = task.IntermediateOutputPath.GetFileWriteInfo(task.Language, task.ProjectFile, "GitVersionInformation"); task.GitVersionInformationFilePath = PathHelper.Combine(fileWriteInfo.WorkingDirectory, fileWriteInfo.FileName); + if (!this.fileSystem.DirectoryExists(fileWriteInfo.WorkingDirectory)) + { + this.fileSystem.CreateDirectory(fileWriteInfo.WorkingDirectory); + } var gitVersionOptions = this.options.Value; gitVersionOptions.WorkingDirectory = fileWriteInfo.WorkingDirectory; var targetNamespace = GetTargetNamespace(task); @@ -102,18 +110,19 @@ public void WriteVersionInfoToBuildLog(WriteVersionInfoToBuildLog task) private void DeleteTempFiles() { - if (!this.fileSystem.DirectoryExists(FileHelper.TempPath)) + var tempPath = FileHelper.TempPath; + if (!this.fileSystem.DirectoryExists(tempPath)) { return; } - foreach (var file in this.fileSystem.GetFiles(FileHelper.TempPath)) + foreach (var file in this.fileSystem.GetFiles(tempPath)) { - if (File.GetLastWriteTime(file) >= DateTime.Now.AddDays(-1)) + if (this.fileSystem.GetLastWriteTime(file) >= DateTime.Now.AddDays(-1).Ticks) continue; try { - File.Delete(file); + this.fileSystem.Delete(file); } catch (UnauthorizedAccessException) { diff --git a/src/GitVersion.MsBuild/Helpers/FileHelper.cs b/src/GitVersion.MsBuild/Helpers/FileHelper.cs index e8a4479af6..ce3d1e9da7 100644 --- a/src/GitVersion.MsBuild/Helpers/FileHelper.cs +++ b/src/GitVersion.MsBuild/Helpers/FileHelper.cs @@ -10,12 +10,7 @@ internal static class FileHelper { public static readonly string TempPath = MakeAndGetTempPath(); - private static string MakeAndGetTempPath() - { - var tempPath = PathHelper.Combine(Path.GetTempPath(), "GitVersionTask"); - Directory.CreateDirectory(tempPath); - return tempPath; - } + private static string MakeAndGetTempPath() => PathHelper.Combine(Path.GetTempPath(), "GitVersionTask"); public static string GetFileExtension(string language) => language switch { From e2734f820549da51eba84def3d2c420a12bca9e0 Mon Sep 17 00:00:00 2001 From: Artur Stolear Date: Mon, 9 Dec 2024 13:39:10 +0100 Subject: [PATCH 36/37] fixing some warnings --- src/GitVersion.App/ArgumentParser.cs | 2 +- src/GitVersion.Core/Core/GitPreparer.cs | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/GitVersion.App/ArgumentParser.cs b/src/GitVersion.App/ArgumentParser.cs index 11f4a4ac37..7e273f99da 100644 --- a/src/GitVersion.App/ArgumentParser.cs +++ b/src/GitVersion.App/ArgumentParser.cs @@ -166,7 +166,7 @@ private void ParseTargetPath(Arguments arguments, string? name, IReadOnlyList Date: Mon, 9 Dec 2024 14:23:47 +0100 Subject: [PATCH 37/37] update shipped API --- src/GitVersion.Core/PublicAPI.Shipped.txt | 3 +++ src/GitVersion.Core/PublicAPI.Unshipped.txt | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/GitVersion.Core/PublicAPI.Shipped.txt b/src/GitVersion.Core/PublicAPI.Shipped.txt index c7172416bd..d3f010c444 100644 --- a/src/GitVersion.Core/PublicAPI.Shipped.txt +++ b/src/GitVersion.Core/PublicAPI.Shipped.txt @@ -361,7 +361,10 @@ GitVersion.IFileSystem.Delete(string! path) -> void GitVersion.IFileSystem.DirectoryEnumerateFiles(string? directory, string! searchPattern, System.IO.SearchOption searchOption) -> System.Collections.Generic.IEnumerable! GitVersion.IFileSystem.DirectoryExists(string! path) -> bool GitVersion.IFileSystem.Exists(string! file) -> bool +GitVersion.IFileSystem.GetDirectories(string! path) -> string![]! +GitVersion.IFileSystem.GetFiles(string! path) -> string![]! GitVersion.IFileSystem.GetLastDirectoryWrite(string! path) -> long +GitVersion.IFileSystem.GetLastWriteTime(string! path) -> long GitVersion.IFileSystem.Move(string! from, string! to) -> void GitVersion.IFileSystem.OpenRead(string! path) -> System.IO.Stream! GitVersion.IFileSystem.OpenWrite(string! path) -> System.IO.Stream! diff --git a/src/GitVersion.Core/PublicAPI.Unshipped.txt b/src/GitVersion.Core/PublicAPI.Unshipped.txt index b5c8a9949f..7dc5c58110 100644 --- a/src/GitVersion.Core/PublicAPI.Unshipped.txt +++ b/src/GitVersion.Core/PublicAPI.Unshipped.txt @@ -1,4 +1 @@ #nullable enable -GitVersion.IFileSystem.GetDirectories(string! path) -> string![]! -GitVersion.IFileSystem.GetFiles(string! path) -> string![]! -GitVersion.IFileSystem.GetLastWriteTime(string! path) -> long