Skip to content

Commit

Permalink
ci: Add code coverage comment into pytest workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
aiakide committed Jan 30, 2025
1 parent 87ef659 commit 67ef85b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 4 deletions.
56 changes: 53 additions & 3 deletions .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ on:
pull_request:
types: [ opened, reopened, synchronize ]
workflow_call:

permissions:
id-token: write
contents: write
checks: write
pull-requests: write
jobs:
test:
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, windows-latest, macos-latest ]
python-version: [ "3.10","3.11", "3.12", "3.13", "3.14" ]
os: [ ubuntu-latest ]
python-version: [ "3.10" ]
runs-on: ${{ matrix.os }}
timeout-minutes: 30
name: 🧪 Run pytests wit ${{matrix.python-version}} on ${{matrix.os}}
Expand Down Expand Up @@ -63,3 +67,49 @@ jobs:

# (Optional) Title of the test results section in the workflow summary
title: Test results
- name: ✏️ Write test result as comment
uses: MishaKav/pytest-coverage-comment@v1
with:
pytest-xml-coverage-path: ./coverage.xml
title: Coverage Report
badge-title: Code Coverage
hide-badge: false
hide-report: false
create-new-comment: false
hide-comment: false
report-only-changed-files: true
remove-link-from-badge: false
junitxml-path: ./junit.xml
junitxml-title: Pytest summary
github-token: ${{ secrets.GITHUB_TOKEN }}
# - name: Upload math result for job 1
# uses: actions/upload-artifact@v4
# with:
# name: code-coverage
# path: ./coverage.xml
# - name: Upload math result for job 1
# uses: actions/upload-artifact@v4
# with:
# name: code-coverage
# path: ./coverage.xml
# - name: Download math result for job 1
# uses: actions/download-artifact@v4
# with:
# name: code-coverage
- name: Pytest coverage comment
if: ${{ github.ref == 'refs/heads/feature/base-cicd' }}
id: coverageComment
uses: MishaKav/pytest-coverage-comment@main
with:
hide-comment: true
pytest-xml-coverage-path: ./coverage.xml

- name: Update Readme with Coverage Html
run: |
sed -i '/<!-- Pytest Coverage Comment:Begin -->/,/<!-- Pytest Coverage Comment:End -->/c\<!-- Pytest Coverage Comment:Begin -->\n\${{ steps.coverageComment.outputs.coverageHtml }}\n<!-- Pytest Coverage Comment:End -->' ./README.md
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
<!-- Pytest Coverage Comment:Begin -->
<!-- Pytest Coverage Comment:End -->

[![🧪 pytest](https://github.com/codecentric-oss/lightml/actions/workflows/pytest.yaml/badge.svg)](https://github.com/codecentric-oss/lightml/actions/workflows/pytest.yaml)
2 changes: 1 addition & 1 deletion tests/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@


def test_dummy_function():
assert dummyfunction() == 0
assert dummyfunction() == 1

0 comments on commit 67ef85b

Please sign in to comment.