From bf6a389f483c3f55dbd8b5232c1417f8c3fd3d49 Mon Sep 17 00:00:00 2001 From: Roman Dyakov Date: Sat, 6 Apr 2024 15:31:42 +0300 Subject: [PATCH 1/4] Makefile format --- Makefile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Makefile b/Makefile index 2ef49c1a..d42b352d 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,12 @@ format: source ./venv/bin/activate && autoflake -r --in-place --remove-all-unused-imports ./calendar_backend source ./venv/bin/activate && isort ./calendar_backend source ./venv/bin/activate && black ./calendar_backend + 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-timetable_api postgres:15 From 1f0366ff9c92c29dae54be85d1312b1d17ff2cec Mon Sep 17 00:00:00 2001 From: Roman Dyakov Date: Sat, 6 Apr 2024 15:44:35 +0300 Subject: [PATCH 2/4] Style --- calendar_backend/settings.py | 2 +- migrations/versions/63263ee9e08e_fix_photo_paths.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/calendar_backend/settings.py b/calendar_backend/settings.py index 573000ce..7658af36 100644 --- a/calendar_backend/settings.py +++ b/calendar_backend/settings.py @@ -2,7 +2,7 @@ from functools import lru_cache from auth_lib.fastapi import UnionAuthSettings -from pydantic import AnyHttpUrl, ConfigDict, DirectoryPath, Json, PostgresDsn +from pydantic import AnyHttpUrl, ConfigDict, DirectoryPath, PostgresDsn from pydantic_settings import BaseSettings diff --git a/migrations/versions/63263ee9e08e_fix_photo_paths.py b/migrations/versions/63263ee9e08e_fix_photo_paths.py index 4841162d..cb31fea1 100644 --- a/migrations/versions/63263ee9e08e_fix_photo_paths.py +++ b/migrations/versions/63263ee9e08e_fix_photo_paths.py @@ -6,7 +6,6 @@ """ -import sqlalchemy as sa from alembic import op From 188d3e8dc9bd85edaf665e7c2ce8b76598e0356d Mon Sep 17 00:00:00 2001 From: Roman Dyakov Date: Sat, 6 Apr 2024 15:56:57 +0300 Subject: [PATCH 3/4] Better on pr workflow --- .github/workflows/checks.yml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 52903a76..9a04895e 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -1,9 +1,8 @@ -name: Python package +name: Python tests on: pull_request: - jobs: test: name: Unit tests @@ -18,7 +17,7 @@ jobs: 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 @@ -28,6 +27,7 @@ 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=calendar_backend tests/ | tee pytest-coverage.txt - name: Print report @@ -48,6 +48,10 @@ jobs: remove-link-from-badge: false 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: @@ -60,7 +64,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: | From 7584ba3e7d9abbf64253640c28867aabd89015a6 Mon Sep 17 00:00:00 2001 From: Roman Dyakov Date: Sat, 6 Apr 2024 16:21:29 +0300 Subject: [PATCH 4/4] Service instead docker setup --- .github/workflows/checks.yml | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 9a04895e..55606cb2 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -7,14 +7,20 @@ jobs: test: name: Unit tests runs-on: ubuntu-latest + 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" @@ -30,6 +36,7 @@ jobs: id: pytest run: | DB_DSN=postgresql://postgres@localhost:5432/postgres pytest --junitxml=pytest.xml --cov-report=term-missing:skip-covered --cov=calendar_backend tests/ | tee pytest-coverage.txt + exit ${PIPESTATUS[0]} - name: Print report if: always() run: |