name: Backend CI on: pull_request: paths: - 'backend/**' - 'requirements.txt' - 'Dockerfile' - 'docker-compose.yml' push: branches: [main] paths: - 'backend/**' - 'requirements.txt' permissions: contents: read jobs: test: name: Backend Tests runs-on: ubuntu-latest services: postgres: image: postgres:15 env: POSTGRES_PASSWORD: postgres POSTGRES_DB: blackroad_test options: >- --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 ports: - 5432:5432 redis: image: redis:7-alpine options: >- --health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 5 ports: - 6379:6379 steps: - uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v5 with: python-version: '3.11' cache: 'pip' - name: Install dependencies run: | cd backend pip install -r requirements.txt - name: Lint with flake8 run: | cd backend pip install flake8 flake8 app --count --select=E9,F63,F7,F82 --show-source --statistics flake8 app --count --max-complexity=10 --max-line-length=127 --statistics - name: Type check with mypy continue-on-error: true run: | cd backend pip install mypy mypy app --ignore-missing-imports - name: Run tests with pytest env: DATABASE_URL: postgresql://postgres:postgres@localhost:5432/blackroad_test REDIS_URL: redis://localhost:6379/0 SECRET_KEY: test-secret-key-for-ci TESTING: true run: | cd backend pytest -v --cov=app --cov-report=xml --cov-report=term - name: Upload coverage uses: codecov/codecov-action@v3 with: file: ./backend/coverage.xml flags: backend fail_ci_if_error: false