Skip to content

Commit 00708ff

Browse files
authored
BUG: Ensure coverage comment is properly triggered (#1901)
I tried to fix this workflow in #1879, but the main CI workflow must first trigger the coverage comment workflow. 🎉 Right, this did it, and the comment is working as expected. I am not super thrilled with the badges' colours, as they have poor contrast (background/text colours), so I might open a PR against the action itself to fix this.
1 parent b18ebb2 commit 00708ff

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

.github/workflows/CI.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ jobs:
205205
with:
206206
pattern: coverage-data-*
207207
merge-multiple: true
208+
208209
- name: "Get coverage data & fail if it's <80%"
209210
run: |
210211
# if we decide to check cov across versions and combine
@@ -216,13 +217,29 @@ jobs:
216217
217218
# report again and fail if under 80%.
218219
python -Im coverage report --fail-under=80
220+
219221
- name: "Upload HTML report if check failed 📤"
220222
uses: actions/upload-artifact@v4
221223
with:
222224
name: html-report
223225
path: htmlcov
224226
if: ${{ failure() }}
225227

228+
# seems we need to call this from the main CI workflow first
229+
- name: "Coverage comment 💬"
230+
uses: py-cov-action/python-coverage-comment-action@v3
231+
id: coverage_comment
232+
with:
233+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
234+
235+
- name: "Store Pull Request comment to be posted 📤"
236+
uses: actions/upload-artifact@v3
237+
if: steps.coverage_comment.outputs.COMMENT_FILE_WRITTEN == 'true'
238+
with:
239+
# leave default names
240+
name: python-coverage-comment-action
241+
path: python-coverage-comment-action.txt
242+
226243
profiling:
227244
needs: [build-site, run-pytest]
228245
runs-on: ubuntu-latest

.github/workflows/coverage.yml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ jobs:
1010
test:
1111
name: "Run tests & display coverage"
1212
runs-on: ubuntu-latest
13+
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success'
1314
permissions:
1415
pull-requests: write
1516
contents: write # needed to edit the comment vs opening multiple ones
@@ -22,13 +23,7 @@ jobs:
2223
route: GET /repos/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}
2324
env:
2425
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25-
- name: "Check if the trigger was a PR event"
26-
run: |
27-
TRIGGER_EVENT=$(echo '${{ steps.get-run.outputs.data }}' | jq -r '.event')
28-
if [[ "$TRIGGER_EVENT" != "pull_request" ]]; then
29-
echo "Workflow was not triggered by a PR, skipping coverage comment."
30-
exit 78 # Exiting with a neutral status
31-
fi
26+
3227
# this needs the .coverage file so we download from the CI workflow artifacts
3328
- name: "Download coverage data 📥"
3429
uses: actions/download-artifact@v4
@@ -37,6 +32,10 @@ jobs:
3732
merge-multiple: true
3833
github-token: ${{ secrets.GITHUB_TOKEN }}
3934
run-id: ${{ github.event.workflow_run.id }}
35+
36+
- name: "Check downloaded files"
37+
run: ls -R
38+
4039
- name: "Post coverage comment"
4140
uses: py-cov-action/python-coverage-comment-action@v3
4241
with:

tox.ini

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ labels =
1919

2020
# general tox env configuration
2121
# these can be run with any py3{9,12} version
22-
# tox run -e py39-lint
22+
# tox run -e py39-lint
2323
[testenv]
2424
deps =
2525
lint: pre-commit
@@ -41,9 +41,11 @@ commands =
4141
# example tox run -e py39-profile-docs -- -o profile.svg -n 100
4242
profile-docs: python ./tools/profile.py {posargs}
4343

44-
# tests can be ran with or without coverage (see examples below), it is recommended to run compile before running tests (see examples below),
44+
# tests can be ran with or without coverage (see examples below),
45+
# it is recommended to run compile before running tests (see examples below),
4546
# tox run -e compile,py39-tests
46-
# if you want to skip the assets compilation step you can run the tests without `compile`
47+
# if you want to skip the assets compilation step you can run the tests without
48+
#`compile`, for example:
4749
# tox run -e py39-tests
4850
# run tests with a specific Sphinx version
4951
# tox run -e compile,py39-sphinx61-tests

0 commit comments

Comments
 (0)