Skip to content

Commit

Permalink
BUG: Ensure coverage comment is properly triggered (#1901)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
trallard authored Jun 27, 2024
1 parent b18ebb2 commit 00708ff
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ jobs:
with:
pattern: coverage-data-*
merge-multiple: true

- name: "Get coverage data & fail if it's <80%"
run: |
# if we decide to check cov across versions and combine
Expand All @@ -216,13 +217,29 @@ jobs:
# report again and fail if under 80%.
python -Im coverage report --fail-under=80
- name: "Upload HTML report if check failed 📤"
uses: actions/upload-artifact@v4
with:
name: html-report
path: htmlcov
if: ${{ failure() }}

# seems we need to call this from the main CI workflow first
- name: "Coverage comment 💬"
uses: py-cov-action/python-coverage-comment-action@v3
id: coverage_comment
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: "Store Pull Request comment to be posted 📤"
uses: actions/upload-artifact@v3
if: steps.coverage_comment.outputs.COMMENT_FILE_WRITTEN == 'true'
with:
# leave default names
name: python-coverage-comment-action
path: python-coverage-comment-action.txt

profiling:
needs: [build-site, run-pytest]
runs-on: ubuntu-latest
Expand Down
13 changes: 6 additions & 7 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ jobs:
test:
name: "Run tests & display coverage"
runs-on: ubuntu-latest
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success'
permissions:
pull-requests: write
contents: write # needed to edit the comment vs opening multiple ones
Expand All @@ -22,13 +23,7 @@ jobs:
route: GET /repos/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: "Check if the trigger was a PR event"
run: |
TRIGGER_EVENT=$(echo '${{ steps.get-run.outputs.data }}' | jq -r '.event')
if [[ "$TRIGGER_EVENT" != "pull_request" ]]; then
echo "Workflow was not triggered by a PR, skipping coverage comment."
exit 78 # Exiting with a neutral status
fi

# this needs the .coverage file so we download from the CI workflow artifacts
- name: "Download coverage data 📥"
uses: actions/download-artifact@v4
Expand All @@ -37,6 +32,10 @@ jobs:
merge-multiple: true
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ github.event.workflow_run.id }}

- name: "Check downloaded files"
run: ls -R

- name: "Post coverage comment"
uses: py-cov-action/python-coverage-comment-action@v3
with:
Expand Down
8 changes: 5 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ labels =

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

# tests can be ran with or without coverage (see examples below), it is recommended to run compile before running tests (see examples below),
# tests can be ran with or without coverage (see examples below),
# it is recommended to run compile before running tests (see examples below),
# tox run -e compile,py39-tests
# if you want to skip the assets compilation step you can run the tests without `compile`
# if you want to skip the assets compilation step you can run the tests without
#`compile`, for example:
# tox run -e py39-tests
# run tests with a specific Sphinx version
# tox run -e compile,py39-sphinx61-tests
Expand Down

0 comments on commit 00708ff

Please sign in to comment.