Update bug_report_form.yml #144
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: "3. Code Coverage" | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| on: | |
| push: | |
| branches: | |
| - "main" | |
| - "feature/*" | |
| paths-ignore: | |
| - "**/README.md" | |
| - "coverage-badge.svg" # prevent loops when the badge PR merges | |
| pull_request: | |
| branches: | |
| - "main" | |
| workflow_dispatch: | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.ref }} | |
| fetch-depth: 0 | |
| persist-credentials: false # let CPR push with the workflow token | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: 8.0.x | |
| - name: Install ReportGenerator tool | |
| run: dotnet tool install --global dotnet-reportgenerator-globaltool | |
| - name: Restore dependencies | |
| run: dotnet restore | |
| - name: Build the solution | |
| run: dotnet build --no-restore | |
| - name: Run tests and collect code coverage | |
| run: dotnet test --no-build --collect:"XPlat Code Coverage" | |
| - name: Generate code coverage report | |
| run: reportgenerator -reports:"**/coverage.cobertura.xml" -targetdir:"coverage" -reporttypes:"HtmlInline_AzurePipelines;Badges" | |
| - name: Upload coverage report zip | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: code-coverage-report | |
| path: coverage | |
| - name: Prepare badge for repo root (only on main) | |
| if: github.ref == 'refs/heads/main' | |
| run: cp coverage/badge_linecoverage.svg ./coverage-badge.svg | |
| # Create or update a PR that contains ONLY the badge file | |
| - name: Open / update PR with coverage badge (only on main) | |
| if: github.ref == 'refs/heads/main' | |
| id: cpr | |
| uses: peter-evans/create-pull-request@v6 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} # explicit to avoid 403s | |
| branch: ci/update-coverage-badge # PR head branch | |
| base: main # PR base branch | |
| title: "Update coverage badge" | |
| commit-message: "Update coverage badge" | |
| body: "Automated update of coverage-badge.svg" | |
| add-paths: | | |
| coverage-badge.svg | |
| labels: | | |
| ci | |
| automated | |
| - name: Report CPR result | |
| run: | | |
| echo "result=${{ steps.cpr.outputs.result }}" | |
| echo "pr=${{ steps.cpr.outputs.pull-request-url || 'no PR (no changes)'}}" | |
| # Optional: auto-merge the PR when allowed by your protections | |
| - name: Enable auto-merge for badge PR | |
| if: steps.cpr.outputs.pull-request-number | |
| uses: peter-evans/enable-pull-request-automerge@v3 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| pull-request-number: ${{ steps.cpr.outputs.pull-request-number }} | |
| merge-method: squash |