Bump the minor-and-patch group with 1 update (#44) #61
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: Tests & Coverage | |
| on: | |
| pull_request: | |
| push: | |
| branches: [ main ] | |
| permissions: | |
| contents: read | |
| pages: write | |
| id-token: write | |
| checks: write | |
| pull-requests: write | |
| jobs: | |
| test: | |
| name: Build, Test, Coverage | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v5 | |
| with: | |
| dotnet-version: '8.0.x' | |
| - name: Restore | |
| run: dotnet restore | |
| - name: Build | |
| run: dotnet build --configuration Release --no-restore | |
| # Create runsettings so the XPlat collector outputs Cobertura XML | |
| - name: Create coverage runsettings (Cobertura) | |
| run: | | |
| printf '%s\n' \ | |
| '<?xml version="1.0" encoding="utf-8"?>' \ | |
| '<RunSettings>' \ | |
| ' <DataCollectionRunSettings>' \ | |
| ' <DataCollectors>' \ | |
| ' <DataCollector friendlyName="XPlat Code Coverage">' \ | |
| ' <Configuration>' \ | |
| ' <Format>cobertura</Format>' \ | |
| ' </Configuration>' \ | |
| ' </DataCollector>' \ | |
| ' </DataCollectors>' \ | |
| ' </DataCollectionRunSettings>' \ | |
| '</RunSettings>' \ | |
| > coverlet.runsettings | |
| # Collect coverage using the built-in collector, force outputs into ./TestResults | |
| - name: Test with coverage (XPlat collector → Cobertura) | |
| run: | | |
| set -e | |
| mkdir -p TestResults | |
| dotnet test --no-build --configuration Release \ | |
| --logger "trx;LogFileName=test-results.trx" \ | |
| --collect:"XPlat Code Coverage" \ | |
| --settings coverlet.runsettings \ | |
| --results-directory TestResults | |
| echo "---- locate Cobertura files (debug) ----" | |
| find TestResults -type f -name "coverage.cobertura.xml" -print || true | |
| # Publish TRX into PR as a check (disabled for forked PRs) | |
| - name: Publish unit test results to PR | |
| if: ${{ github.event_name == 'pull_request' && !github.event.pull_request.head.repo.fork && always() }} | |
| uses: EnricoMi/publish-unit-test-result-action@v2 | |
| with: | |
| files: | | |
| **/TestResults/**/*.trx | |
| # Generate HTML coverage + badges, and enforce 75% line coverage | |
| - name: Generate coverage HTML, badges, and enforce threshold | |
| if: ${{ always() }} | |
| run: | | |
| set -e | |
| dotnet tool update -g dotnet-reportgenerator-globaltool | |
| export PATH="$PATH:/github/home/.dotnet/tools" | |
| SRC="TestResults/**/coverage.cobertura.xml" | |
| echo "Using reports pattern: $SRC" | |
| if compgen -G "$SRC" > /dev/null; then | |
| reportgenerator \ | |
| -reports:"$SRC" \ | |
| -targetdir:"coverage-report" \ | |
| -reporttypes:"Html;HtmlSummary;MarkdownSummaryGithub;Badges;TextSummary" | |
| echo "---- coverage-report contents ----" | |
| ls -la coverage-report || true | |
| # Enforce 75% line coverage from Summary.txt ("Line coverage: 83.4%") | |
| COV_LINE=$(grep -Eo 'Line coverage: *[0-9]+(\.[0-9]+)?%' coverage-report/Summary.txt | grep -Eo '[0-9]+(\.[0-9]+)?') | |
| echo "Parsed line coverage: ${COV_LINE:-N/A}%" | |
| awk -v cov="${COV_LINE:-0}" 'BEGIN { if (cov+0 < 75) exit 1 }' || { | |
| echo "Line coverage ${COV_LINE}% is below the 75% threshold."; exit 1; } | |
| else | |
| echo "No Cobertura files found; creating placeholder site." | |
| mkdir -p coverage-report | |
| printf '%s\n' \ | |
| '<!doctype html><meta charset="utf-8">' \ | |
| '<title>Coverage</title>' \ | |
| '<h1>No coverage files found for this run.</h1>' \ | |
| '<p>Verify the XPlat collector executed and produced Cobertura.</p>' \ | |
| > coverage-report/index.html | |
| fi | |
| - name: Upload artifacts (TRX + coverage HTML) | |
| if: ${{ always() }} | |
| uses: actions/upload-artifact@v6 | |
| with: | |
| name: test-and-coverage-artifacts | |
| path: | | |
| TestResults/**/*.trx | |
| coverage-report/** | |
| - name: Add coverage summary to PR | |
| if: ${{ always() }} | |
| run: | | |
| if [ -f "coverage-report/SummaryGithub.md" ]; then | |
| echo "## Code Coverage" >> "$GITHUB_STEP_SUMMARY" | |
| cat coverage-report/SummaryGithub.md >> "$GITHUB_STEP_SUMMARY" | |
| else | |
| echo "_No coverage report generated._" >> "$GITHUB_STEP_SUMMARY" | |
| fi | |
| - name: Prepare site for Pages | |
| if: ${{ always() }} | |
| run: | | |
| set -e | |
| rm -rf site | |
| mkdir -p site | |
| if [ -d "coverage-report" ] && [ "$(ls -A coverage-report)" ]; then | |
| cp -r coverage-report/* site/ || true | |
| fi | |
| mkdir -p site/tests | |
| find . -path ./site -prune -o -type f -name '*.trx' -print -exec cp {} site/tests/ \; || true | |
| if [ ! -f site/index.html ]; then | |
| printf '%s\n' \ | |
| '<!doctype html><meta charset="utf-8">' \ | |
| '<title>Test & Coverage Reports</title>' \ | |
| '<h1>Test & Coverage Reports</h1>' \ | |
| '<p>No coverage site for this run. TRX files are under <a href="./tests/">/tests/</a>.</p>' \ | |
| > site/index.html | |
| fi | |
| - name: Configure Pages | |
| if: ${{ github.ref == 'refs/heads/main' && always() }} | |
| uses: actions/configure-pages@v5 | |
| - name: Upload site artifact for Pages | |
| if: ${{ github.ref == 'refs/heads/main' && always() }} | |
| uses: actions/upload-pages-artifact@v4 | |
| with: | |
| path: site | |
| - name: Deploy to GitHub Pages | |
| if: ${{ github.ref == 'refs/heads/main' && always() }} | |
| uses: actions/deploy-pages@v4 |