YAML

GitHub Actions: тесты и линтеры

Algonexys · 07.08.2026 · 👁 0

CI-пайплайн для Python-проекта: матрица версий, кеш зависимостей, сервисная БД, покрытие.

Код

name: CI

on:
  push:
    branches: [main, master]
  pull_request:

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        python-version: ["3.11", "3.12"]

    services:
      postgres:
        image: postgres:16
        env:
          POSTGRES_PASSWORD: postgres
          POSTGRES_DB: test_db
        ports: ["5432:5432"]
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5

    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python-version }}
          cache: pip

      - name: Установка зависимостей
        run: |
          python -m pip install --upgrade pip
          pip install -r requirements.txt ruff

      - name: Линтер
        run: ruff check .

      - name: Тесты
        env:
          DATABASE_URL: postgres://postgres:postgres@localhost:5432/test_db
          SECRET_KEY: ci-secret-key
        run: python manage.py test --verbosity=2