Skip to content

Commit 8dd315b

Browse files
authored
ci: simplify report comment (#160)
1 parent af63907 commit 8dd315b

File tree

2 files changed

+17
-36
lines changed

2 files changed

+17
-36
lines changed

.github/workflows/test.yml

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ jobs:
8080
path: main.breakdown
8181
if-no-files-found: error
8282

83-
# Post coverage report as comment
8483
- name: find pull request ID
8584
run: |
8685
PR_DATA=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
@@ -92,25 +91,16 @@ jobs:
9291
else
9392
echo "No open pull request found for this branch."
9493
fi
95-
- name: find if coverage report is already present
96-
if: env.pull_request_id
97-
uses: peter-evans/find-comment@v3
98-
id: fc
99-
with:
100-
issue-number: ${{ env.pull_request_id }}
101-
comment-author: 'github-actions[bot]'
102-
body-includes: 'go-test-coverage report:'
10394
- name: post coverage report
10495
if: env.pull_request_id
105-
uses: peter-evans/create-or-update-comment@v4
96+
uses: thollander/actions-comment-pull-request@v3
10697
with:
107-
token: ${{ secrets.GITHUB_TOKEN }}
108-
issue-number: ${{ env.pull_request_id }}
109-
comment-id: ${{ steps.fc.outputs.comment-id }}
110-
edit-mode: replace
111-
body: |
98+
github-token: ${{ secrets.GITHUB_TOKEN }}
99+
comment-tag: coverage-report
100+
pr-number: ${{ env.pull_request_id }}
101+
message: |
112102
go-test-coverage report:
113-
```
103+
```
114104
${{ fromJSON(steps.coverage.outputs.report) }}```
115105
116106
- name: "finally check coverage"

docs/github_action.md

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -108,39 +108,30 @@ Example of report is in [this PR](https://github.com/vladopajic/go-test-coverage
108108
continue-on-error: true # Should fail after coverage comment is posted
109109
with:
110110
config: ./.github/.testcoverage.yml
111-
112-
# Post coverage report as comment (in 3 steps)
111+
112+
# Post coverage report as comment (in 2 steps)
113113
- name: find pull request ID
114114
run: |
115115
PR_DATA=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
116-
"https://api.github.com/repos/${{ github.repository }}/pulls?head=${{ github.repository_owner }}:${{ github.ref_name }}&state=open")
116+
"https://api.github.com/repos/${{ github.repository }}/pulls?head=${{ github.repository_owner }}:${{ github.ref_name }}&state=open")
117117
PR_ID=$(echo "$PR_DATA" | jq -r '.[0].number')
118118
119119
if [ "$PR_ID" != "null" ]; then
120-
echo "pull_request_id=$PR_ID" >> $GITHUB_ENV
120+
echo "pull_request_id=$PR_ID" >> $GITHUB_ENV
121121
else
122-
echo "No open pull request found for this branch."
122+
echo "No open pull request found for this branch."
123123
fi
124-
- name: find if coverage report is already present
125-
if: env.pull_request_id
126-
uses: peter-evans/find-comment@v3
127-
id: fc
128-
with:
129-
issue-number: ${{ env.pull_request_id }}
130-
comment-author: 'github-actions[bot]'
131-
body-includes: 'go-test-coverage report:'
132124
- name: post coverage report
133125
if: env.pull_request_id
134-
uses: peter-evans/create-or-update-comment@v4
126+
uses: thollander/actions-comment-pull-request@v3
135127
with:
136-
token: ${{ secrets.GITHUB_TOKEN }}
137-
issue-number: ${{ env.pull_request_id }}
138-
comment-id: ${{ steps.fc.outputs.comment-id }}
139-
edit-mode: replace
140-
body: |
128+
github-token: ${{ secrets.GITHUB_TOKEN }}
129+
comment-tag: coverage-report
130+
pr-number: ${{ env.pull_request_id }}
131+
message: |
141132
go-test-coverage report:
142133
```
143-
${{ fromJSON(steps.coverage.outputs.report) }} ```
134+
${{ fromJSON(steps.coverage.outputs.report) }}```
144135
145136
- name: "finally check coverage"
146137
if: steps.coverage.outcome == 'failure'

0 commit comments

Comments
 (0)