Skip to content

Commit 2db926a

Browse files
committed
reupdate
1 parent 01aec42 commit 2db926a

1 file changed

Lines changed: 16 additions & 40 deletions

File tree

.github/workflows/code-coverage.yml

Lines changed: 16 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111
- "feature/*"
1212
paths-ignore:
1313
- "**/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
1515
pull_request:
1616
branches:
1717
- "main"
@@ -27,7 +27,7 @@ jobs:
2727
with:
2828
ref: ${{ github.ref }}
2929
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
3131

3232
- name: Setup .NET
3333
uses: actions/setup-dotnet@v4
@@ -55,52 +55,28 @@ jobs:
5555
name: code-coverage-report
5656
path: coverage
5757

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)
6659
if: github.ref == 'refs/heads/main'
6760
run: |
6861
cp coverage/badge_linecoverage.svg ./coverage-badge.svg
6962
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)
7165
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
9967
uses: peter-evans/create-pull-request@v6
10068
with:
10169
branch: ci/update-coverage-badge
70+
base: main
10271
title: "Update coverage badge"
10372
commit-message: "Update coverage badge"
10473
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

Comments
 (0)