From 1aedc4f996331e6868229e8ee38509f0ee495bd6 Mon Sep 17 00:00:00 2001 From: Vsevolod Kukol Date: Wed, 20 May 2026 22:08:02 +0200 Subject: [PATCH 1/3] Replace GitVersion with Nerdbank.GitVersioning Adopt NBGV so local and CI builds share a single, git-history-driven version computation, replacing the CI-only patch script introduced in #90. - Add version.json with baseline 1.1-preview, public-release refspecs (main, rel/*, PR merges), SemVer 2 package version, and disabled cloudBuild auto-variables. - Add Nerdbank.GitVersioning 3.9.50 PackageReference via Directory.Build.props (with VersionOverride so CosmosDBShell.Fuzzer still works without central package management) and a corresponding entry in Directory.Packages.props. - Replace gitversion.tool with nbgv in .config/dotnet-tools.json. - Delete GitVersion.yml. - Update GitHub Actions workflow and OneBranch pipeline to fetch full git history, restore .NET tools, compute the package version via nbgv get-version, and stop overriding /p:Version, /p:FileVersion, /p:InformationalVersion, /p:PackageVersion on build/publish/pack. --- .config/dotnet-tools.json | 6 +- .github/workflows/validate-and-package.yml | 61 ++++-------------- .pipelines/CosmosDB-Shell-Official.yml | 74 +++++++--------------- Directory.Build.props | 26 ++++---- Directory.Packages.props | 1 + GitVersion.yml | 21 ------ version.json | 19 ++++++ 7 files changed, 73 insertions(+), 135 deletions(-) delete mode 100644 GitVersion.yml create mode 100644 version.json diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index c4b83df..e7633c4 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -2,10 +2,10 @@ "version": 1, "isRoot": true, "tools": { - "gitversion.tool": { - "version": "6.0.5", + "nbgv": { + "version": "3.9.50", "commands": [ - "dotnet-gitversion" + "nbgv" ] } } diff --git a/.github/workflows/validate-and-package.yml b/.github/workflows/validate-and-package.yml index 1c2c484..efe0b5d 100644 --- a/.github/workflows/validate-and-package.yml +++ b/.github/workflows/validate-and-package.yml @@ -59,7 +59,9 @@ jobs: - name: Checkout uses: actions/checkout@v4 with: - # GitVersion needs full history to compute commit counts. + # Nerdbank.GitVersioning needs full history to walk back to the + # commit that last changed version.json (the baseline) so it can + # compute the patch as the git height since that commit. fetch-depth: 0 - name: Setup .NET SDK @@ -72,13 +74,13 @@ jobs: Directory.Packages.props **/*.csproj - - name: Restore GitVersion tool + - name: Restore .NET tools shell: pwsh run: | $ErrorActionPreference = 'Stop' dotnet tool restore if ($LASTEXITCODE -ne 0) { - throw "Failed to restore the local GitVersion tool." + throw "Failed to restore .NET local tools (nbgv)." } - name: Compute version properties @@ -87,43 +89,18 @@ jobs: run: | $ErrorActionPreference = 'Stop' - # Major.Minor come from GitVersion (`next-version` in - # GitVersion.yml). The patch is the number of commits since - # GitVersion.yml was last modified, computed directly from - # git so it is independent of any tags and so it resets to 0 - # whenever next-version is bumped. GitVersion's - # CommitsSinceVersionSource is not used because, with the - # TaggedCommit strategy disabled, it falls back to counting - # all commits in the repository. - $gitVersionJson = dotnet tool run dotnet-gitversion /output json /nofetch /nonormalize - if ($LASTEXITCODE -ne 0) { - throw "Failed to compute version metadata with dotnet-gitversion." - } - - $gv = $gitVersionJson | ConvertFrom-Json - - $configPath = Join-Path $env:GITHUB_WORKSPACE 'GitVersion.yml' - $configCommit = (git log -n 1 --format=%H -- $configPath).Trim() - if ([string]::IsNullOrWhiteSpace($configCommit)) { - throw "Could not determine the commit that last changed GitVersion.yml." + # Nerdbank.GitVersioning is wired in via PackageReference in + # Directory.Build.props, so dotnet build/publish/pack already + # produce versions matching version.json. We only need NBGV's + # NuGetPackageVersion here to drive artifact naming and the + # workflow step summary. + $packageVersion = (dotnet tool run nbgv get-version -v NuGetPackageVersion).Trim() + if ($LASTEXITCODE -ne 0 -or [string]::IsNullOrWhiteSpace($packageVersion)) { + throw "Failed to compute version metadata with nbgv." } - $commitsSinceConfig = [int](git rev-list --count "$configCommit..HEAD") - if ($commitsSinceConfig -gt 65535) { - throw "Commits since GitVersion.yml ($commitsSinceConfig) exceeds the maximum .NET assembly version segment value of 65535. Bump next-version in GitVersion.yml before generating assembly and file versions." - } - - $assemblyVersion = "$($gv.Major).$($gv.Minor).$commitsSinceConfig" - $packageVersion = "$assemblyVersion-preview" - $fileVersion = "$assemblyVersion.0" - $infoVersion = "$packageVersion+${{ github.sha }}" - - Write-Host "AssemblyVersion: $assemblyVersion" Write-Host "PackageVersion: $packageVersion" - "assembly_version=$assemblyVersion" >> $env:GITHUB_OUTPUT "package_version=$packageVersion" >> $env:GITHUB_OUTPUT - "file_version=$fileVersion" >> $env:GITHUB_OUTPUT - "informational_version=$infoVersion" >> $env:GITHUB_OUTPUT $branchName = "${{ github.ref_name }}" $branchLabel = $branchName.ToLowerInvariant() @@ -150,9 +127,6 @@ jobs: dotnet build CosmosDBShell.sln --configuration $env:BUILD_CONFIGURATION --no-restore - /p:Version=${{ steps.version.outputs.assembly_version }} - /p:FileVersion=${{ steps.version.outputs.file_version }} - /p:InformationalVersion=${{ steps.version.outputs.informational_version }} shell: pwsh - name: Test solution @@ -213,10 +187,7 @@ jobs: --configuration $env:BUILD_CONFIGURATION ` --no-restore ` -r $rid ` - --output "out/$rid" ` - /p:Version=${{ steps.version.outputs.assembly_version }} ` - /p:FileVersion=${{ steps.version.outputs.file_version }} ` - /p:InformationalVersion=${{ steps.version.outputs.informational_version }} + --output "out/$rid" if ($LASTEXITCODE -ne 0) { throw "RID publish failed for $rid with exit code $LASTEXITCODE." @@ -235,10 +206,6 @@ jobs: --configuration $env:BUILD_CONFIGURATION ` --no-restore ` --output out/nupkg ` - /p:PackageVersion=${{ steps.version.outputs.package_version }} ` - /p:Version=${{ steps.version.outputs.assembly_version }} ` - /p:FileVersion=${{ steps.version.outputs.file_version }} ` - /p:InformationalVersion=${{ steps.version.outputs.informational_version }} ` /p:ContinuousIntegrationBuild=true - name: Validate NuGet package set diff --git a/.pipelines/CosmosDB-Shell-Official.yml b/.pipelines/CosmosDB-Shell-Official.yml index 3ea02b4..e88dec7 100644 --- a/.pipelines/CosmosDB-Shell-Official.yml +++ b/.pipelines/CosmosDB-Shell-Official.yml @@ -71,10 +71,13 @@ extends: variables: # More settings at https://aka.ms/obpipelines/yaml/jobs ob_outputDirectory: '$(Build.SourcesDirectory)\out' # this directory is uploaded to pipeline artifacts, reddog and cloudvault. More info at https://aka.ms/obpipelines/artifacts ob_artifactBaseName: cosmos_shell_all # combined artifact with all RIDs for SDL scanning - # GitVersion needs full history to count commits. Using - # ob_git_fetchDepth lets OneBranch do the full clone in one shot - # instead of shallow-clone + --unshallow, which avoids a second - # fetch to github.com that the windows_build_container pool blocks. + # Nerdbank.GitVersioning needs full history to walk back to + # the commit that last changed version.json (the baseline) so + # it can compute the patch as the git height since that + # commit. Setting ob_git_fetchDepth: -1 makes OneBranch do the + # full clone in one shot instead of shallow-clone + + # --unshallow, avoiding a second fetch to github.com that the + # windows_build_container pool blocks. ob_git_fetchDepth: -1 OneES_SbomNugetSDLPath: out\nupkg # https://aka.ms/obpipelines/sdl @@ -97,52 +100,25 @@ extends: - script: dotnet tool restore --configfile "$(Build.SourcesDirectory)\\.pipelines\\nuget.config" displayName: "Dotnet Tools Restore" - # Major.Minor come from GitVersion (`next-version` in - # GitVersion.yml). The patch is the number of commits since - # GitVersion.yml was last modified, computed directly from - # git so it is independent of any tags and so it resets to - # 0 whenever next-version is bumped. GitVersion's - # CommitsSinceVersionSource is not used because, with the - # TaggedCommit strategy disabled, it falls back to counting - # all commits in the repository. + # Nerdbank.GitVersioning is wired in via PackageReference in + # Directory.Build.props, so dotnet build/publish/pack already + # produce versions matching version.json. We only need NBGV's + # NuGetPackageVersion here to drive the OneBranch build + # number and the zip filenames. - task: PowerShell@2 - displayName: "Compute version with GitVersion" + displayName: "Compute version with nbgv" inputs: targetType: inline pwsh: true script: | $ErrorActionPreference = 'Stop' - $gitVersionJson = dotnet tool run dotnet-gitversion /output json - - if ($LASTEXITCODE -ne 0) { - throw "dotnet-gitversion failed with exit code $LASTEXITCODE." - } - - $gv = $gitVersionJson | ConvertFrom-Json - - $configPath = Join-Path '$(Build.SourcesDirectory)' 'GitVersion.yml' - $configCommit = (git log -n 1 --format=%H -- $configPath).Trim() - if ([string]::IsNullOrWhiteSpace($configCommit)) { - throw "Could not determine the commit that last changed GitVersion.yml." + $packageVersion = (dotnet tool run nbgv get-version -v NuGetPackageVersion).Trim() + if ($LASTEXITCODE -ne 0 -or [string]::IsNullOrWhiteSpace($packageVersion)) { + throw "Failed to compute version metadata with nbgv." } - $commitsSinceConfig = [int](git rev-list --count "$configCommit..HEAD") - if ($commitsSinceConfig -gt 65535) { - throw "Commits since GitVersion.yml ($commitsSinceConfig) exceeds the maximum .NET assembly version segment value of 65535. Bump next-version in GitVersion.yml before generating assembly and file versions." - } - - $assemblyVersion = "$($gv.Major).$($gv.Minor).$commitsSinceConfig" - $packageVersion = "$assemblyVersion-preview" - $fileVersion = "$assemblyVersion.0" - $infoVersion = "$packageVersion+$(Build.SourceVersion)" - - Write-Host "AssemblyVersion: $assemblyVersion" Write-Host "PackageVersion: $packageVersion" - - Write-Host "##vso[task.setvariable variable=CosmosDBShell_Version]$assemblyVersion" Write-Host "##vso[task.setvariable variable=CosmosDBShell_PackageVersion]$packageVersion" - Write-Host "##vso[task.setvariable variable=CosmosDBShell_FileVersion]$fileVersion" - Write-Host "##vso[task.setvariable variable=CosmosDBShell_InformationalVersion]$infoVersion" - task: onebranch.pipeline.version@1 displayName: "Update build number" @@ -166,7 +142,7 @@ extends: displayName: "DotNetCore build with RoslynAnalyzers" inputs: userProvideBuildInfo: "msBuildInfo" - msBuildCommandline: "dotnet.exe build $(BuildSolution) --no-restore --configuration $(BuildConfiguration) /p:Version=$(CosmosDBShell_Version) /p:FileVersion=$(CosmosDBShell_FileVersion) /p:InformationalVersion=$(CosmosDBShell_InformationalVersion)" + msBuildCommandline: "dotnet.exe build $(BuildSolution) --no-restore --configuration $(BuildConfiguration)" - task: DotNetCoreCLI@2 displayName: "DotNetCore test" @@ -189,7 +165,7 @@ extends: command: "publish" publishWebProjects: false projects: $(ReleaseProject) - arguments: '--configuration $(BuildConfiguration) -r win-x64 --output $(Build.SourcesDirectory)\out\win-x64 /p:Version=$(CosmosDBShell_Version) /p:FileVersion=$(CosmosDBShell_FileVersion) /p:InformationalVersion=$(CosmosDBShell_InformationalVersion) --configfile $(Build.SourcesDirectory)\.pipelines\nuget.config' + arguments: '--configuration $(BuildConfiguration) -r win-x64 --output $(Build.SourcesDirectory)\out\win-x64 --configfile $(Build.SourcesDirectory)\.pipelines\nuget.config' zipAfterPublish: false - task: DotNetCoreCLI@2 @@ -198,7 +174,7 @@ extends: command: "publish" publishWebProjects: false projects: $(ReleaseProject) - arguments: '--configuration $(BuildConfiguration) -r win-arm64 --output $(Build.SourcesDirectory)\out\win-arm64 /p:Version=$(CosmosDBShell_Version) /p:FileVersion=$(CosmosDBShell_FileVersion) /p:InformationalVersion=$(CosmosDBShell_InformationalVersion) --configfile $(Build.SourcesDirectory)\.pipelines\nuget.config' + arguments: '--configuration $(BuildConfiguration) -r win-arm64 --output $(Build.SourcesDirectory)\out\win-arm64 --configfile $(Build.SourcesDirectory)\.pipelines\nuget.config' zipAfterPublish: false - task: DotNetCoreCLI@2 @@ -207,7 +183,7 @@ extends: command: "publish" publishWebProjects: false projects: $(ReleaseProject) - arguments: '--configuration $(BuildConfiguration) -r osx-x64 --output $(Build.SourcesDirectory)\out\osx-x64 /p:Version=$(CosmosDBShell_Version) /p:FileVersion=$(CosmosDBShell_FileVersion) /p:InformationalVersion=$(CosmosDBShell_InformationalVersion) --configfile $(Build.SourcesDirectory)\.pipelines\nuget.config' + arguments: '--configuration $(BuildConfiguration) -r osx-x64 --output $(Build.SourcesDirectory)\out\osx-x64 --configfile $(Build.SourcesDirectory)\.pipelines\nuget.config' zipAfterPublish: false - task: DotNetCoreCLI@2 @@ -216,7 +192,7 @@ extends: command: "publish" publishWebProjects: false projects: $(ReleaseProject) - arguments: '--configuration $(BuildConfiguration) -r linux-x64 --output $(Build.SourcesDirectory)\out\linux-x64 /p:Version=$(CosmosDBShell_Version) /p:FileVersion=$(CosmosDBShell_FileVersion) /p:InformationalVersion=$(CosmosDBShell_InformationalVersion) --configfile $(Build.SourcesDirectory)\.pipelines\nuget.config' + arguments: '--configuration $(BuildConfiguration) -r linux-x64 --output $(Build.SourcesDirectory)\out\linux-x64 --configfile $(Build.SourcesDirectory)\.pipelines\nuget.config' zipAfterPublish: false - task: DotNetCoreCLI@2 @@ -225,7 +201,7 @@ extends: command: "publish" publishWebProjects: false projects: $(ReleaseProject) - arguments: '--configuration $(BuildConfiguration) -r linux-arm64 --output $(Build.SourcesDirectory)\out\linux-arm64 /p:Version=$(CosmosDBShell_Version) /p:FileVersion=$(CosmosDBShell_FileVersion) /p:InformationalVersion=$(CosmosDBShell_InformationalVersion) --configfile $(Build.SourcesDirectory)\.pipelines\nuget.config' + arguments: '--configuration $(BuildConfiguration) -r linux-arm64 --output $(Build.SourcesDirectory)\out\linux-arm64 --configfile $(Build.SourcesDirectory)\.pipelines\nuget.config' zipAfterPublish: false - task: DotNetCoreCLI@2 @@ -234,7 +210,7 @@ extends: command: "publish" publishWebProjects: false projects: $(ReleaseProject) - arguments: '--configuration $(BuildConfiguration) -r osx-arm64 --output $(Build.SourcesDirectory)\out\osx-arm64 /p:Version=$(CosmosDBShell_Version) /p:FileVersion=$(CosmosDBShell_FileVersion) /p:InformationalVersion=$(CosmosDBShell_InformationalVersion) --configfile $(Build.SourcesDirectory)\.pipelines\nuget.config' + arguments: '--configuration $(BuildConfiguration) -r osx-arm64 --output $(Build.SourcesDirectory)\out\osx-arm64 --configfile $(Build.SourcesDirectory)\.pipelines\nuget.config' zipAfterPublish: false # Kept for reference, intentionally disabled: @@ -416,10 +392,6 @@ extends: --no-build ` --no-restore ` --output $pkgDir ` - /p:PackageVersion=$(CosmosDBShell_PackageVersion) ` - /p:Version=$(CosmosDBShell_Version) ` - /p:FileVersion=$(CosmosDBShell_FileVersion) ` - /p:InformationalVersion=$(CosmosDBShell_InformationalVersion) ` /p:ContinuousIntegrationBuild=true if ($LASTEXITCODE -ne 0) { diff --git a/Directory.Build.props b/Directory.Build.props index bd3ae56..b2043b9 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,15 +1,15 @@ - - - - - preview - + + + + + diff --git a/Directory.Packages.props b/Directory.Packages.props index 5f198f0..d753641 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -16,6 +16,7 @@ + diff --git a/GitVersion.yml b/GitVersion.yml deleted file mode 100644 index 51c42bc..0000000 --- a/GitVersion.yml +++ /dev/null @@ -1,21 +0,0 @@ -# GitVersion configuration for CosmosDBShell. -# Docs: https://gitversion.net/docs/reference/configuration -# -# We use GitVersion purely to read next-version (Major.Minor) and count -# commits since it was last bumped. The pipelines construct the final -# version string as "Major.Minor.-preview" from those values so -# we get the exact format we want across GitHub Actions and OneBranch. -# -# To start a new release line, bump next-version (e.g. 1.2.0) and commit. -# -# We override `strategies` to omit `TaggedCommit` so GitVersion never -# treats a tag (such as `v1.0.273`) as the version source. Without this, -# creating a version tag resets `CommitsSinceVersionSource` and the patch -# number can go backwards relative to a previous build. -strategies: - - Fallback - - ConfiguredNextVersion - - TrackReleaseBranches - - VersionInBranchName - -next-version: 1.1.0 diff --git a/version.json b/version.json new file mode 100644 index 0000000..6854714 --- /dev/null +++ b/version.json @@ -0,0 +1,19 @@ +{ + "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json", + "version": "1.1-preview", + "publicReleaseRefSpec": [ + "^refs/heads/main$", + "^refs/heads/rel/.+$", + "^refs/pull/\\d+/merge$" + ], + "nugetPackageVersion": { + "semVer": 2 + }, + "cloudBuild": { + "buildNumber": { + "enabled": false + }, + "setVersionVariables": false, + "setAllVariables": false + } +} From 6768671bff8e0645e2de045e30dd2d57e46a4513 Mon Sep 17 00:00:00 2001 From: Vsevolod Kukol Date: Wed, 20 May 2026 22:31:46 +0200 Subject: [PATCH 2/3] Split NBGV PackageReference by central PM mode Address PR feedback: VersionOverride was applied unconditionally, shadowing the central entry in Directory.Packages.props for every consumer. Use a conditional PackageReference instead so central-PM projects pull the version from Directory.Packages.props and only CosmosDBShell.Fuzzer (which sets ManagePackageVersionsCentrally=false) pins it directly. --- Directory.Build.props | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index b2043b9..8dcb9c5 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -5,11 +5,14 @@ a Major.Minor bump cleanly resets the patch to 0. NBGV sets Version, FileVersion, AssemblyVersion, AssemblyInformationalVersion, and PackageVersion automatically for both local and CI builds. --> - - - + + + + + + + From 2c8628187c82ee9075da0b8c17e2d69299597276 Mon Sep 17 00:00:00 2001 From: Vsevolod Kukol Date: Wed, 20 May 2026 22:34:19 +0200 Subject: [PATCH 3/3] Use full git clone in integration-tests workflow for NBGV --- .github/workflows/integration-tests.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index 8c93c6e..effa318 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -19,6 +19,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Setup .NET uses: actions/setup-dotnet@v4 @@ -52,6 +54,8 @@ jobs: steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Setup .NET uses: actions/setup-dotnet@v4