Replace Coverlet with dotnet-coverage for code coverage collection #6
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: Build and Publish | |
| on: | |
| push: | |
| branches: [ main, develop ] | |
| pull_request: | |
| branches: [ main, develop ] | |
| release: | |
| types: [ published ] | |
| workflow_dispatch: | |
| env: | |
| DOTNET_VERSION: '10.0.x' | |
| DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 | |
| DOTNET_NOLOGO: true | |
| DOTNET_CLI_TELEMETRY_OPTOUT: 1 | |
| jobs: | |
| build: | |
| name: Build and Test | |
| runs-on: windows-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Full history for versioning | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: ${{ env.DOTNET_VERSION }} | |
| - name: Display .NET version | |
| run: dotnet --version | |
| - name: Build solution | |
| run: | | |
| cd src | |
| .\build.ps1 -Configuration Release -SkipTests | |
| shell: pwsh | |
| - name: Run tests with coverage | |
| run: | | |
| cd src | |
| .\build.ps1 -Configuration Release -TestOnly -EnableCodeCoverage -GenerateTestReport | |
| shell: pwsh | |
| - name: Upload test results | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: test-results | |
| path: src/TestResults/**/* | |
| retention-days: 30 | |
| - name: Upload code coverage | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: code-coverage | |
| path: src/TestResults/Coverage/**/* | |
| retention-days: 30 | |
| - name: Publish test results | |
| if: always() | |
| uses: EnricoMi/publish-unit-test-result-action/windows@v2 | |
| with: | |
| files: src/TestResults/**/*.trx | |
| check_name: Test Results | |
| comment_mode: off | |
| - name: Code Coverage Report | |
| if: always() | |
| uses: danielpalme/[email protected] | |
| with: | |
| reports: 'src/TestResults/Coverage/coverage.cobertura.xml' | |
| targetdir: 'src/TestResults/CoverageReport' | |
| reporttypes: 'MarkdownSummaryGithub;Html' | |
| filefilters: '-*.g.cs' | |
| verbosity: 'Info' | |
| - name: Write Coverage Summary to Job Summary | |
| if: always() | |
| run: | | |
| if (Test-Path src/TestResults/CoverageReport/SummaryGithub.md) { | |
| Get-Content src/TestResults/CoverageReport/SummaryGithub.md >> $env:GITHUB_STEP_SUMMARY | |
| } | |
| shell: pwsh | |
| - name: Add Coverage PR Comment | |
| if: github.event_name == 'pull_request' && always() | |
| uses: marocchino/sticky-pull-request-comment@v2 | |
| with: | |
| recreate: true | |
| path: src/TestResults/CoverageReport/SummaryGithub.md | |
| - name: Create NuGet packages | |
| if: github.event_name == 'push' || github.event_name == 'release' || github.event_name == 'workflow_dispatch' | |
| run: | | |
| cd src | |
| .\build.ps1 -Configuration Release -PackOnly -PackageOutputPath "${{ github.workspace }}/packages" | |
| shell: pwsh | |
| - name: Upload NuGet packages | |
| if: github.event_name == 'push' || github.event_name == 'release' || github.event_name == 'workflow_dispatch' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: nuget-packages | |
| path: packages/**/*.nupkg | |
| retention-days: 90 | |
| publish: | |
| name: Publish to GitHub Packages | |
| runs-on: windows-latest | |
| needs: build | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' || github.event_name == 'release' | |
| steps: | |
| - name: Download NuGet packages | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: nuget-packages | |
| path: packages | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: ${{ env.DOTNET_VERSION }} | |
| source-url: https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json | |
| env: | |
| NUGET_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Publish to GitHub Packages | |
| run: | | |
| Get-ChildItem -Path packages -Filter *.nupkg -Recurse | ForEach-Object { | |
| Write-Host "Publishing $($_.Name)..." | |
| dotnet nuget push $_.FullName --api-key ${{ secrets.GITHUB_TOKEN }} --source "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json" --skip-duplicate | |
| } | |
| shell: pwsh | |
| - name: Publish Summary | |
| run: | | |
| $packages = Get-ChildItem -Path packages -Filter *.nupkg -Recurse | |
| Write-Output "## 📦 Published Packages" >> $env:GITHUB_STEP_SUMMARY | |
| Write-Output "" >> $env:GITHUB_STEP_SUMMARY | |
| Write-Output "| Package | Version |" >> $env:GITHUB_STEP_SUMMARY | |
| Write-Output "|---------|---------|" >> $env:GITHUB_STEP_SUMMARY | |
| foreach ($pkg in $packages) { | |
| $name = $pkg.BaseName -replace '\.\d+\.\d+\.\d+.*$', '' | |
| $version = $pkg.BaseName -replace '^.*?(\d+\.\d+\.\d+.*)$', '$1' | |
| Write-Output "| $name | $version |" >> $env:GITHUB_STEP_SUMMARY | |
| } | |
| shell: pwsh | |
| publish-release: | |
| name: Publish Release to GitHub Packages | |
| runs-on: windows-latest | |
| needs: build | |
| if: github.event_name == 'release' | |
| steps: | |
| - name: Download NuGet packages | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: nuget-packages | |
| path: packages | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: ${{ env.DOTNET_VERSION }} | |
| - name: Publish to GitHub Packages | |
| run: | | |
| Get-ChildItem -Path packages -Filter *.nupkg -Recurse | ForEach-Object { | |
| Write-Host "Publishing release package $($_.Name)..." | |
| dotnet nuget push $_.FullName --api-key ${{ secrets.GITHUB_TOKEN }} --source "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json" --skip-duplicate | |
| } | |
| shell: pwsh | |
| env: | |
| NUGET_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Upload packages to release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| files: packages/**/*.nupkg | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |