diff --git a/.github/workflows/tests.yml b/.github/workflows/checks.yml similarity index 79% rename from .github/workflows/tests.yml rename to .github/workflows/checks.yml index e05f50f..49459ea 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/checks.yml @@ -1,25 +1,29 @@ -name: Python package +name: Python tests on: pull_request: - jobs: test: name: Unit tests runs-on: ubuntu-latest - continue-on-error: true + services: + postgres: + image: postgres:15 + env: + POSTGRES_HOST_AUTH_METHOD: trust + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + -p 5432:5432 steps: - name: Checkout uses: actions/checkout@v4 - - name: Set up docker - uses: docker-practice/actions-setup-docker@master - - name: Run postgres - run: | - docker run -d -p 5432:5432 -e POSTGRES_HOST_AUTH_METHOD=trust --name db-test postgres:15-alpine - uses: actions/setup-python@v4 with: - python-version: '3.11' + python-version: "3.11" - name: Install dependencies run: | python -m ensurepip @@ -29,8 +33,10 @@ jobs: run: | DB_DSN=postgresql://postgres@localhost:5432/postgres alembic upgrade head - name: Build coverage file + id: pytest run: | DB_DSN=postgresql://postgres@localhost:5432/postgres pytest --junitxml=pytest.xml --cov-report=term-missing:skip-covered --cov=userdata_api tests/ | tee pytest-coverage.txt + exit ${PIPESTATUS[0]} - name: Print report if: always() run: | @@ -50,6 +56,10 @@ jobs: unique-id-for-comment: python3.11 junitxml-path: ./pytest.xml junitxml-title: Summary + - name: Fail on pytest errors + if: steps.pytest.outcome == 'failure' + run: exit 1 + linting: runs-on: ubuntu-latest steps: @@ -62,7 +72,7 @@ jobs: requirementsFiles: "requirements.txt requirements.dev.txt" - uses: psf/black@stable - name: Comment if linting failed - if: ${{ failure() }} + if: failure() uses: thollander/actions-comment-pull-request@v2 with: message: | diff --git a/Makefile b/Makefile index c213a43..16652ca 100644 --- a/Makefile +++ b/Makefile @@ -8,18 +8,15 @@ venv: python3.11 -m venv venv format: - autoflake -r --in-place --remove-all-unused-imports ./userdata_api - isort ./userdata_api - black ./userdata_api - -dev-format: format - autoflake -r --in-place --remove-all-unused-imports ./tests - isort ./tests - black ./tests - autoflake -r --in-place --remove-all-unused-imports ./migrations - isort ./migrations - black ./migrations - + source ./venv/bin/activate && autoflake -r --in-place --remove-all-unused-imports ./userdata_api + source ./venv/bin/activate && isort ./userdata_api + source ./venv/bin/activate && black ./userdata_api + source ./venv/bin/activate && autoflake -r --in-place --remove-all-unused-imports ./tests + source ./venv/bin/activate && isort ./tests + source ./venv/bin/activate && black ./tests + source ./venv/bin/activate && autoflake -r --in-place --remove-all-unused-imports ./migrations + source ./venv/bin/activate && isort ./migrations + source ./venv/bin/activate && black ./migrations db: docker run -d -p 5432:5432 -e POSTGRES_HOST_AUTH_METHOD=trust --name db-userdata_api postgres:15