From 4919abfa91cd4a2cbd6ff194f7a8786aad2d37db Mon Sep 17 00:00:00 2001 From: Bernhard Windisch Date: Sun, 28 Sep 2025 18:39:14 +0200 Subject: [PATCH] Refactor GitVersion integration in workflows to streamline version calculation and logging --- .../workflows/develop-nuget-prerelease.yml | 29 ++++++++------- .github/workflows/develop-prerelease.yml | 30 +++++++++------- .github/workflows/pr-validation.yml | 24 +++++++------ .github/workflows/release-stable.yml | 36 ++++++++++--------- GitVersion.yml | 5 +-- 5 files changed, 67 insertions(+), 57 deletions(-) diff --git a/.github/workflows/develop-nuget-prerelease.yml b/.github/workflows/develop-nuget-prerelease.yml index 5820894..ebed3f0 100644 --- a/.github/workflows/develop-nuget-prerelease.yml +++ b/.github/workflows/develop-nuget-prerelease.yml @@ -28,29 +28,32 @@ jobs: with: dotnet-version: 9.0.x - - name: Build (versioning via GitVersion.MsBuild) - run: | - dotnet restore ./Cocoar.Capabilities.slnx - dotnet build -c Release ./Cocoar.Capabilities.slnx - working-directory: ./src + - name: Install GitVersion + uses: gittools/actions/gitversion/setup@v3 + with: + versionSpec: '6.x' + + - name: Calculate version + uses: gittools/actions/gitversion/execute@v3 + id: gitversion + + - name: Log calculated version + run: echo "GitVersion calculated prerelease version ${{ steps.gitversion.outputs.SemVer }}" - name: Restore dependencies - run: dotnet restore ./Cocoar.Capabilities.slnx + run: dotnet restore working-directory: ./src - name: Build solution - run: dotnet build ./Cocoar.Capabilities.slnx -c Release --no-restore + run: dotnet build -c Release --no-restore working-directory: ./src - name: Run tests - run: dotnet test ./Cocoar.Capabilities.slnx -c Release --no-build --no-restore --verbosity normal + run: dotnet test -c Release --no-build --no-restore --verbosity normal working-directory: ./src - name: Pack NuGet packages (incl. symbols) - run: > - dotnet pack ./Cocoar.Capabilities/Cocoar.Capabilities.csproj -c Release --no-restore - /p:IncludeSymbols=true /p:SymbolPackageFormat=snupkg - -o ../artifacts + run: dotnet pack -c Release --no-restore /p:IncludeSymbols=true /p:SymbolPackageFormat=snupkg -o ../artifacts working-directory: ./src - name: Ensure packages exist @@ -62,7 +65,7 @@ jobs: - name: Upload artifacts (audit) uses: actions/upload-artifact@v4 with: - name: prerelease-packages + name: prerelease-packages-${{ steps.gitversion.outputs.SemVer }} path: artifacts retention-days: 30 diff --git a/.github/workflows/develop-prerelease.yml b/.github/workflows/develop-prerelease.yml index 3a97a13..e3d4259 100644 --- a/.github/workflows/develop-prerelease.yml +++ b/.github/workflows/develop-prerelease.yml @@ -23,33 +23,37 @@ jobs: with: dotnet-version: 9.0.x - - name: Log version from GitVersion.MsBuild - run: | - dotnet restore ./Cocoar.Capabilities.slnx - dotnet build -c Release ./Cocoar.Capabilities.slnx > /dev/null - VERSION=$(grep -oP '\K[^<]+' ./Cocoar.Capabilities/obj/Release/*/GitVersion.MsBuild.props | head -n1 || true) - echo "Calculated SemVer: ${VERSION:-unknown}" - working-directory: ./src + - name: Install GitVersion + uses: gittools/actions/gitversion/setup@v3 + with: + versionSpec: '6.x' + + - name: Calculate version + uses: gittools/actions/gitversion/execute@v3 + id: gitversion + + - name: Log calculated version + run: echo "GitVersion calculated version ${{ steps.gitversion.outputs.SemVer }}" - name: Restore dependencies - run: dotnet restore ./Cocoar.Capabilities.slnx + run: dotnet restore working-directory: ./src - name: Build solution - run: dotnet build ./Cocoar.Capabilities.slnx -c Release --no-restore + run: dotnet build -c Release --no-restore working-directory: ./src - name: Run tests - run: dotnet test ./Cocoar.Capabilities.slnx -c Release --no-build --no-restore --verbosity normal + run: dotnet test -c Release --no-build --no-restore --verbosity normal working-directory: ./src - - name: Pack NuGet packages (incl. symbols) - run: dotnet pack ./Cocoar.Capabilities/Cocoar.Capabilities.csproj -c Release --no-restore /p:IncludeSymbols=true /p:SymbolPackageFormat=snupkg -o ../artifacts + - name: Pack NuGet packages (testing only) + run: dotnet pack -c Release --no-restore -o ../artifacts working-directory: ./src - name: Upload artifacts for testing uses: actions/upload-artifact@v4 with: - name: prerelease-packages + name: prerelease-packages-${{ steps.gitversion.outputs.SemVer }} path: artifacts retention-days: 7 \ No newline at end of file diff --git a/.github/workflows/pr-validation.yml b/.github/workflows/pr-validation.yml index 8b8377e..0ec56f6 100644 --- a/.github/workflows/pr-validation.yml +++ b/.github/workflows/pr-validation.yml @@ -22,22 +22,26 @@ jobs: with: dotnet-version: 9.0.x - - name: Log version from GitVersion.MsBuild - run: | - dotnet restore ./Cocoar.Capabilities.slnx - dotnet build -c Release ./Cocoar.Capabilities.slnx > /dev/null - VERSION=$(grep -oP '\K[^<]+' ./Cocoar.Capabilities/obj/Release/*/GitVersion.MsBuild.props | head -n1 || true) - echo "Calculated SemVer: ${VERSION:-unknown}" - working-directory: ./src + - name: Install GitVersion + uses: gittools/actions/gitversion/setup@v3 + with: + versionSpec: '6.x' + + - name: Calculate version + uses: gittools/actions/gitversion/execute@v3 + id: gitversion + + - name: Log calculated version + run: echo "GitVersion calculated version ${{ steps.gitversion.outputs.SemVer }}" - name: Restore dependencies - run: dotnet restore ./Cocoar.Capabilities.slnx + run: dotnet restore working-directory: ./src - name: Build solution - run: dotnet build ./Cocoar.Capabilities.slnx -c Release --no-restore + run: dotnet build -c Release --no-restore working-directory: ./src - name: Run tests - run: dotnet test ./Cocoar.Capabilities.slnx -c Release --no-build --no-restore --verbosity normal + run: dotnet test -c Release --no-build --no-restore --verbosity normal working-directory: ./src \ No newline at end of file diff --git a/.github/workflows/release-stable.yml b/.github/workflows/release-stable.yml index bb5ac46..7a80711 100644 --- a/.github/workflows/release-stable.yml +++ b/.github/workflows/release-stable.yml @@ -30,37 +30,39 @@ jobs: with: dotnet-version: 9.0.x - - name: Extract version from tag - id: extract_version - shell: bash + - name: Install GitVersion + uses: gittools/actions/gitversion/setup@v3 + with: + versionSpec: '6.x' + + - name: Calculate version + id: gitversion + uses: gittools/actions/gitversion/execute@v3 + + - name: Verify tag matches version run: | TAG="${{ github.event.release.tag_name }}" + SEMVER="${{ steps.gitversion.outputs.SemVer }}" echo "Release tag: $TAG" - if [[ ! "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z\.-]+)?$ ]]; then - echo "::error ::Tag must be like vX.Y.Z or vX.Y.Z-
"); exit 1;
+          echo "GitVersion calculated: $SEMVER"
+          if [ "v$SEMVER" != "$TAG" ]; then
+            echo "::error ::Tag ($TAG) does not match GitVersion ($SEMVER)"; exit 1;
           fi
-          SEMVER="${TAG#v}"
-          echo "SemVer: $SEMVER"
-          echo "semver=$SEMVER" >> "$GITHUB_OUTPUT"
 
       - name: Restore dependencies
-        run: dotnet restore ./Cocoar.Capabilities.slnx
+        run: dotnet restore
         working-directory: ./src
 
       - name: Build solution
-        run: dotnet build ./Cocoar.Capabilities.slnx -c Release --no-restore
+        run: dotnet build -c Release --no-restore
         working-directory: ./src
 
       - name: Run tests
-        run: dotnet test ./Cocoar.Capabilities.slnx -c Release --no-build --no-restore --verbosity normal
+        run: dotnet test -c Release --no-build --no-restore --verbosity normal
         working-directory: ./src
 
       - name: Pack NuGet packages (incl. symbols)
-        run: >
-          dotnet pack ./Cocoar.Capabilities/Cocoar.Capabilities.csproj -c Release --no-restore
-          /p:IncludeSymbols=true /p:SymbolPackageFormat=snupkg
-          /p:Version=${{ steps.extract_version.outputs.semver }}
-          -o ../artifacts
+        run: dotnet pack -c Release --no-restore /p:IncludeSymbols=true /p:SymbolPackageFormat=snupkg -o ../artifacts
         working-directory: ./src
 
       - name: Ensure packages exist
@@ -72,7 +74,7 @@ jobs:
       - name: Upload artifacts (audit)
         uses: actions/upload-artifact@v4
         with:
-          name: packages-${{ steps.extract_version.outputs.semver }}
+          name: packages-${{ steps.gitversion.outputs.SemVer }}
           path: artifacts
           retention-days: 7
 
diff --git a/GitVersion.yml b/GitVersion.yml
index 31b2cdf..46f7f6b 100644
--- a/GitVersion.yml
+++ b/GitVersion.yml
@@ -1,13 +1,10 @@
 mode: ContinuousDeployment
 
 branches:
-  main:
-    regex: ^main$
-    label: ''               # v6 uses 'label' instead of 'tag'
-    is-main-branch: true    # ← use this in v6 (or delete)
   develop:
     regex: ^develop$
     label: alpha
+    is-main-branch: true
   release:
     regex: ^release[/-]
     label: rc