add coverage badge #11
Workflow file for this run
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: CodeCoverage | |
| on: [push, pull_request, workflow_dispatch] | |
| jobs: | |
| run: | |
| runs-on: [ubuntu-24.04] | |
| strategy: | |
| matrix: | |
| python-versions: ['3.12'] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python ${{ matrix.python-versions }} | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: ${{ matrix.python-versions }} | |
| - name: setup | |
| run: | | |
| sudo apt update && sudo apt install --yes \ | |
| libcdd-dev \ | |
| libgmp-dev \ | |
| numdiff \ | |
| texlive \ | |
| texlive-latex-extra | |
| python -m pip install --upgrade pip | |
| pip install pycddlib autograd # this is optional | |
| pip install coverage | |
| python --version | |
| - name: Generate Report | |
| run: | | |
| python -m pip install git+https://github.com/geodynamics/burnman@main | |
| mkdir main_tests | |
| cd main_tests | |
| git clone https://github.com/geodynamics/burnman | |
| cp burnman/tests/*.py . | |
| rm -fr burnman | |
| cd ../ | |
| coverage run -m unittest discover ./main_tests | |
| coverage report > main_coverage.tmp | |
| main_coverage=$(coverage report --precision=7 --format=total) | |
| rm -fr main_tests | |
| python -m pip install -q -e .[dev] | |
| coverage run -m unittest discover ./tests | |
| coverage report > new_coverage.tmp | |
| new_coverage=$(coverage report --precision=7 --format=total) | |
| echo "Main coverage: $main_coverage" | |
| echo "New coverage: $new_coverage" | |
| if (( $(echo "$new_coverage < $main_coverage" | bc -l) )); then | |
| diff main_coverage.tmp new_coverage.tmp | |
| echo "Coverage ($new_coverage %) decreased relative to main ($main_coverage %)" | |
| exit 1 | |
| fi | |
| - name: Run coverage | |
| run: | | |
| coverage run -m unittest discover ./tests | |
| coverage report -m | |
| - name: Coverage Badge | |
| uses: tj-actions/coverage-badge-py@v2 | |
| - name: Verify Changed files | |
| uses: tj-actions/verify-changed-files@v16 | |
| id: verify-changed-files | |
| with: | |
| files: coverage.svg | |
| - name: Commit files | |
| if: steps.verify-changed-files.outputs.files_changed == 'true' | |
| run: | | |
| git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
| git config --local user.name "github-actions[bot]" | |
| git add coverage.svg | |
| git commit -m "Updated coverage.svg" | |
| - name: Push changes | |
| if: steps.verify-changed-files.outputs.files_changed == 'true' | |
| uses: ad-m/github-push-action@master | |
| with: | |
| github_token: ${{ secrets.github_token }} | |
| branch: ${{ github.ref }} |