0
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2025-07-13 19:21:50 +02:00

ci: coverage

This commit is contained in:
2025-05-12 20:25:12 +02:00
committed by Klaus Wakonig
parent 88a17a566c
commit a301d37c4f
2 changed files with 56 additions and 8 deletions

View File

@ -1,5 +1,15 @@
name: Run Pytest with Coverage
on: [workflow_call]
on:
workflow_call:
inputs:
pr_number:
description: 'Pull request number'
required: false
type: number
permissions:
pull-requests: write
jobs:
pytest:
@ -40,13 +50,46 @@ jobs:
pip install -e .[dev,pyside6]
- name: Run Pytest with Coverage
id: coverage
run: |
pip install coverage pytest pytest-random-order
coverage run --source=./bec_widgets -m pytest -v --junitxml=report.xml --maxfail=2 --random-order --full-trace ./tests/unit_tests
coverage report
coverage xml
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v5
full_report=$(coverage report)
coverage xml -i -o coverage.cobertura.xml
# Extract total coverage %
COVERAGE=$(echo "$full_report" | grep TOTAL | awk '{print $4}' | sed 's/%//')
echo "coverage=$COVERAGE" >> $GITHUB_OUTPUT
- name: Code Coverage Summary Report
uses: irongut/CodeCoverageSummary@v1.3.0
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: bec-project/bec_widgets
filename: coverage.cobertura.xml
format: 'markdown'
output: 'both'
- name: Format Coverage Report
shell: bash
run: |
tmpfile=$(cat code-coverage-results.md)
echo "## Code Coverage Report" > code-coverage-results-formatted.md
echo "![Coverage Badge](https://img.shields.io/badge/coverage-${{ steps.coverage.outputs.coverage }}%25-brightgreen)" >> code-coverage-results-formatted.md
echo "<details>" >> code-coverage-results-formatted.md
echo "<summary>Code Coverage</summary>" >> code-coverage-results-formatted.md
echo >> code-coverage-results-formatted.md
echo >> code-coverage-results-formatted.md
echo "$tmpfile" >> code-coverage-results-formatted.md
echo "</details>" >> code-coverage-results-formatted.md
- name: Add Coverage PR Comment
if: ${{ github.event_name == 'pull_request' }}
uses: marocchino/sticky-pull-request-comment@v2
with:
number: ${{ github.event.pull_request.number }}
recreate: true
path: code-coverage-results-formatted.md
- name: Write Coverage to Job Summary
shell: bash
run: cat code-coverage-results.md >> $GITHUB_STEP_SUMMARY