Files
training-software/.github/workflows/ci.yml
Paperclip CTO 8b2ac6b52b
Some checks failed
CI / lint (push) Successful in 7s
CI / test (push) Failing after 9s
CI / build-container (push) Has been skipped
fix(ci): use service hostnames for postgres and redis
2026-05-18 14:55:27 +02:00

153 lines
3.6 KiB
YAML

name: CI
on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
env:
DJANGO_SECRET_KEY: ci-secret-key-not-for-production
DJANGO_SETTINGS_MODULE: config.settings.test
DJANGO_ALLOWED_HOSTS: testserver,localhost
DATABASE_URL: postgres://training:training@postgres:5432/training_test
REDIS_URL: redis://redis:6379/0
jobs:
test:
name: Tests (Python ${{ matrix.python-version }})
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.12"]
services:
postgres:
image: postgres:16-alpine
env:
POSTGRES_DB: training_test
POSTGRES_USER: training
POSTGRES_PASSWORD: training
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 5s
--health-timeout 5s
--health-retries 10
redis:
image: redis:7-alpine
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 5s
--health-timeout 3s
--health-retries 10
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: requirements/test.txt
- name: Install dependencies
run: pip install -r requirements/test.txt
- name: Check migrations up to date
run: python manage.py migrate --check
- name: Run migrations
run: python manage.py migrate
- name: Run smoke + settings tests
run: pytest -m "smoke or settings" -v --tb=short
- name: Run full test suite
run: pytest --cov=. --cov-report=xml --cov-report=term-missing -v
- name: Upload coverage
uses: codecov/codecov-action@v4
with:
file: coverage.xml
fail_ci_if_error: false
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: pip
- name: Install lint tools
run: pip install ruff
- name: Ruff lint check
run: ruff check .
schema:
name: OpenAPI Schema
runs-on: ubuntu-latest
needs: test
services:
postgres:
image: postgres:16-alpine
env:
POSTGRES_DB: training_test
POSTGRES_USER: training
POSTGRES_PASSWORD: training
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 5s
--health-timeout 5s
--health-retries 10
redis:
image: redis:7-alpine
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 5s
--health-timeout 3s
--health-retries 10
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: pip
cache-dependency-path: requirements/test.txt
- name: Install dependencies
run: pip install -r requirements/test.txt
- name: Run migrations
run: python manage.py migrate
- name: Generate OpenAPI schema
run: python manage.py spectacular --file openapi.yaml --validate
- name: Upload schema artifact
uses: actions/upload-artifact@v4
with:
name: openapi-schema
path: openapi.yaml