Skip to content

Commit ee8f319

Browse files
committed
rework pr comment with workflow_run
1 parent 5bbafa0 commit ee8f319

File tree

2 files changed

+90
-60
lines changed

2 files changed

+90
-60
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,17 @@ jobs:
9999
path: ./src/.coverage*
100100
include-hidden-files: true
101101
compression-level: 0 # no compression
102+
103+
- name: Save PR number for coverage report
104+
if: ${{ !startsWith(matrix.python-version, 'pypy') }}
105+
run: |
106+
mkdir -p ./pr
107+
echo ${{ github.event.number }} > ./pr/NR
108+
- uses: actions/upload-artifact@v4
109+
if: ${{ !startsWith(matrix.python-version, 'pypy') }}
110+
with:
111+
name: pr
112+
path: pr/
102113

103114
- name: Test CPython typing test suite
104115
# Test suite fails on PyPy even without typing_extensions
@@ -136,63 +147,4 @@ jobs:
136147
repo: "typing_extensions",
137148
title: `Daily tests failed on ${new Date().toDateString()}`,
138149
body: "Runs listed here: https://github.com/python/typing_extensions/actions/workflows/ci.yml",
139-
})
140-
141-
report-coverage:
142-
name: Report coverage
143-
144-
runs-on: ubuntu-latest
145-
146-
needs: [tests]
147-
permissions:
148-
contents: read
149-
pull-requests: write
150-
151-
if: ${{ always() }}
152-
153-
steps:
154-
- uses: actions/checkout@v4
155-
with:
156-
persist-credentials: false
157-
- name: Set up Python
158-
uses: actions/setup-python@v5
159-
with:
160-
python-version: "3"
161-
- name: Download coverage artifacts
162-
uses: actions/download-artifact@v4
163-
with:
164-
pattern: .coverage_*
165-
path: .
166-
# merge only when files are named differently
167-
merge-multiple: true
168-
- name: Install dependencies
169-
run: pip install coverage
170-
- name: Combine coverage results
171-
run: |
172-
# List the files to see what we have
173-
echo "Combining coverage files..."
174-
ls -aR .coverage*
175-
coverage combine .coverage*
176-
echo "Creating coverage report..."
177-
coverage report
178-
coverage xml
179-
180-
- name: Code Coverage Report
181-
uses: irongut/CodeCoverageSummary@51cc3a756ddcd398d447c044c02cb6aa83fdae95 # v1.3.0
182-
with:
183-
filename: coverage.xml
184-
badge: true
185-
fail_below_min: false
186-
format: markdown
187-
hide_branch_rate: false
188-
hide_complexity: true
189-
indicators: true
190-
output: both
191-
thresholds: '80 90'
192-
193-
- name: Add Coverage PR Comment
194-
uses: marocchino/sticky-pull-request-comment@52423e01640425a022ef5fd42c6fb5f633a02728 # v2.9.3
195-
if: github.event_name == 'pull_request'
196-
with:
197-
recreate: true
198-
path: code-coverage-results.md
150+
})
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Comment on the pull request
2+
3+
# read-write repo token
4+
# access to secrets
5+
on:
6+
workflow_run:
7+
workflows: ["Test and lint"]
8+
types:
9+
- completed
10+
11+
jobs:
12+
upload:
13+
runs-on: ubuntu-latest
14+
if: >
15+
github.event.workflow_run.event == 'pull_request'
16+
steps:
17+
- name: Download PR number
18+
uses: actions/download-artifact@v4
19+
with:
20+
pattern: pr
21+
path: .
22+
# merge only when files are named differently
23+
github-token: ${{ secrets.GITHUB_TOKEN }}
24+
run-id: ${{ github.event.workflow_run.id }}
25+
- name: Extract PR number
26+
id: pr_number
27+
run: |
28+
echo "PR number is:"
29+
cat pr/NR
30+
echo "pr_number=$(cat pr/NR)" >> $GITHUB_ENV
31+
- uses: actions/checkout@v4
32+
with:
33+
persist-credentials: false
34+
- name: Set up Python
35+
uses: actions/setup-python@v5
36+
with:
37+
python-version: "3"
38+
- name: Download coverage artifacts
39+
uses: actions/download-artifact@v4
40+
with:
41+
pattern: .coverage_*
42+
path: .
43+
# merge only when files are named differently
44+
merge-multiple: true
45+
github-token: ${{ secrets.GITHUB_TOKEN }}
46+
run-id: ${{ github.event.workflow_run.id }}
47+
- name: Install dependencies
48+
run: pip install coverage
49+
- name: Combine coverage results
50+
run: |
51+
# List the files to see what we have
52+
echo "Combining coverage files..."
53+
ls -aR .coverage*
54+
coverage combine .coverage*
55+
echo "Creating coverage report..."
56+
coverage report
57+
coverage xml
58+
59+
- name: Code Coverage Report
60+
uses: irongut/CodeCoverageSummary@51cc3a756ddcd398d447c044c02cb6aa83fdae95 # v1.3.0
61+
with:
62+
filename: coverage.xml
63+
badge: true
64+
fail_below_min: false
65+
format: markdown
66+
hide_branch_rate: false
67+
hide_complexity: true
68+
indicators: true
69+
output: both
70+
thresholds: '80 90'
71+
72+
- name: Add Coverage PR Comment
73+
uses: marocchino/sticky-pull-request-comment@52423e01640425a022ef5fd42c6fb5f633a02728 # v2.9.3
74+
if: github.event_name == 'pull_request'
75+
with:
76+
recreate: true
77+
path: code-coverage-results.md
78+
number: ${{ env.pr_number }}

0 commit comments

Comments
 (0)