Workflow coverage #8
This file contains 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: Update Coverage Badge | |
on: | |
push: | |
branches: | |
- '*' | |
jobs: | |
update-readme: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: 3.9 | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
apt-get update && apt-get upgrade -y && apt-get install -y --no-install-recommends libpq-dev gcc libc6-dev gpg git | |
pip install -r webservice/requirements.txt | |
- name: Run tests with coverage | |
run: | | |
coverage run -m pytest webservice/test/test_app.py | |
- name: Generate coverage badge | |
run: | | |
coverage-badge -o coverage.svg | |
- name: Prepend badge to README | |
run: | | |
echo "" > temp_readme.md # Create a temporary file | |
echo "# My Project" >> temp_readme.md # Restore the title | |
echo "" >> temp_readme.md # Add a blank line for spacing | |
echo "[![Coverage Status](coverage.svg)](./coverage.svg)" >> temp_readme.md # Append the badge | |
sed '1d' README.md >> temp_readme.md # Append the rest of README.md | |
mv temp_readme.md README.md # Replace README.md with the modified temp file | |
- name: Commit and push changes | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Action" | |
git add README.md | |
git commit -m "Add coverage badge to README" -a || true # Continue even if nothing to commit | |
git push |