diff --git a/src/djinit/templates/project/ci/github_actions-tpl b/src/djinit/templates/project/ci/github_actions-tpl index ad03ec2..03648aa 100644 --- a/src/djinit/templates/project/ci/github_actions-tpl +++ b/src/djinit/templates/project/ci/github_actions-tpl @@ -11,22 +11,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.12", "3.13"] - - services: - postgres: - image: postgres:15 - env: - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres - POSTGRES_DB: test_db - options: >- - --health-cmd pg_isready - --health-interval 10s - --health-timeout 5s - --health-retries 5 - ports: - - 5432:5432 + python-version: ["3.13"] steps: - uses: actions/checkout@v4 @@ -39,7 +24,8 @@ jobs: - name: Install uv uses: astral-sh/setup-uv@v4 with: - version: "latest" + enable-cache: true + cache-suffix: ${{ matrix.python-version }} - name: Install dependencies run: uv sync @@ -50,60 +36,30 @@ jobs: - name: Format check run: uv run ruff format --check . - - name: Set up PostgreSQL - env: - DB_NAME: test_db - DB_USER: postgres - DB_PASSWORD: postgres - DB_HOST: localhost - DB_PORT: 5432 - run: | - echo "PostgreSQL is ready" - - - name: Run Django tests + - name: Run Django checks env: DJANGO_SETTINGS_MODULE: [[ module_name ]].settings.development SECRET_KEY: test-secret-key-for-ci - ALLOWED_HOSTS: localhost - DB_NAME: test_db - DB_USER: postgres - DB_PASSWORD: postgres - DB_HOST: localhost - DB_PORT: 5432 run: | uv run python manage.py check + + - name: Run tests + env: + DJANGO_SETTINGS_MODULE: [[ module_name ]].settings.development + SECRET_KEY: test-secret-key-for-ci + run: | uv run python manage.py test - name: Check migrations env: DJANGO_SETTINGS_MODULE: [[ module_name ]].settings.development SECRET_KEY: test-secret-key-for-ci - ALLOWED_HOSTS: localhost - DB_NAME: test_db - DB_USER: postgres - DB_PASSWORD: postgres - DB_HOST: localhost - DB_PORT: 5432 run: | uv run python manage.py makemigrations --check --dry-run - security: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: "3.13" - - - name: Install uv - uses: astral-sh/setup-uv@v4 - with: - version: "latest" - - - name: Install dependencies - run: uv sync - - - name: Run security check - run: uv run python manage.py check --deploy + - name: Security check + env: + DJANGO_SETTINGS_MODULE: [[ module_name ]].settings.development + SECRET_KEY: test-secret-key-for-ci + run: | + uv run python manage.py check --deploy diff --git a/src/djinit/templates/project/ci/gitlab_ci-tpl b/src/djinit/templates/project/ci/gitlab_ci-tpl index e5e3f47..41e4520 100644 --- a/src/djinit/templates/project/ci/gitlab_ci-tpl +++ b/src/djinit/templates/project/ci/gitlab_ci-tpl @@ -1,133 +1,72 @@ # GitLab CI/CD configuration for [[ project_name ]] stages: - - test - lint + - test - security +variables: + DJANGO_SETTINGS_MODULE: [[ module_name ]].settings.development + SECRET_KEY: test-secret-key-for-ci + ALLOWED_HOSTS: localhost + PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip" + UV_CACHE_DIR: "$CI_PROJECT_DIR/.cache/uv" + +cache: + paths: + - .cache/pip + - .cache/uv + - .venv/ + +# @IF database_type == 'mysql' +services: + - mysql:8.0 + +variables: + MYSQL_DATABASE: test_db + MYSQL_ROOT_PASSWORD: test_password +# @ELSE +services: + - postgres:15 + variables: POSTGRES_DB: test_db POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres - DATABASE_URL: "postgresql://postgres:postgres@postgres:5432/test_db" - -# Use Docker-in-Docker -services: - - postgres:15 +# @ENDIF before_script: - python --version - pip install uv - uv sync -# Lint stage lint: stage: lint image: python:3.13 script: - uv run ruff check . - uv run ruff format --check . - only: - - branches - - merge_requests + rules: + - if: $CI_PIPELINE_SOURCE == 'merge_request_event' + - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH + - if: $CI_COMMIT_BRANCH == 'develop' -# Test stage test: stage: test image: python:3.13 - variables: - DJANGO_SETTINGS_MODULE: [[ module_name ]].settings.development - SECRET_KEY: test-secret-key-for-ci - ALLOWED_HOSTS: localhost script: - uv run python manage.py check - - uv run python manage.py migrate - uv run python manage.py test - only: - - branches - - merge_requests + rules: + - if: $CI_PIPELINE_SOURCE == 'merge_request_event' + - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH + - if: $CI_COMMIT_BRANCH == 'develop' -# Multiple Python versions -test:python310: - stage: test - image: python:3.10 - variables: - DJANGO_SETTINGS_MODULE: [[ module_name ]].settings.development - SECRET_KEY: test-secret-key-for-ci - ALLOWED_HOSTS: localhost - script: - - pip install uv - - uv sync - - uv run python manage.py check - - uv run python manage.py migrate - - uv run python manage.py test - only: - - branches - - merge_requests - -test:python311: - stage: test - image: python:3.11 - variables: - DJANGO_SETTINGS_MODULE: [[ module_name ]].settings.development - SECRET_KEY: test-secret-key-for-ci - ALLOWED_HOSTS: localhost - script: - - pip install uv - - uv sync - - uv run python manage.py check - - uv run python manage.py migrate - - uv run python manage.py test - only: - - branches - - merge_requests - -test:python312: - stage: test - image: python:3.12 - variables: - DJANGO_SETTINGS_MODULE: [[ module_name ]].settings.development - SECRET_KEY: test-secret-key-for-ci - ALLOWED_HOSTS: localhost - script: - - pip install uv - - uv sync - - uv run python manage.py check - - uv run python manage.py migrate - - uv run python manage.py test - only: - - branches - - merge_requests - -test:python313: - stage: test - image: python:3.13 - variables: - DJANGO_SETTINGS_MODULE: [[ module_name ]].settings.development - SECRET_KEY: test-secret-key-for-ci - ALLOWED_HOSTS: localhost - script: - - pip install uv - - uv sync - - uv run python manage.py check - - uv run python manage.py migrate - - uv run python manage.py test - only: - - branches - - merge_requests - -# Security check security: stage: security image: python:3.13 - variables: - DJANGO_SETTINGS_MODULE: [[ module_name ]].settings.development - SECRET_KEY: test-secret-key-for-ci script: - - pip install uv - - uv sync - uv run python manage.py check --deploy - - uv run python manage.py validate_templates - only: - - main - - develop + rules: + - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH + - if: $CI_COMMIT_BRANCH == 'develop'