Skip to content

Commit 6c998fb

Browse files
committed
Add Codecov step to CI
1 parent 108f448 commit 6c998fb

File tree

1 file changed

+16
-105
lines changed

1 file changed

+16
-105
lines changed

.github/workflows/ci.yml

Lines changed: 16 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,9 @@ jobs:
8080
cd src
8181
python --version # just to make sure we're running the right one
8282
# Run tests under coverage
83-
export COVERAGE_FILE=.coverage_${{ matrix.python-version }}
8483
python -m coverage run -m unittest test_typing_extensions.py
84+
# Create xml file for Codecov
85+
coverage xml --rcfile=../pyproject.toml --fail-under=0
8586
- name: Test typing_extensions no coverage on pypy
8687
if: ${{ startsWith(matrix.python-version, 'pypy') }}
8788
run: |
@@ -91,15 +92,6 @@ jobs:
9192
python --version # just to make sure we're running the right one
9293
python -m unittest test_typing_extensions.py
9394
94-
- name: Archive code coverage results
95-
id: archive-coverage
96-
if: ${{ !startsWith(matrix.python-version, 'pypy') }}
97-
uses: actions/upload-artifact@v4
98-
with:
99-
name: .coverage_${{ matrix.python-version }}
100-
path: ./src/.coverage*
101-
include-hidden-files: true
102-
compression-level: 0 # no compression
10395
- name: Test CPython typing test suite
10496
# Test suite fails on PyPy even without typing_extensions
10597
if: ${{ !startsWith(matrix.python-version, 'pypy') }}
@@ -108,9 +100,20 @@ jobs:
108100
# Run the typing test suite from CPython with typing_extensions installed,
109101
# because we monkeypatch typing under some circumstances.
110102
python -c 'import typing_extensions; import test.__main__' test_typing -v
111-
outputs:
112-
# report if coverage was uploaded
113-
cov_uploaded: ${{ steps.archive-coverage.outputs.artifact-id }}
103+
104+
- name: Upload coverage reports to Codecov
105+
uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7
106+
if: >-
107+
${{
108+
!startsWith(matrix.python-version, 'pypy')
109+
&& (github.event_name == 'push' || github.event_name == 'pull_request')
110+
}}
111+
with:
112+
token: ${{ secrets.CODECOV_ORG_TOKEN }}
113+
flags: ${{ matrix.python-version }}
114+
directory: src
115+
fail_ci_if_error: true
116+
verbose: true
114117

115118
create-issue-on-failure:
116119
name: Create an issue if daily tests failed
@@ -140,95 +143,3 @@ jobs:
140143
title: `Daily tests failed on ${new Date().toDateString()}`,
141144
body: "Runs listed here: https://github.com/python/typing_extensions/actions/workflows/ci.yml",
142145
})
143-
144-
report-coverage:
145-
name: Report coverage
146-
147-
runs-on: ubuntu-latest
148-
149-
needs: [tests]
150-
151-
permissions:
152-
pull-requests: write
153-
154-
# Job will run even if tests failed but only if at least one artifact was uploaded
155-
if: ${{ always() && needs.tests.outputs.cov_uploaded != '' }}
156-
157-
steps:
158-
- uses: actions/checkout@v4
159-
with:
160-
persist-credentials: false
161-
- name: Set up Python
162-
uses: actions/setup-python@v5
163-
with:
164-
python-version: "3"
165-
- name: Download coverage artifacts
166-
uses: actions/download-artifact@v4
167-
with:
168-
pattern: .coverage_*
169-
path: .
170-
# merge only when files are named differently
171-
merge-multiple: true
172-
- name: Install dependencies
173-
run: pip install coverage
174-
- name: Combine coverage results
175-
run: |
176-
# List the files to see what we have
177-
echo "Combining coverage files..."
178-
ls -aR .coverage*
179-
coverage combine .coverage*
180-
echo "Creating coverage report..."
181-
# Create xml file for further processing; Create even if below minimum
182-
coverage xml --fail-under=0
183-
# Write markdown report to job summary
184-
coverage report --fail-under=0 --format=markdown -m >> "$GITHUB_STEP_SUMMARY"
185-
186-
# For future use in case we want to add a PR comment for 3rd party PRs which requires
187-
# a workflow with elevated PR write permissions. Move below steps into a separate job.
188-
- name: Archive code coverage report
189-
id: cov_xml_upload
190-
uses: actions/upload-artifact@v4
191-
with:
192-
name: coverage
193-
path: coverage.xml
194-
- name: Code Coverage Report (console)
195-
run: |
196-
# Create a coverage report (console), respects fail_under in pyproject.toml
197-
coverage report
198-
199-
- name: Code Coverage Report
200-
uses: irongut/CodeCoverageSummary@51cc3a756ddcd398d447c044c02cb6aa83fdae95 # v1.3.0
201-
# Create markdown file even if coverage report fails due to fail_under
202-
if: ${{ always() && steps.cov_xml_upload.outputs.artifact-id != '' }}
203-
with:
204-
filename: coverage.xml
205-
badge: true
206-
fail_below_min: true
207-
format: markdown
208-
hide_branch_rate: false
209-
hide_complexity: true
210-
indicators: true
211-
output: both # console, file or both
212-
# Note: it appears fail below min is one off, use fail_under -1 here
213-
thresholds: '95 98'
214-
215-
- name: Add link to report badge
216-
if: ${{ always() && steps.cov_xml_upload.outputs.artifact-id != '' }}
217-
run: |
218-
run_url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}?pr=${{ github.event.pull_request.number }}"
219-
sed -i "1s|^\(!.*\)$|[\1]($run_url)|" code-coverage-results.md
220-
221-
- name: Add Coverage PR Comment
222-
uses: marocchino/sticky-pull-request-comment@52423e01640425a022ef5fd42c6fb5f633a02728 # v2.9.3
223-
# Create PR comment when the branch is on the repo, otherwise we lack PR write permissions
224-
# -> need another workflow with access to secret token
225-
if: >-
226-
${{
227-
always()
228-
&& github.event_name == 'pull_request'
229-
&& github.event.pull_request.head.repo.full_name == github.repository
230-
&& steps.cov_xml_upload.outputs.artifact-id != ''
231-
}}
232-
with:
233-
hide_and_recreate: true
234-
path: code-coverage-results.md

0 commit comments

Comments
 (0)