|
11 | 11 | - "feature/*" |
12 | 12 | paths-ignore: |
13 | 13 | - "**/README.md" |
14 | | - - "coverage-badge.svg" # prevent loops when the bot updates the badge |
| 14 | + - "coverage-badge.svg" # prevent loops when the bot updates the badge |
15 | 15 | pull_request: |
16 | 16 | branches: |
17 | 17 | - "main" |
|
27 | 27 | with: |
28 | 28 | ref: ${{ github.ref }} |
29 | 29 | fetch-depth: 0 |
30 | | - persist-credentials: false # we'll push with the workflow token |
| 30 | + persist-credentials: false # we'll rely on the action to commit/push |
31 | 31 |
|
32 | 32 | - name: Setup .NET |
33 | 33 | uses: actions/setup-dotnet@v4 |
@@ -55,52 +55,28 @@ jobs: |
55 | 55 | name: code-coverage-report |
56 | 56 | path: coverage |
57 | 57 |
|
58 | | - - name: Upload coverage badge file |
59 | | - uses: actions/upload-artifact@v4 |
60 | | - with: |
61 | | - name: code-coverage-badge |
62 | | - path: coverage/badge_linecoverage.svg |
63 | | - |
64 | | - # === Create/update PR with the badge (only when running on main) === |
65 | | - - name: Prepare badge (only on main) |
| 58 | + - name: Prepare single-file badge for repo root (only on main) |
66 | 59 | if: github.ref == 'refs/heads/main' |
67 | 60 | run: | |
68 | 61 | cp coverage/badge_linecoverage.svg ./coverage-badge.svg |
69 | 62 |
|
70 | | - - name: Commit badge to a branch (only on main) |
| 63 | + # Create/update a PR containing only the badge file. The action handles commits & pushes. |
| 64 | + - name: Open / update PR with coverage badge (only on main) |
71 | 65 | if: github.ref == 'refs/heads/main' |
72 | | - run: | |
73 | | - git config user.name "github-actions[bot]" |
74 | | - git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
75 | | -
|
76 | | - # Create/update a dedicated branch |
77 | | - BRANCH="ci/update-coverage-badge" |
78 | | - git checkout -B "$BRANCH" |
79 | | -
|
80 | | - git add coverage-badge.svg |
81 | | - if git diff --cached --quiet; then |
82 | | - echo "No changes to commit" |
83 | | - echo "NO_CHANGES=true" >> $GITHUB_ENV |
84 | | - else |
85 | | - git commit -m "Update coverage badge" |
86 | | - echo "NO_CHANGES=false" >> $GITHUB_ENV |
87 | | - fi |
88 | | -
|
89 | | - - name: Push branch (only on main and if changes) |
90 | | - if: github.ref == 'refs/heads/main' && env.NO_CHANGES == 'false' |
91 | | - env: |
92 | | - GH_TOKEN: ${{ github.token }} |
93 | | - run: | |
94 | | - BRANCH="ci/update-coverage-badge" |
95 | | - git push --set-upstream "https://x-access-token:${GH_TOKEN}@github.com/${{ github.repository }}" "$BRANCH" |
96 | | -
|
97 | | - - name: Open / update PR (only on main and if changes) |
98 | | - if: github.ref == 'refs/heads/main' && env.NO_CHANGES == 'false' |
| 66 | + id: cpr |
99 | 67 | uses: peter-evans/create-pull-request@v6 |
100 | 68 | with: |
101 | 69 | branch: ci/update-coverage-badge |
| 70 | + base: main |
102 | 71 | title: "Update coverage badge" |
103 | 72 | commit-message: "Update coverage badge" |
104 | 73 | body: "Automated update of coverage-badge.svg" |
105 | | - base: main |
106 | | - labels: ci, automated |
| 74 | + add-paths: | |
| 75 | + coverage-badge.svg |
| 76 | + labels: | |
| 77 | + ci |
| 78 | + automated |
| 79 | +
|
| 80 | + - name: Print PR URL |
| 81 | + if: steps.cpr.outputs.pull-request-url |
| 82 | + run: echo "${{ steps.cpr.outputs.pull-request-url }}" |
0 commit comments