Skip to content

Commit b3baf8d

Browse files
Coverage: Fix and consolidate coverage steps to fix coverage upload
Signed-off-by: Bernhard Kaindl <[email protected]>
1 parent 90e3143 commit b3baf8d

File tree

1 file changed

+44
-72
lines changed

1 file changed

+44
-72
lines changed

.github/workflows/main.yml

Lines changed: 44 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@ concurrency: # On new workflow, cancel old workflows from the same PR, branch o
1212
# Checks can be skipped by adding "skip-checks: true" to a commit message,
1313
# or requested by adding "request-checks: true" if disabled by default for pushes:
1414
# https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/collaborating-on-repositories-with-code-quality-features/about-status-checks#skipping-and-requesting-checks-for-individual-commits
15-
on: [push, pull_request]
15+
on:
16+
push:
17+
pull_request:
18+
types: [opened, synchronize, reopened]
19+
20+
permissions:
21+
contents: read
22+
pull-requests: write
23+
1624
env:
1725
PYTHONWARNINGS: "ignore:DEPRECATION"
1826
PIP_ROOT_USER_ACTION: "ignore" # For local testing using act-cli
@@ -35,6 +43,8 @@ jobs:
3543
- python-version: '3.13'
3644
os: ubuntu-22.04
3745
runs-on: ${{ matrix.os }}
46+
env:
47+
PYTHON_VERSION_USED_FOR_COVERAGE: ${{ '3.11' }}
3848
steps:
3949
- uses: actions/checkout@v4
4050
with:
@@ -50,94 +60,56 @@ jobs:
5060
if: ${{ (github.actor == 'nektos/act' && matrix.python-version != '3.11') }}
5161
run: apt-get update && apt-get install -y cpio
5262

53-
- name: Run of tox on Ubuntu
63+
- name: Run tox to run pytest in the defined tox environments
5464
# Python 3.11 is not supported in the nektos/act container, so we skip this step
5565
if: ${{ !(matrix.python-version == '3.11' && github.actor == 'nektos/act') }}
5666
run: |
5767
pip install tox tox-gh-actions
5868
tox --workdir .github/workflows/.tox --recreate
69+
env:
70+
DIFF_COVERAGE_MIN: 0 # Let the reviewdog and codecov show uncovered lines
5971

