11name : Add coverage comment on PR
22
3- # read-write repo token
4- # access to secrets
53on :
64 workflow_run :
75 workflows : ["Test and lint"]
86 types :
97 - completed
10-
8+
119permissions : {}
1210
1311jobs :
@@ -16,31 +14,46 @@ jobs:
1614 contents : read
1715 pull-requests : write
1816 runs-on : ubuntu-latest
17+ # && github.repository == github.event.workflow_run.repository.full_name
1918 if : >
2019 github.event.workflow_run.event == 'pull_request'
2120 steps :
22- - name : Download PR number
23- uses : actions/download-artifact@v4
24- with :
25- pattern : pr_number
26- path : .
27- github-token : ${{ secrets.GITHUB_TOKEN }}
28- run-id : ${{ github.event.workflow_run.id }}
29- - name : Extract PR number
30- run : |
31- echo "Triggering PR number is:"
32- cat pr_number/pr_number.txt
33- export "pr_number=$(cat pr_number/pr_number.txt)"
34- - name : Download coverage report
35- uses : actions/download-artifact@v4
36- with :
37- pattern : code-coverage-results.md
38- github-token : ${{ secrets.GITHUB_TOKEN }}
39- run-id : ${{ github.event.workflow_run.id }}
40- - name : Add Coverage PR Comment
41- uses : marocchino/sticky-pull-request-comment@52423e01640425a022ef5fd42c6fb5f633a02728 # v2.9.3
42- with :
43- recreate : true
44- path : code-coverage-results.md
45- number : ${{ env.pr_number }}
46- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
21+ - name : Get PR number from commit SHA
22+ id : get_pr
23+ env :
24+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
25+ run : |
26+ SHA="${{ github.event.workflow_run.head_sha }}"
27+ REPO="${{ github.repository }}"
28+ PR_DATA=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
29+ "https://api.github.com/repos/$REPO/commits/$SHA/pulls" \
30+ -H "Accept: application/vnd.github.groot-preview+json")
31+ echo "$PR_DATA"
32+ PR_NUMBER=$(echo "$PR_DATA" | jq '.[0].number')
33+ echo "PR number is $PR_NUMBER"
34+ echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT
35+ - name : Download coverage report
36+ uses : actions/download-artifact@v4
37+ with :
38+ pattern : coverage.xml
39+ github-token : ${{ secrets.GITHUB_TOKEN }}
40+ run-id : ${{ github.event.workflow_run.id }}
41+ - name : Code Coverage Report
42+ uses : irongut/CodeCoverageSummary@51cc3a756ddcd398d447c044c02cb6aa83fdae95 # v1.3.0
43+ with :
44+ filename : coverage.xml
45+ badge : true
46+ fail_below_min : false
47+ format : markdown
48+ hide_branch_rate : false
49+ hide_complexity : true
50+ indicators : true
51+ output : both
52+ thresholds : ' 80 90'
53+ - name : Add Coverage PR Comment
54+ uses : marocchino/sticky-pull-request-comment@52423e01640425a022ef5fd42c6fb5f633a02728 # v2.9.3
55+ with :
56+ recreate : true
57+ path : code-coverage-results.md
58+ number : ${{ steps.get_pr.outputs.pr_number }}
59+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments