-
Notifications
You must be signed in to change notification settings - Fork 19
93 lines (78 loc) · 2.85 KB
/
Copy pathcode-coverage.yml
File metadata and controls
93 lines (78 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
name: "3. Code Coverage"
permissions:
contents: write # commit & push
pull-requests: write # open/update PRs
issues: write # create/apply labels (fixes your error)
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 # PR action will handle auth
- 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/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 }} # uses repo�s workflow token
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 branch 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