From 2b0684440f41f4f6b326cffc2d2d818e9cabe901 Mon Sep 17 00:00:00 2001 From: Owen Lamont Date: Tue, 17 Dec 2024 17:14:07 +1030 Subject: [PATCH] Add coverage comment to test CI --- .github/workflows/pytest.yml | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index c5eebe2..07ddef6 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -18,5 +18,27 @@ jobs: python-version-file: ".python-version" - name: Install the project run: uv sync --all-extras --dev - - name: Run tests - run: uv run pytest tests + - name: Run tests with Coverage + run: uv run pytest tests --cov=. --cov-report=term > coverage_summary.txt + - name: Prepare Comment Body + run: | + echo '### Coverage Report' >> comment_body.md + echo '```txt' >> comment_body.md + cat coverage_summary.txt >> comment_body.md + echo '' >> comment_body.md + echo '```' >> comment_body.md + - name: Find Coverage Report Comment + id: find-comment + uses: peter-evans/find-comment@v3 + with: + issue-number: ${{ github.event.pull_request.number }} + comment-author: github-actions[bot] + body-includes: '### Coverage Report' + - name: Create or Update Coverage Comment + uses: peter-evans/create-or-update-comment@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + issue-number: ${{ github.event.pull_request.number }} + body-path: comment_body.md + comment-id: ${{ steps.find-comment.outputs.comment-id }} + edit-mode: replace