Changes to the GitVersion.yml configurations #37
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Messaging CI/CD | |
| permissions: | |
| contents: read | |
| packages: write | |
| on: | |
| push: | |
| branches: [ main, develop ] | |
| env: | |
| DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true | |
| DOTNET_NOLOGO: true | |
| DOTNET_CLI_TELEMETRY_OPTOUT: true | |
| jobs: | |
| calculate-version: | |
| name: "Calculate Version" | |
| runs-on: ubuntu-latest | |
| outputs: | |
| version: ${{ steps.validate-version.outputs.VERSION }} | |
| nuget-version: ${{ steps.validate-version.outputs.NUGET_VERSION }} | |
| assembly-version: ${{ steps.validate-version.outputs.ASSEMBLY_VERSION }} | |
| file-version: ${{ steps.validate-version.outputs.FILE_VERSION }} | |
| informational-version: ${{ steps.validate-version.outputs.INFORMATIONAL_VERSION }} | |
| is-prerelease: ${{ steps.validate-version.outputs.IS_PRERELEASE }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Install GitVersion | |
| uses: gittools/actions/gitversion/setup@v4.0.1 | |
| with: | |
| versionSpec: '6.x' | |
| - name: Determine Version | |
| id: gitversion | |
| uses: gittools/actions/gitversion/execute@v4.0.1 | |
| - name: Validate and Normalize All Version Properties | |
| id: validate-version | |
| run: | | |
| echo "🔍 Raw GitVersion outputs:" | |
| echo "SemVer: '${{ steps.gitversion.outputs.SemVer }}'" | |
| echo "NuGetVersion: '${{ steps.gitversion.outputs.NuGetVersion }}'" | |
| echo "AssemblySemVer: '${{ steps.gitversion.outputs.AssemblySemVer }}'" | |
| echo "AssemblySemFileVer: '${{ steps.gitversion.outputs.AssemblySemFileVer }}'" | |
| echo "InformationalVersion: '${{ steps.gitversion.outputs.InformationalVersion }}'" | |
| echo "PreReleaseTag: '${{ steps.gitversion.outputs.PreReleaseTag }}'" | |
| echo "PreReleaseNumber: '${{ steps.gitversion.outputs.PreReleaseNumber }}'" | |
| echo "CommitsSinceVersionSource: '${{ steps.gitversion.outputs.CommitsSinceVersionSource }}'" | |
| # Validate and set Version (SemVer) | |
| VERSION="${{ steps.gitversion.outputs.SemVer }}" | |
| if [ -z "$VERSION" ] || [ "$VERSION" = " " ] || [ "$VERSION" = "0.0.0" ]; then | |
| echo "⚠️ SemVer is empty or invalid, using fallback" | |
| if [ "${{ github.ref }}" = "refs/heads/develop" ]; then | |
| VERSION="1.0.0-dev.1" | |
| else | |
| VERSION="1.0.0-dev" | |
| fi | |
| fi | |
| # Validate and set NuGet Version | |
| NUGET_VERSION="${{ steps.gitversion.outputs.NuGetVersion }}" | |
| if [ -z "$NUGET_VERSION" ] || [ "$NUGET_VERSION" = " " ] || [ "$NUGET_VERSION" = "0.0.0" ]; then | |
| echo "⚠️ NuGetVersion is empty or invalid, using SemVer fallback" | |
| NUGET_VERSION="$VERSION" | |
| fi | |
| # Validate and set AssemblyVersion | |
| ASSEMBLY_VERSION="${{ steps.gitversion.outputs.AssemblySemVer }}" | |
| if [ -z "$ASSEMBLY_VERSION" ] || [ "$ASSEMBLY_VERSION" = " " ] || [ "$ASSEMBLY_VERSION" = "0.0.0" ]; then | |
| echo "⚠️ AssemblySemVer is empty or invalid, using fallback" | |
| ASSEMBLY_VERSION="1.0.0.0" | |
| fi | |
| # Validate and set FileVersion | |
| FILE_VERSION="${{ steps.gitversion.outputs.AssemblySemFileVer }}" | |
| if [ -z "$FILE_VERSION" ] || [ "$FILE_VERSION" = " " ] || [ "$FILE_VERSION" = "0.0.0" ]; then | |
| echo "⚠️ AssemblySemFileVer is empty or invalid, using AssemblyVersion" | |
| FILE_VERSION="$ASSEMBLY_VERSION" | |
| fi | |
| # Validate and set InformationalVersion | |
| INFORMATIONAL_VERSION="${{ steps.gitversion.outputs.InformationalVersion }}" | |
| if [ -z "$INFORMATIONAL_VERSION" ] || [ "$INFORMATIONAL_VERSION" = " " ]; then | |
| echo "⚠️ InformationalVersion is empty or invalid, using Version fallback" | |
| INFORMATIONAL_VERSION="$VERSION" | |
| fi | |
| # Determine if this is a pre-release | |
| IS_PRERELEASE="false" | |
| if [[ "$NUGET_VERSION" == *"-"* ]]; then | |
| IS_PRERELEASE="true" | |
| echo "🎯 Pre-release version detected: $NUGET_VERSION" | |
| fi | |
| echo "✅ Validated versions:" | |
| echo "Version: '$VERSION'" | |
| echo "NuGetVersion: '$NUGET_VERSION'" | |
| echo "AssemblyVersion: '$ASSEMBLY_VERSION'" | |
| echo "FileVersion: '$FILE_VERSION'" | |
| echo "InformationalVersion: '$INFORMATIONAL_VERSION'" | |
| echo "IsPreRelease: '$IS_PRERELEASE'" | |
| echo "VERSION=$VERSION" >> $GITHUB_OUTPUT | |
| echo "NUGET_VERSION=$NUGET_VERSION" >> $GITHUB_OUTPUT | |
| echo "ASSEMBLY_VERSION=$ASSEMBLY_VERSION" >> $GITHUB_OUTPUT | |
| echo "FILE_VERSION=$FILE_VERSION" >> $GITHUB_OUTPUT | |
| echo "INFORMATIONAL_VERSION=$INFORMATIONAL_VERSION" >> $GITHUB_OUTPUT | |
| echo "IS_PRERELEASE=$IS_PRERELEASE" >> $GITHUB_OUTPUT | |
| - name: Display Final Version Information | |
| run: | | |
| echo "🔍 Final CD Version Calculation:" | |
| echo "Branch: ${{ github.ref }}" | |
| echo "Version: ${{ steps.validate-version.outputs.VERSION }}" | |
| echo "NuGet Version: ${{ steps.validate-version.outputs.NUGET_VERSION }}" | |
| echo "Assembly Version: ${{ steps.validate-version.outputs.ASSEMBLY_VERSION }}" | |
| echo "File Version: ${{ steps.validate-version.outputs.FILE_VERSION }}" | |
| echo "Informational Version: ${{ steps.validate-version.outputs.INFORMATIONAL_VERSION }}" | |
| echo "Is Pre-release: ${{ steps.validate-version.outputs.IS_PRERELEASE }}" | |
| build: | |
| needs: calculate-version | |
| name: "Build and Test" | |
| strategy: | |
| matrix: | |
| include: | |
| - dotnet: '8.0.x' | |
| dotnet-framework: 'net8.0' | |
| os: ubuntu-latest | |
| - dotnet: '8.0.x' | |
| dotnet-framework: 'net8.0' | |
| os: windows-latest | |
| - dotnet: '9.0.x' | |
| dotnet-framework: 'net9.0' | |
| os: ubuntu-latest | |
| - dotnet: '9.0.x' | |
| dotnet-framework: 'net9.0' | |
| os: windows-latest | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup .NET ${{ matrix.dotnet }} | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: ${{ matrix.dotnet }} | |
| - name: Display Build Version Info | |
| run: | | |
| echo "🔍 Build Version Information:" | |
| echo "SemVer: ${{ needs.calculate-version.outputs.version }}" | |
| echo "NuGet Version: ${{ needs.calculate-version.outputs.nuget-version }}" | |
| echo "Assembly Version: ${{ needs.calculate-version.outputs.assembly-version }}" | |
| echo "File Version: ${{ needs.calculate-version.outputs.file-version }}" | |
| echo "Informational Version: ${{ needs.calculate-version.outputs.informational-version }}" | |
| echo "Is Pre-release: ${{ needs.calculate-version.outputs.is-prerelease }}" | |
| - name: Restore dependencies | |
| run: dotnet restore -p:TargetFramework=${{ matrix.dotnet-framework }} | |
| - name: Build | |
| run: | | |
| echo "🏗️ Building with explicit version properties..." | |
| dotnet build --no-restore -c Release -f ${{ matrix.dotnet-framework }} \ | |
| -p:Version="${{ needs.calculate-version.outputs.nuget-version }}" \ | |
| -p:PackageVersion="${{ needs.calculate-version.outputs.nuget-version }}" \ | |
| -p:AssemblyVersion="${{ needs.calculate-version.outputs.assembly-version }}" \ | |
| -p:FileVersion="${{ needs.calculate-version.outputs.file-version }}" \ | |
| -p:InformationalVersion="${{ needs.calculate-version.outputs.informational-version }}" \ | |
| -p:UseGitVersion=false \ | |
| --verbosity normal | |
| - name: Test (Ubuntu) | |
| if: startsWith(matrix.os, 'ubuntu') | |
| run: dotnet test --no-build --verbosity normal -c Release -f ${{ matrix.dotnet-framework }} | |
| - name: Test (Windows) | |
| if: startsWith(matrix.os, 'windows') | |
| run: dotnet test --no-build --verbosity normal -c Release -f ${{ matrix.dotnet-framework }} --filter "DB!=SQLServer" | |
| publish: | |
| needs: [calculate-version, build] | |
| name: "Publish Pre-release Packages" | |
| if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop' | |
| uses: ./.github/workflows/publish.yml | |
| with: | |
| publish-to-nuget: false | |
| build-configuration: 'Release' | |
| version: ${{ needs.calculate-version.outputs.version }} | |
| nuget-version: ${{ needs.calculate-version.outputs.nuget-version }} | |
| assembly-version: ${{ needs.calculate-version.outputs.assembly-version }} | |
| informational-version: ${{ needs.calculate-version.outputs.informational-version }} | |
| secrets: inherit | |
| clean: | |
| needs: publish | |
| name: "Clean Old Pre-release Packages" | |
| if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop' | |
| uses: ./.github/workflows/clean-packages.yml | |
| summary: | |
| needs: [calculate-version, build, publish] | |
| runs-on: ubuntu-latest | |
| if: always() | |
| steps: | |
| - name: CD Workflow Summary | |
| run: | | |
| echo "## 🚀 CD Workflow Summary" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "| Property | Value |" >> $GITHUB_STEP_SUMMARY | |
| echo "|----------|-------|" >> $GITHUB_STEP_SUMMARY | |
| echo "| Branch | \`${{ github.ref_name }}\` |" >> $GITHUB_STEP_SUMMARY | |
| echo "| Version | \`${{ needs.calculate-version.outputs.version }}\` |" >> $GITHUB_STEP_SUMMARY | |
| echo "| NuGet Version | \`${{ needs.calculate-version.outputs.nuget-version }}\` |" >> $GITHUB_STEP_SUMMARY | |
| echo "| Assembly Version | \`${{ needs.calculate-version.outputs.assembly-version }}\` |" >> $GITHUB_STEP_SUMMARY | |
| echo "| Pre-release | ${{ needs.calculate-version.outputs.is-prerelease == 'true' && '✅ Yes' || '❌ No' }} |" >> $GITHUB_STEP_SUMMARY | |
| echo "| Published to GitHub | ${{ needs.publish.result == 'success' && '✅ Yes' || '❌ No' }} |" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| if [ "${{ needs.calculate-version.outputs.is-prerelease }}" == "true" ]; then | |
| echo "🎯 **Pre-release Package**: This version includes commit count and pre-release identifier" >> $GITHUB_STEP_SUMMARY | |
| echo "📦 **Usage**: Install with \`--prerelease\` flag: \`dotnet add package PackageName --version ${{ needs.calculate-version.outputs.nuget-version }} --prerelease\`" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "🏷️ **Stable Package**: This is a stable release version" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "📦 **Published Packages**: Check the [GitHub Packages](https://github.com/${{ github.repository }}/pkgs) for the published packages." >> $GITHUB_STEP_SUMMARY |