Skip to content

Commit e221bf2

Browse files
committed
test coverage report
1 parent 8de5285 commit e221bf2

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

.github/workflows/test.yml

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ name: test
22
on: [push]
33
permissions:
44
contents: write
5+
pull-requests: write
56
jobs:
67
test:
78
name: test
@@ -13,11 +14,47 @@ jobs:
1314
uses: actions/setup-go@v5
1415
with:
1516
go-version-file: go.mod
17+
1618
- name: test
1719
run: make test
20+
1821
- name: check test coverage
22+
id: coverage
1923
uses: vladopajic/go-test-coverage@v2
2024
with:
2125
config: ./.github/.testcoverage.yml
2226
git-branch: badges
23-
git-token: ${{ github.ref_name == 'main' && secrets.GITHUB_TOKEN || '' }}
27+
git-token: ${{ github.ref_name == 'main' && secrets.GITHUB_TOKEN || '' }}
28+
29+
# Post coverage report as comment
30+
- name: find pull request ID
31+
run: |
32+
PR_DATA=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
33+
"https://api.github.com/repos/${{ github.repository }}/pulls?head=${{ github.repository_owner }}:${{ github.ref_name }}&state=open")
34+
PR_ID=$(echo "$PR_DATA" | jq -r '.[0].number')
35+
36+
if [ "$PR_ID" != "null" ]; then
37+
echo "pull_request_id=$PR_ID" >> $GITHUB_ENV
38+
else
39+
echo "No open pull request found for this branch."
40+
fi
41+
- name: find if coverage report is already present
42+
if: env.pull_request_id
43+
uses: peter-evans/find-comment@v3
44+
id: fc
45+
with:
46+
issue-number: ${{ env.pull_request_id }}
47+
comment-author: 'github-actions[bot]'
48+
body-includes: 'Total test coverage: '
49+
- name: post coverage report
50+
if: env.pull_request_id
51+
uses: peter-evans/create-or-update-comment@v4
52+
with:
53+
token: ${{ secrets.GITHUB_TOKEN }}
54+
issue-number: ${{ env.pull_request_id }}
55+
comment-id: ${{ steps.fc.outputs.comment-id }}
56+
body: |
57+
```
58+
${{ fromJSON(steps.coverage.outputs.report) }}
59+
```
60+
edit-mode: replace

0 commit comments

Comments
 (0)