Skip to content

Commit 3e0dd25

Browse files
Coverage: Fix and consolidate coverage steps to fix coverage upload
Signed-off-by: Bernhard Kaindl <bernhard.kaindl@cloud.com>
1 parent 01ea603 commit 3e0dd25

File tree

1 file changed

+26
-75
lines changed

1 file changed

+26
-75
lines changed

.github/workflows/main.yml

Lines changed: 26 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ concurrency: # On new workflow, cancel old workflows from the same PR, branch o
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
1515
on: [push, pull_request]
16+
17+
permissions:
18+
contents: read
19+
pull-requests: write
20+
1621
env:
1722
PYTHONWARNINGS: "ignore:DEPRECATION"
1823
PIP_ROOT_USER_ACTION: "ignore" # For local testing using act-cli
@@ -35,6 +40,8 @@ jobs:
3540
- python-version: '3.13'
3641
os: ubuntu-22.04
3742
runs-on: ${{ matrix.os }}
43+
env:
44+
PYTHON_VERSION_USED_FOR_COVERAGE: ${{ '3.11' }}
3845
steps:
3946
- uses: actions/checkout@v4
4047
with:
@@ -50,94 +57,38 @@ jobs:
5057
if: ${{ (github.actor == 'nektos/act' && matrix.python-version != '3.11') }}
5158
run: apt-get update && apt-get install -y cpio
5259

53-
- name: Run of tox on Ubuntu
60+
- name: Run tox to run pytest in the defined tox environments
5461
# Python 3.11 is not supported in the nektos/act container, so we skip this step
5562
if: ${{ !(matrix.python-version == '3.11' && github.actor == 'nektos/act') }}
5663
run: |
5764
pip install tox tox-gh-actions
5865
tox --workdir .github/workflows/.tox --recreate
59-
60-
- name: Select the coverage file for upload
61-
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-
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:
8166
env:
82-
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.
67+
DIFF_COVERAGE_MIN: 0 # Let the reviewdog and codecov show uncovered lines
68+
69+
- uses: aki77/reviewdog-action-code-coverage@v2
70+
continue-on-error: true
8871
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
72+
matrix.python-version == env.PYTHON_VERSION_USED_FOR_COVERAGE &&
73+
!cancelled() && github.event_name == 'pull_request'
9474
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
75+
lcov_path: coverage.lcov
10676

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 }}
77+
- uses: codecov/codecov-action@v5
78+
id: codecov
11179
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
80+
matrix.python-version == env.PYTHON_VERSION_USED_FOR_COVERAGE &&
81+
!cancelled() && github.actor != 'nektos/act'
82+
83+
- uses: codecov/test-results-action@v1
84+
if: steps.codecov.outcome == 'success'
12385

124-
- if: steps.coverage.outcome == 'success'
86+
- if: |
87+
matrix.python-version == env.PYTHON_VERSION_USED_FOR_COVERAGE &&
88+
!cancelled() && github.actor != 'nektos/act'
12589
name: Upload coverage reports to Coveralls
12690
env:
127-
COVERALLS_PARALLEL: true
12891
COVERALLS_FLAG_NAME: ${{ format('python{0}', steps.python.outputs.python-version ) }}
12992
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
13093
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
94+
continue-on-error: true # Coveralls.io is currently overloaded

0 commit comments

Comments
 (0)