Repository navigation
Improve test coverage for BlogApi #24
This file contains hidden or 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: Pull Request Checks | |
| on: | |
| pull_request: | |
| branches: [main, develop] | |
| types: [opened, synchronize, reopened] | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| issues: write | |
| checks: write | |
| jobs: | |
| pr-check-cov: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v5 | |
| - name: Set up Python 3.12.x | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: 3.12.x | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| - name: Run tests with coverage | |
| run: | | |
| pytest --verbose --tb=short --cov=. --cov-report=xml --cov-report=term | |
| - name: Upload coverage reports to Codecov with GitHub Action | |
| uses: codecov/codecov-action@v5 | |
| env: | |
| CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} | |
| verbose: true | |
| fail_ci_if_error: true | |
| pr-checks-tests: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| python-version: [3.10.x, 3.11.x, 3.12.x] | |
| postgres-version: [17-alpine] | |
| redis-version: [8-alpine] | |
| services: | |
| postgres: | |
| image: postgres:${{matrix.postgres-version}} | |
| env: | |
| POSTGRES_PASSWORD: postgres | |
| POSTGRES_USER: postgres | |
| POSTGRES_DB: test_backend | |
| options: >- | |
| --health-cmd pg_isready | |
| --health-interval 10s | |
| --health-timeout 5s | |
| --health-retries 5 | |
| ports: | |
| - 5432:5432 | |
| redis: | |
| image: redis:${{matrix.redis-version}} | |
| options: >- | |
| --health-cmd "redis-cli ping" | |
| --health-interval 10s | |
| --health-timeout 5s | |
| --health-retries 5 | |
| ports: | |
| - 6379:6379 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v5 | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Cache pip dependencies | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.cache/pip | |
| key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} | |
| restore-keys: | | |
| ${{ runner.os }}-pip- | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| - name: Set up environment variables | |
| run: | | |
| echo "DJANGO_DEBUG=False" >> $GITHUB_ENV | |
| echo "SECRET_KEY=test-secret-key-for-ci" >> $GITHUB_ENV | |
| echo "ALLOWED_HOSTS=localhost,127.0.0.1" >> $GITHUB_ENV | |
| echo "DATABASE_TYPE=pgsql" >> $GITHUB_ENV | |
| echo "DATABASE_USER=postgres" >> $GITHUB_ENV | |
| echo "DATABASE_PASSWORD=postgres" >> $GITHUB_ENV | |
| echo "DATABASE_HOST=localhost" >> $GITHUB_ENV | |
| echo "DATABASE_PORT=5432" >> $GITHUB_ENV | |
| echo "DATABASE_NAME=test_backend" >> $GITHUB_ENV | |
| echo "REDIS_HOST=localhost" >> $GITHUB_ENV | |
| echo "REDIS_PORT=6379" >> $GITHUB_ENV | |
| echo "REDIS_DB=0" >> $GITHUB_ENV | |
| - name: Run migrations | |
| run: | | |
| python manage.py migrate | |
| - name: Run Django system checks | |
| run: | | |
| python manage.py check | |
| - name: Run tests | |
| run: | | |
| pytest --verbose --tb=short | |
| pr-check-formating: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v5 | |
| - name: Set up Python 3.12.x | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: 3.12.x | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| - name: Lint with flake8 | |
| run: | | |
| flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | |
| flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics | |
| - name: Check code formatting with black | |
| run: | | |
| black --check --diff . | |
| - name: Check import sorting with isort | |
| run: | | |
| isort --check-only --diff . | |
| pr-sec-check: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v5 | |
| - name: Set up Python 3.12.x | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: 3.12.x | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| - name: Security scan with bandit | |
| run: | | |
| bandit -r . --severity-level medium | |
| - name: Dependency security check | |
| run: | | |
| # Install compatible versions for safety | |
| pip install "typer<0.13.0" "safety==2.4.0b2" || pip install "safety<3.0.0" | |
| # Run safety check with fallback | |
| safety check || { | |
| echo "Safety check failed, trying pip-audit as fallback..." | |
| pip install pip-audit | |
| pip-audit --desc || echo "Dependency security scan completed with warnings" | |
| } | |