6868
6969 - name : Install coverage
7070 run : |
71- # Be wary that this does not install typing_extensions in the future
72- pip install coverage
71+ # Be wary that this does not install typing_extensions in the future.
72+ # 'toml' extra is needed to read settings from pyproject.toml on Python <3.11
73+ pip install 'coverage[toml]'
7374
7475 - name : Test typing_extensions with coverage
7576 run : |
@@ -78,17 +79,10 @@ jobs:
7879 cd src
7980 python --version # just to make sure we're running the right one
8081 # Run tests under coverage
81- export COVERAGE_FILE=.coverage_${{ matrix.python-version }}
8282 python -m coverage run -m unittest test_typing_extensions.py
83+ # Create xml file for Codecov
84+ coverage xml --rcfile=../pyproject.toml --fail-under=0
8385
84- - name : Archive code coverage results
85- id : archive-coverage
86- uses : actions/upload-artifact@v4
87- with :
88- name : .coverage_${{ matrix.python-version }}
89- path : ./src/.coverage*
90- include-hidden-files : true
91- compression-level : 0 # no compression
9286 - name : Test CPython typing test suite
9387 # Test suite fails on PyPy even without typing_extensions
9488 if : ${{ !startsWith(matrix.python-version, 'pypy') }}
9791 # Run the typing test suite from CPython with typing_extensions installed,
9892 # because we monkeypatch typing under some circumstances.
9993 python -c 'import typing_extensions; import test.__main__' test_typing -v
100- outputs :
101- # report if coverage was uploaded
102- cov_uploaded : ${{ steps.archive-coverage.outputs.artifact-id }}
94+
95+ - name : Upload coverage reports to Codecov
96+ uses : codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7
97+ if : ${{ (github.event_name == 'push' || github.event_name == 'pull_request') }}
98+ with :
99+ token : ${{ secrets.CODECOV_ORG_TOKEN }}
100+ flags : ${{ matrix.python-version }}
101+ directory : src
102+ fail_ci_if_error : true
103+ verbose : true
103104
104105 create-issue-on-failure :
105106 name : Create an issue if daily tests failed
@@ -129,95 +130,3 @@ jobs:
129130 title: `Daily tests failed on ${new Date().toDateString()}`,
130131 body: "Runs listed here: https://github.com/python/typing_extensions/actions/workflows/ci.yml",
131132 })
132-
133- report-coverage :
134- name : Report coverage
135-
136- runs-on : ubuntu-latest
137-
138- needs : [tests]
139-
140- permissions :
141- pull-requests : write
142-
143- # Job will run even if tests failed but only if at least one artifact was uploaded
144- if : ${{ always() && needs.tests.outputs.cov_uploaded != '' }}
145-
146- steps :
147- - uses : actions/checkout@v4
148- with :
149- persist-credentials : false
150- - name : Set up Python
151- uses : actions/setup-python@v5
152- with :
153- python-version : " 3"
154- - name : Download coverage artifacts
155- uses : actions/download-artifact@v4
156- with :
157- pattern : .coverage_*
158- path : .
159- # merge only when files are named differently
160- merge-multiple : true
161- - name : Install dependencies
162- run : pip install coverage
163- - name : Combine coverage results
164- run : |
165- # List the files to see what we have
166- echo "Combining coverage files..."
167- ls -aR .coverage*
168- coverage combine .coverage*
169- echo "Creating coverage report..."
170- # Create xml file for further processing; Create even if below minimum
171- coverage xml --fail-under=0
172- # Write markdown report to job summary
173- coverage report --fail-under=0 --format=markdown -m >> "$GITHUB_STEP_SUMMARY"
174-
175- # For future use in case we want to add a PR comment for 3rd party PRs which requires
176- # a workflow with elevated PR write permissions. Move below steps into a separate job.
177- - name : Archive code coverage report
178- id : cov_xml_upload
179- uses : actions/upload-artifact@v4
180- with :
181- name : coverage
182- path : coverage.xml
183- - name : Code Coverage Report (console)
184- run : |
185- # Create a coverage report (console), respects fail_under in pyproject.toml
186- coverage report
187-
188- - name : Code Coverage Report
189- uses : irongut/CodeCoverageSummary@51cc3a756ddcd398d447c044c02cb6aa83fdae95 # v1.3.0
190- # Create markdown file even if coverage report fails due to fail_under
191- if : ${{ always() && steps.cov_xml_upload.outputs.artifact-id != '' }}
192- with :
193- filename : coverage.xml
194- badge : true
195- fail_below_min : true
196- format : markdown
197- hide_branch_rate : false
198- hide_complexity : true
199- indicators : true
200- output : both # console, file or both
201- # Note: it appears fail below min is one off, use fail_under -1 here
202- thresholds : ' 95 98'
203-
204- - name : Add link to report badge
205- if : ${{ always() && steps.cov_xml_upload.outputs.artifact-id != '' }}
206- run : |
207- run_url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}?pr=${{ github.event.pull_request.number }}"
208- sed -i "1s|^\(!.*\)$|[\1]($run_url)|" code-coverage-results.md
209-
210- - name : Add Coverage PR Comment
211- uses : marocchino/sticky-pull-request-comment@52423e01640425a022ef5fd42c6fb5f633a02728 # v2.9.3
212- # Create PR comment when the branch is on the repo, otherwise we lack PR write permissions
213- # -> need another workflow with access to secret token
214- if : >-
215- ${{
216- always()
217- && github.event_name == 'pull_request'
218- && github.event.pull_request.head.repo.full_name == github.repository
219- && steps.cov_xml_upload.outputs.artifact-id != ''
220- }}
221- with :
222- hide_and_recreate : true
223- path : code-coverage-results.md
0 commit comments