name: CI on: push: branches: [ main, develop ] pull_request: branches: [ main ] jobs: test: runs-on: ubuntu-latest services: postgres: image: postgres:15-alpine env: POSTGRES_PASSWORD: postgres POSTGRES_USER: postgres POSTGRES_DB: test_db options: >- --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 ports: - 5432:5432 steps: - uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v4 with: python-version: '3.11' - name: Cache pip dependencies uses: actions/cache@v3 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/development.txt - name: Create .env file run: | echo "SECRET_KEY=test-secret-key-for-ci" >> .env echo "DEBUG=True" >> .env echo "DB_NAME=test_db" >> .env echo "DB_USER=postgres" >> .env echo "DB_PASSWORD=postgres" >> .env echo "DB_HOST=localhost" >> .env echo "DB_PORT=5432" >> .env - name: Run migrations run: | python manage.py migrate --settings=django_project.settings.development - name: Create test groups run: | python manage.py create_groups --settings=django_project.settings.development - name: Run tests run: | python manage.py test --settings=django_project.settings.development - name: Check for missing migrations run: | python manage.py makemigrations --check --dry-run --settings=django_project.settings.development docker: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Build Docker image run: | docker build --target development -t django-template:test . - name: Test Docker image run: | docker run --rm django-template:test python manage.py check --settings=django_project.settings.development