Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions .github/workflows/upload_coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Upload coverage

on:
workflow_call:
inputs:
fail-on-coverage-error:
required: false
type: boolean
default: true
description: Fail if codecov action fails.
artifact-pattern:
required: false
type: string
default: covreport-*
description: >
glob pattern to the artifacts that should be downloaded for coverage reports.
This should match the `name` you used for the `upload-artifact` step in the
job that generates the coverage reports.
(*This default matches the name in test-pyrepo.yml*)
secrets:
codecov_token:
required: false
description: Token for codecov-action.

jobs:
upload_coverage:
name: Upload coverage
runs-on: ubuntu-latest
steps:

- name: Checkout ${{ github.repository }}
uses: actions/checkout@v5

- name: Install the latest version of uv
uses: astral-sh/setup-uv@v6
with:
version: "latest"
python-version: '3.12'
activate-environment: true

- name: Install coverage
run: uv pip install coverage

- name: Download coverage data
uses: actions/download-artifact@v5
with:
pattern: ${{ inputs.artifact-pattern }}
path: covreports
merge-multiple: true

- name: Combine coverage data
run: |
REPO_NAME="${GITHUB_REPOSITORY##*/}"
echo "[paths]" > ci_coveragerc
echo "source =" >> ci_coveragerc
# if src exists, add it to the pathmap
if [ -d "src" ]; then
echo " src/" >> ci_coveragerc
echo " D:\\a\\$REPO_NAME\\$REPO_NAME\\src" >> ci_coveragerc
echo " /home/runner/work/$REPO_NAME/$REPO_NAME/src" >> ci_coveragerc
echo " /Users/runner/work/$REPO_NAME/$REPO_NAME/src" >> ci_coveragerc
else
echo " ${GITHUB_WORKSPACE}" >> ci_coveragerc
echo " D:\\a\\$REPO_NAME\\$REPO_NAME" >> ci_coveragerc
echo " /home/runner/work/$REPO_NAME/$REPO_NAME" >> ci_coveragerc
echo " /Users/runner/work/$REPO_NAME/$REPO_NAME" >> ci_coveragerc
fi
echo " */site-packages/" >> ci_coveragerc
cat ci_coveragerc
python -Im coverage combine --rcfile=ci_coveragerc covreports
python -Im coverage xml -o coverage.xml
python -Im coverage report
python -Im coverage report --format=markdown --skip-empty --skip-covered >> $GITHUB_STEP_SUMMARY

- name: Upload to codecov
uses: codecov/codecov-action@v5
with:
fail_ci_if_error: ${{ inputs.fail-on-coverage-error }}
verbose: true
token: ${{ secrets.CODECOV_TOKEN }}