Created
May 19, 2026 14:55
-
-
Save imaitland/1f82c1837450f627239f4223984f5fa4 to your computer and use it in GitHub Desktop.
Run codecov as a github action - sans external services
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Update Coverage Badge | |
| on: | |
| push: | |
| branches: [main] | |
| paths-ignore: | |
| - 'README.md' | |
| - 'pytest.xml' | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| update-badge: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Python 3.10 | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.10' | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v4 | |
| with: | |
| enable-cache: true | |
| - name: Install dependencies | |
| run: uv sync --dev | |
| - name: Run tests with coverage | |
| run: | | |
| uv run pytest --junitxml=pytest.xml --cov-report=term-missing:skip-covered --cov=. | tee pytest-coverage.txt | |
| - name: Coverage comment | |
| id: coverage | |
| uses: MishaKav/pytest-coverage-comment@main | |
| with: | |
| pytest-coverage-path: ./pytest-coverage.txt | |
| junitxml-path: ./pytest.xml | |
| hide-comment: true | |
| - name: Update README | |
| run: | | |
| sed -i '/<!-- Pytest Coverage Comment:Begin -->/,/<!-- Pytest Coverage Comment:End -->/c\<!-- Pytest Coverage Comment:Begin -->\n${{ steps.coverage.outputs.coverageHtml }}\n<!-- Pytest Coverage Comment:End -->' ./README.md | |
| - name: Create Pull Request | |
| uses: peter-evans/create-pull-request@v6 | |
| with: | |
| commit-message: 'docs: update coverage badge' | |
| title: 'Update coverage badge' | |
| body: 'Automated coverage badge update from test run' | |
| branch: update-coverage-badge | |
| delete-branch: true |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This action runs codecov, and makes a change to the project's
README.md. It submits this change as a PR. The change consists of a code report (e.g. uncovered lines, coverage percent), and a badge.There is a gotcha - merging the PR created by the action can be tricky if you have other actions that must report a 'pass' status on PRs in order for them to be eligible for merge. Generally PRs created by actions don't trigger downstream actions in order to prevent recursive (and therefore potentially expensive) action workflows...
This gotcha seems like it should be resolvable using one of the following workarounds, ideally one that can be incorporated inside this action itself...