Skip to content

update coverage workflow to only commit on changes to coverage #2

update coverage workflow to only commit on changes to coverage

update coverage workflow to only commit on changes to coverage #2

name: Update code coverage badge
on:
push:
branches:
main
jobs:
update_coverage:
name: "Update coverage badgeadge"
runs-on: ubuntu-latest
steps:
- name: "Checkout Repository"
uses: actions/checkout@v2
- name: "Set up Python"
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: "Install Dependencies"
run: |
python -m pip install --upgrade pip
pip install -r requirements-dev.txt
pip install -e .
- name: "Run Coverage and Generate Badge"
run: |
pytest .
coverage report
coverage xml
coverage html
genbadge coverage --input-file coverage.xml
- name: "Check if coverage-badge.svg Changed"
id: check_svg_change
run: |
if git diff --quiet -- exit-code -- coverage-badge.svg; then
echo "No changes in coverage-badge.svg"
echo "::set-output name=svg_changed::false"
else
echo "Changes detected in coverage-badge.svg"
echo "::set-output name=svg_changed::true"
fi
- name: "Commit and Push Changes"
if: steps.check_svg_change.outputs.svg_changed == 'true'
run: |
git config user.email "${{ github.run_id }}+github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
git add coverage-badge.svg
git commit -m "Update code coverage badge"
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}