60-
- name: Select the coverage file for upload
72+
- uses: aki77/reviewdog-action-code-coverage@v2
73+
continue-on-error: true
6174
if: |
62-
matrix.python-version == '3.11' &&
63-
( !cancelled() && github.actor != 'nektos/act' )
64-
id: coverage
65-
run: mv $( ls -t .github/workflows/.tox/*/log/.coverage | head -1 ) .coverage
66-
67-
# The new reliable Codecov upload requires Codecov to query the GitHub API to check
68-
# the repo and the commit. The repo (or organisation) owner needs to login to
69-
# codecov, generated the CODECOV_TOKEN and save it as a secret in the ORG or the repo:
70-
# https://docs.codecov.com/docs/adding-the-codecov-token
71-
72-
# Links to get and set the token:
73-
# Get the CODECOV_TOKEN: https://app.codecov.io/gh/xenserver/python-libs/settings
74-
# Set the CODE_COV_TOKEN: https://github.com/xenserver/python-libs/settings/secrets/actions
75+
matrix.python-version == env.PYTHON_VERSION_USED_FOR_COVERAGE &&
76+
!cancelled() && github.event_name == 'pull_request' &&
77+
vars.REVIEWDOG_PR_REVIEW_TOKEN
78+
with:
79+
lcov_path: coverage.lcov
80+
github_token: ${{ vars.REVIEWDOG_PR_REVIEW_TOKEN }}
7581

76-
# Without it, the API calls are rate-limited by GitHub, and the upload may fail:
77-
# https://github.com/codecov/feedback/issues/126#issuecomment-1932658904
78-
#
79-
- name: Upload coverage reports to Codecov (fallback, legacy Node.js 16 action)
80-
# If CODECOV_TOKEN is not set, use the legacy tokenless Codecov action:
82+
- name: Upload coverage reports to Codecov using secret token
83+
id: codecov_sec
8184
env:
8285
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
83-
# To reduce chances of GitHub's API throttling to hit this upload, only run the
84-
# upload for the py38-covcombine-check job running on Ubuntu-20.04, which is the
85-
# one we need. And only run it for PRs and the master branch, not for pushes.
86-
# This reduces the number of uploads and the chance of hitting the rate limit
87-
# by a factor of 6.
8886
if: |
89-
steps.coverage.outcome == 'success' &&
90-
!env.CODECOV_TOKEN && !cancelled() &&
91-
matrix.os == 'ubuntu-20.04' && github.actor != 'nektos/act' &&
92-
( github.event.pull_request.number || github.ref == 'refs/heads/master' )
93-
uses: codecov/codecov-action@v3
87+
matrix.python-version == env.PYTHON_VERSION_USED_FOR_COVERAGE &&
88+
!cancelled() && github.actor != 'nektos/act' && env.CODECOV_TOKEN
89+
uses: codecov/codecov-action@v5
9490
with:
95-
directory: .github/workflows/.tox/py38-covcombine-check/log
96-
env_vars: OS,PYTHON
97-
# Use fail_ci_if_error: false as explained the big comment above:
98-
# Not failing this job in this case is ok because the tox CI checks also contain
99-
# a diff-cover check which would fail on changed lines missing coverage.
100-
# The Codecov CLI is more reliable and should be used if the CODECOV_TOKEN is set.
101-
# The Codecov CLI is used in the next step when CODECOV_TOKEN is set.
102-
fail_ci_if_error: false
103-
flags: unittest
104-
name: py27-py38-combined
105-
verbose: true
91+
token: ${{ secrets.CODECOV_TOKEN }}
10692

107-
- name: Upload coverage reports to Codecov (used when secrets.CODECOV_TOKEN is set)
108-
# If CODECOV_TOKEN is set, use the new Codecov CLI to upload the coverage reports
109-
env:
110-
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
93+
- name: Upload coverage reports to Codecov
94+
id: codecov
11195
if: |
112-
env.CODECOV_TOKEN && !cancelled() && github.actor != 'nektos/act' &&
113-
steps.coverage.outcome == 'success' && matrix.os == 'ubuntu-20.04'
114-
run: >
115-
set -euxv;
116-
mv .github/workflows/.tox/py38-covcombine-check/log/coverage.xml cov.xml;
117-
curl -O https://cli.codecov.io/latest/linux/codecov; sudo chmod +x codecov;
118-
./codecov upload-process --report-type coverage
119-
--name "CLI Upload for ${{ env.PYTHON_VERSION }}"
120-
--git-service github --fail-on-error --file cov.xml --disable-search
121-
--flag python${{ env.PYTHON_VERSION }}
122-
continue-on-error: false # Fail the job if the upload with CODECOV_TOKEN fails
96+
matrix.python-version == env.PYTHON_VERSION_USED_FOR_COVERAGE &&
97+
!cancelled() && github.actor != 'nektos/act' && vars.CODECOV_TOKEN
98+
uses: codecov/codecov-action@v5
99+
with:
100+
token: ${{ vars.CODECOV_TOKEN }}
101+
102+
- uses: codecov/test-results-action@v1
103+
if: ${{ steps.codecov.outcome == 'success' || steps.codecov_sec.outcome == 'success' }}
104+
with:
105+
token: ${{ vars.CODECOV_TOKEN }}
123106

124-
- if: steps.coverage.outcome == 'success'
107+
- if: |
108+
matrix.python-version == env.PYTHON_VERSION_USED_FOR_COVERAGE &&
109+
!cancelled() && github.actor != 'nektos/act'
125110
name: Upload coverage reports to Coveralls
126111
env:
127-
COVERALLS_PARALLEL: true
128112
COVERALLS_FLAG_NAME: ${{ format('python{0}', steps.python.outputs.python-version ) }}
129113
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
130114
run: pip install coveralls && coveralls --service=github
131-
132-
# For combined coverage of 2.7, 3.8 and 3.11 we upload to Coveralls in parallel mode.
133-
# To view the Coveralls results from the PR, click on the "Details" link to the right
134-
# of the Coveralls Logo in the Checks section of the PR.
135-
finish-coverage-upload:
136-
if: github.actor != 'nektos/act'
137-
needs: test
138-
runs-on: ubuntu-latest
139-
steps:
140-
- name: Finish the coverage upload to Coveralls
141-
uses: coverallsapp/github-action@v1
142-
with:
143-
parallel-finished: true
115+
continue-on-error: true # Coveralls.io is currently overloaded

0 commit comments

Comments
 (0)