Skip to content

Commit b41735a

Browse files
committed
Upload xml and create markdown downstream, get PR number via API
1 parent 26ace2b commit b41735a

2 files changed

Lines changed: 46 additions & 53 deletions

File tree

.github/workflows/ci.yml

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -171,34 +171,14 @@ jobs:
171171
ls -aR .coverage*
172172
coverage combine .coverage*
173173
echo "Creating coverage report..."
174+
# print output
174175
coverage report
176+
# Create xml for comment
175177
coverage xml
176178
177-
- name: Code Coverage Report
178-
uses: irongut/CodeCoverageSummary@51cc3a756ddcd398d447c044c02cb6aa83fdae95 # v1.3.0
179-
with:
180-
filename: coverage.xml
181-
badge: true
182-
fail_below_min: false
183-
format: markdown
184-
hide_branch_rate: false
185-
hide_complexity: true
186-
indicators: true
187-
output: both
188-
thresholds: '80 90'
189-
190179
- name: Archive code coverage report
191180
uses: actions/upload-artifact@v4
192181
with:
193-
name: code-coverage-results.md
194-
path: code-coverage-results.md
195-
compression-level: 0 # no compression
196-
- name: Save PR number for coverage report
197-
run: |
198-
echo ${{ github.event.number }} > ./pr_number.txt
199-
- uses: actions/upload-artifact@v4
200-
continue-on-error: true
201-
with:
202-
name: pr_number
203-
path: pr_number.txt
204-
compression-level: 0 # no compression
182+
name: coverage.xml
183+
path: coverage.xml
184+
compression-level: 0 # no compression
Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
name: Add coverage comment on PR
22

3-
# read-write repo token
4-
# access to secrets
53
on:
64
workflow_run:
75
workflows: ["Test and lint"]
86
types:
97
- completed
10-
8+
119
permissions: {}
1210

1311
jobs:
@@ -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

Comments
 (0)