Add black formatter (#2) #5
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: run tests and check coverage | |
on: push | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: checkout repo content | |
uses: actions/checkout@v2 # checkout the repository content | |
- name: setup python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.10' # install the python version needed | |
- name: install python packages | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt | |
- name: Check files using the black formatter | |
uses: psf/black@stable | |
id: action_black | |
with: | |
options: "." | |
- name: commit files | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Action" | |
git add -A | |
git diff-index --quiet HEAD || (git commit -a -m "code formatted" --allow-empty) | |
- name: push changes | |
uses: ad-m/[email protected] | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
branch: ${{ github.head_ref || github.ref_name }} | |
- name: run pytest | |
id: test_step | |
run: pytest tests | |
- name: Fail workflow if tests were failed | |
if: ${{ steps.test_step.outcome == 'failure' }} | |
run: exit 1 | |
- name: run coverage | |
id: test_cov_step | |
run: | | |
coverage run -m pytest tests | |
coverage report -m | awk '/TOTAL/ {print ($4 > 70)}' | |
- name: Fail workflow if test coverage score is below threshold | |
if: ${{ steps.test_cov_step.outcome == 0 }} | |
run: exit 1 |