Skip to content

Commit 4ffe386

Browse files
committed
#147 fix code coverage permission issue
1 parent b504cec commit 4ffe386

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

.github/workflows/code-coverage.yml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
name: "3. Code Coverage"
22

3+
permissions:
4+
contents: write
5+
36
on:
47
push:
58
branches:
@@ -22,6 +25,7 @@ jobs:
2225
with:
2326
ref: ${{ github.ref }}
2427
fetch-depth: 0
28+
token: ${{ secrets.GITHUB_TOKEN }}
2529

2630
- name: Setup .NET
2731
uses: actions/setup-dotnet@v4
@@ -55,25 +59,22 @@ jobs:
5559
name: code-coverage-badge
5660
path: coverage/badge_linecoverage.svg
5761

58-
- name: Commit coverage badge
62+
- name: Commit coverage badge (only on main)
63+
if: github.ref == 'refs/heads/main'
5964
run: |
60-
git config --global user.name 'github-actions[bot]'
61-
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
65+
git config --global user.name "github-actions[bot]"
66+
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
6267
6368
# Copy badge to root directory
64-
find . -name badge_linecoverage.svg || echo "Badge not found"
6569
cp coverage/badge_linecoverage.svg ./coverage-badge.svg
6670
67-
# Force add badge and commit
68-
git add -f coverage-badge.svg
69-
if git diff-index --cached --quiet HEAD; then
70-
echo "No changes to commit"
71+
git add coverage-badge.svg
72+
if git diff --cached --quiet; then
73+
echo "No changes to commit"
7174
else
72-
git commit -m 'Update coverage badge'
73-
git push --force
75+
git commit -m "Update coverage badge"
76+
git push
7477
fi
75-
env:
76-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7778
7879
- name: Print Directory Structure
7980
uses: FiorelaCiroku/XDTesting-Print-Directory-Structure@v1.0.2

0 commit comments

Comments
 (0)