diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..8a5450e --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,57 @@ +name: Base Fast Workflow + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + test: + runs-on: ubuntu-latest + + services: + postgres: + image: postgres:17 + ports: + - 5432:5432 + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: localdb123 + POSTGRES_DB: test_db_1 + options: >- + --health-cmd "pg_isready -U postgres -d test_db_1" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + + env: + DATABASE_URL: postgresql://postgres:localdb123@localhost:5432/base_fast + TEST_DATABASE_URL: postgresql://postgres:localdb123@localhost:5432/test_db_1 + ENV: development + SECRET_KEY: somthing-that-already-secret + ALGORITHM: HS256 + ACCESS_TOKEN_EXPIRE_MINUTES: 45 + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: 3.13 + + - name: Install uv + run: | + curl -LsSf https://astral.sh/uv/install.sh | sh + echo "$HOME/.cargo/bin" >> $GITHUB_PATH + + - name: Install dependencies with uv + run: uv sync + + - name: Run ruff format check + run: uv run ruff format + + - name: Run tests + run: uv run pytest -n auto \ No newline at end of file diff --git a/.gitignore b/.gitignore index c5ef094..cc3f834 100644 --- a/.gitignore +++ b/.gitignore @@ -155,8 +155,6 @@ cython_debug/ rules.md GEMINI.MD -# development files -logs/ # IDE Jetbrains .idea \ No newline at end of file diff --git a/app/core/logger.py b/app/core/logger.py index 43d0e48..d4afefe 100644 --- a/app/core/logger.py +++ b/app/core/logger.py @@ -2,6 +2,7 @@ import json import sys import os +import sys from datetime import datetime @@ -11,9 +12,12 @@ def __init__(self, path: str): self.logger = logging.getLogger(path) self.logger.setLevel(logging.INFO) + is_testing = "pytest" in sys.modules + is_production = os.getenv("ENV") == "production" + # Ensure handlers are not duplicated if logger is retrieved multiple times if not self.logger.handlers: - if os.getenv("ENV") == "production": + if is_production or is_testing: # Production: Stream logs to external system (e.g., Grafana) handler = logging.StreamHandler( sys.stdout diff --git a/logs/.gitignore b/logs/.gitignore new file mode 100644 index 0000000..7bfddbf --- /dev/null +++ b/logs/.gitignore @@ -0,0 +1,2 @@ +*.log +*logs.json \ No newline at end of file