chore(src/djinit/templates/project/ci): streamline CI jobs and improve caching
The CI templates were refactored to simplify configuration, remove redundant services, and enable better cache reuse while maintaining compatibility across Python versions. - New Features - Consolidated caching logic with `cache-suffix` per Python version. - Integrated security check directly into the main pipeline. - Enhancements - Reduced matrix size to only Python 3.13. - Replaced manual PostgreSQL setup with Django checks using `DJANGO_SETTINGS_MODULE` and `SECRET_KEY`. - Merged duplicate test and security steps across CI platforms. - Bug Fixes - Fixed missing `python-version` entries that caused undefined matrix behavior. - Resolved duplicate environment variable definitions in GitLab CI.
This commit is contained in:
2 files changed
+53
-158
No files matched your search
@@ -11,22 +11,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
python-version: ["3.12", "3.13"]
|
python-version: ["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
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
@@ -39,7 +24,8 @@ jobs:
|
|||||||
- name: Install uv
|
- name: Install uv
|
||||||
uses: astral-sh/setup-uv@v4
|
uses: astral-sh/setup-uv@v4
|
||||||
with:
|
with:
|
||||||
version: "latest"
|
enable-cache: true
|
||||||
|
cache-suffix: ${{ matrix.python-version }}
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: uv sync
|
run: uv sync
|
||||||
@@ -50,60 +36,30 @@ jobs:
|
|||||||
- name: Format check
|
- name: Format check
|
||||||
run: uv run ruff format --check .
|
run: uv run ruff format --check .
|
||||||
|
|
||||||
- name: Set up PostgreSQL
|
- name: Run Django checks
|
||||||
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
|
|
||||||
env:
|
env:
|
||||||
DJANGO_SETTINGS_MODULE: [[ module_name ]].settings.development
|
DJANGO_SETTINGS_MODULE: [[ module_name ]].settings.development
|
||||||
SECRET_KEY: test-secret-key-for-ci
|
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: |
|
run: |
|
||||||
uv run python manage.py check
|
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
|
uv run python manage.py test
|
||||||
|
|
||||||
- name: Check migrations
|
- name: Check migrations
|
||||||
env:
|
env:
|
||||||
DJANGO_SETTINGS_MODULE: [[ module_name ]].settings.development
|
DJANGO_SETTINGS_MODULE: [[ module_name ]].settings.development
|
||||||
SECRET_KEY: test-secret-key-for-ci
|
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: |
|
run: |
|
||||||
uv run python manage.py makemigrations --check --dry-run
|
uv run python manage.py makemigrations --check --dry-run
|
||||||
|
|
||||||
security:
|
- name: Security check
|
||||||
runs-on: ubuntu-latest
|
env:
|
||||||
steps:
|
DJANGO_SETTINGS_MODULE: [[ module_name ]].settings.development
|
||||||
- uses: actions/checkout@v4
|
SECRET_KEY: test-secret-key-for-ci
|
||||||
|
run: |
|
||||||
- name: Set up Python
|
uv run python manage.py check --deploy
|
||||||
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
|
|
||||||
@@ -1,133 +1,72 @@
|
|||||||
# GitLab CI/CD configuration for [[ project_name ]]
|
# GitLab CI/CD configuration for [[ project_name ]]
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- test
|
|
||||||
- lint
|
- lint
|
||||||
|
- test
|
||||||
- security
|
- 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:
|
variables:
|
||||||
POSTGRES_DB: test_db
|
POSTGRES_DB: test_db
|
||||||
POSTGRES_USER: postgres
|
POSTGRES_USER: postgres
|
||||||
POSTGRES_PASSWORD: postgres
|
POSTGRES_PASSWORD: postgres
|
||||||
DATABASE_URL: "postgresql://postgres:postgres@postgres:5432/test_db"
|
# @ENDIF
|
||||||
|
|
||||||
# Use Docker-in-Docker
|
|
||||||
services:
|
|
||||||
- postgres:15
|
|
||||||
|
|
||||||
before_script:
|
before_script:
|
||||||
- python --version
|
- python --version
|
||||||
- pip install uv
|
- pip install uv
|
||||||
- uv sync
|
- uv sync
|
||||||
|
|
||||||
# Lint stage
|
|
||||||
lint:
|
lint:
|
||||||
stage: lint
|
stage: lint
|
||||||
image: python:3.13
|
image: python:3.13
|
||||||
script:
|
script:
|
||||||
- uv run ruff check .
|
- uv run ruff check .
|
||||||
- uv run ruff format --check .
|
- uv run ruff format --check .
|
||||||
only:
|
rules:
|
||||||
- branches
|
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
|
||||||
- merge_requests
|
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
|
||||||
|
- if: $CI_COMMIT_BRANCH == 'develop'
|
||||||
|
|
||||||
# Test stage
|
|
||||||
test:
|
test:
|
||||||
stage: test
|
stage: test
|
||||||
image: python:3.13
|
image: python:3.13
|
||||||
variables:
|
|
||||||
DJANGO_SETTINGS_MODULE: [[ module_name ]].settings.development
|
|
||||||
SECRET_KEY: test-secret-key-for-ci
|
|
||||||
ALLOWED_HOSTS: localhost
|
|
||||||
script:
|
script:
|
||||||
- uv run python manage.py check
|
- uv run python manage.py check
|
||||||
- uv run python manage.py migrate
|
|
||||||
- uv run python manage.py test
|
- uv run python manage.py test
|
||||||
only:
|
rules:
|
||||||
- branches
|
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
|
||||||
- merge_requests
|
- 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:
|
security:
|
||||||
stage: security
|
stage: security
|
||||||
image: python:3.13
|
image: python:3.13
|
||||||
variables:
|
|
||||||
DJANGO_SETTINGS_MODULE: [[ module_name ]].settings.development
|
|
||||||
SECRET_KEY: test-secret-key-for-ci
|
|
||||||
script:
|
script:
|
||||||
- pip install uv
|
|
||||||
- uv sync
|
|
||||||
- uv run python manage.py check --deploy
|
- uv run python manage.py check --deploy
|
||||||
- uv run python manage.py validate_templates
|
rules:
|
||||||
only:
|
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
|
||||||
- main
|
- if: $CI_COMMIT_BRANCH == 'develop'
|
||||||
- develop
|
|
||||||
Reference in new issue
Block a user