|
| 1 | +# .gitlab-ci.yml |
| 2 | +# See https://docs.gitlab.com/ee/ci/yaml/ |
| 3 | + |
| 4 | +# Global settings |
| 5 | +image: ghcr.io/astral-sh/uv:latest-python3.13-bookworm-slim |
| 6 | + |
| 7 | +variables: |
| 8 | + UV_CACHE_DIR: .uv-cache |
| 9 | + UV_LINK_MODE: copy |
| 10 | + PIP_CACHE_DIR: $CI_PROJECT_DIR/.cache/pip |
| 11 | + |
| 12 | +# Define stages |
| 13 | +stages: |
| 14 | + - quality |
| 15 | + - test |
| 16 | + - security |
| 17 | + - build |
| 18 | + - release |
| 19 | + |
| 20 | +# Global cache configuration for uv |
| 21 | +.uv-cache: &uv-cache |
| 22 | + cache: |
| 23 | + key: |
| 24 | + files: |
| 25 | + - pyproject.toml |
| 26 | + paths: |
| 27 | + - $UV_CACHE_DIR |
| 28 | + - $PIP_CACHE_DIR |
| 29 | + policy: pull-push |
| 30 | + |
| 31 | +# Shared rules for when to run jobs |
| 32 | +.on-merge-requests-and-main: &on-merge-requests-and-main |
| 33 | + rules: |
| 34 | + - if: $CI_PIPELINE_SOURCE == "merge_request_event" |
| 35 | + - if: $CI_COMMIT_BRANCH == "main" |
| 36 | + - if: $CI_PIPELINE_SOURCE == "web" |
| 37 | + |
| 38 | +# Base job template for Python quality checks |
| 39 | +.quality-job: &quality-job |
| 40 | + stage: quality |
| 41 | + <<: *uv-cache |
| 42 | + <<: *on-merge-requests-and-main |
| 43 | + before_script: |
| 44 | + - uv --version |
| 45 | + after_script: |
| 46 | + - uv cache prune --ci |
| 47 | + |
| 48 | +# Python Quality Checks Jobs |
| 49 | +format-python: |
| 50 | + <<: *quality-job |
| 51 | + script: |
| 52 | + - uvx nox -s format-python |
| 53 | + changes: |
| 54 | + - "src/**/*.py" |
| 55 | + - "tests/**/*.py" |
| 56 | + - "noxfile.py" |
| 57 | + - "pyproject.toml" |
| 58 | + - ".ruff.toml" |
| 59 | + - ".pydocstyle" |
| 60 | + - ".gitlab-ci.yml" |
| 61 | + |
| 62 | +lint-python: |
| 63 | + <<: *quality-job |
| 64 | + script: |
| 65 | + - uvx nox -s lint-python |
| 66 | + changes: |
| 67 | + - "src/**/*.py" |
| 68 | + - "tests/**/*.py" |
| 69 | + - "noxfile.py" |
| 70 | + - "pyproject.toml" |
| 71 | + - ".ruff.toml" |
| 72 | + - ".pydocstyle" |
| 73 | + - ".gitlab-ci.yml" |
| 74 | + |
| 75 | +typecheck-python: |
| 76 | + <<: *quality-job |
| 77 | + script: |
| 78 | + - uvx nox -s typecheck |
| 79 | + changes: |
| 80 | + - "src/**/*.py" |
| 81 | + - "tests/**/*.py" |
| 82 | + - "noxfile.py" |
| 83 | + - "pyproject.toml" |
| 84 | + - "pyrightconfig.json" |
| 85 | + - ".gitlab-ci.yml" |
| 86 | + |
| 87 | +# Security Checks |
| 88 | +security-python: |
| 89 | + stage: security |
| 90 | + <<: *uv-cache |
| 91 | + <<: *on-merge-requests-and-main |
| 92 | + script: |
| 93 | + - uvx nox -s security-python |
| 94 | + after_script: |
| 95 | + - uv cache prune --ci |
| 96 | + allow_failure: true |
| 97 | + changes: |
| 98 | + - "src/**/*.py" |
| 99 | + - "tests/**/*.py" |
| 100 | + - "noxfile.py" |
| 101 | + - "pyproject.toml" |
| 102 | + - "bandit.yml" |
| 103 | + - ".gitlab-ci.yml" |
| 104 | + |
| 105 | +# Python Tests - Using GitLab Matrix Strategy |
| 106 | +test-python: |
| 107 | + stage: test |
| 108 | + <<: *uv-cache |
| 109 | + <<: *on-merge-requests-and-main |
| 110 | + parallel: |
| 111 | + matrix: |
| 112 | + - PYTHON_VERSION: ["3.9", "3.10", "3.11", "3.12", "3.13"] |
| 113 | + OS_IMAGE: ["bookworm-slim"] |
| 114 | + # Add cross-platform testing for latest Python version |
| 115 | + - PYTHON_VERSION: ["3.13"] |
| 116 | + OS_IMAGE: ["alpine", "bookworm-slim"] |
| 117 | + image: ghcr.io/astral-sh/uv:latest-python$PYTHON_VERSION-$OS_IMAGE |
| 118 | + script: |
| 119 | + - uvx nox -s tests-python-${PYTHON_VERSION//.} |
| 120 | + after_script: |
| 121 | + - uv cache prune --ci |
| 122 | + artifacts: |
| 123 | + reports: |
| 124 | + junit: tests/results/*.xml |
| 125 | + coverage_report: |
| 126 | + coverage_format: cobertura |
| 127 | + path: coverage.xml |
| 128 | + paths: |
| 129 | + - tests/results/ |
| 130 | + - coverage.xml |
| 131 | + expire_in: 5 days |
| 132 | + changes: |
| 133 | + - "src/**/*.py" |
| 134 | + - "tests/**/*.py" |
| 135 | + - "noxfile.py" |
| 136 | + - "pyproject.toml" |
| 137 | + - ".coveragerc" |
| 138 | + - ".gitlab-ci.yml" |
| 139 | + |
| 140 | +{% if cookiecutter.add_rust_extension == 'y' -%} |
| 141 | +# Rust-specific jobs (conditional on rust extension flag) |
| 142 | +.rust-job: &rust-job |
| 143 | + image: rust:latest |
| 144 | + stage: quality |
| 145 | + <<: *on-merge-requests-and-main |
| 146 | + changes: |
| 147 | + - "rust/**/*.rs" |
| 148 | + - "Cargo.toml" |
| 149 | + - ".gitlab-ci.yml" |
| 150 | + |
| 151 | +format-rust: |
| 152 | + <<: *rust-job |
| 153 | + before_script: |
| 154 | + - rustup component add rustfmt |
| 155 | + - curl -LsSf https://astral.sh/uv/install.sh | sh |
| 156 | + - export PATH="$PATH:/root/.cargo/bin" |
| 157 | + script: |
| 158 | + - uvx nox -s format-rust |
| 159 | + |
| 160 | +lint-rust: |
| 161 | + <<: *rust-job |
| 162 | + before_script: |
| 163 | + - rustup component add clippy |
| 164 | + - curl -LsSf https://astral.sh/uv/install.sh | sh |
| 165 | + - export PATH="$PATH:/root/.cargo/bin" |
| 166 | + script: |
| 167 | + - uvx nox -s lint-rust |
| 168 | + |
| 169 | +test-rust: |
| 170 | + <<: *rust-job |
| 171 | + stage: test |
| 172 | + before_script: |
| 173 | + - curl -LsSf https://astral.sh/uv/install.sh | sh |
| 174 | + - export PATH="$PATH:/root/.cargo/bin" |
| 175 | + script: |
| 176 | + - uvx nox -s test-rust |
| 177 | +{%- endif %} |
| 178 | + |
| 179 | +# Build Stage |
| 180 | +build-python: |
| 181 | + stage: build |
| 182 | + <<: *uv-cache |
| 183 | + script: |
| 184 | + - uvx nox -s build-python |
| 185 | + after_script: |
| 186 | + - uv cache prune --ci |
| 187 | + artifacts: |
| 188 | + paths: |
| 189 | + - dist/ |
| 190 | + expire_in: 30 days |
| 191 | + rules: |
| 192 | + - if: $CI_COMMIT_TAG |
| 193 | + - if: $CI_COMMIT_BRANCH == "main" |
| 194 | + - if: $CI_PIPELINE_SOURCE == "web" |
| 195 | + |
| 196 | +# Documentation build (GitLab Pages) |
| 197 | +pages: |
| 198 | + stage: build |
| 199 | + <<: *uv-cache |
| 200 | + script: |
| 201 | + - uvx nox -s build-docs |
| 202 | + - mv docs/_build/html public |
| 203 | + after_script: |
| 204 | + - uv cache prune --ci |
| 205 | + artifacts: |
| 206 | + paths: |
| 207 | + - public |
| 208 | + expire_in: 30 days |
| 209 | + rules: |
| 210 | + - if: $CI_COMMIT_BRANCH == "main" |
| 211 | + changes: |
| 212 | + - "docs/**/*" |
| 213 | + - "src/**/*.py" |
| 214 | + - "noxfile.py" |
| 215 | + - "pyproject.toml" |
| 216 | + |
| 217 | +# Release Job (only on tags) |
| 218 | +release-python: |
| 219 | + stage: release |
| 220 | + <<: *uv-cache |
| 221 | + script: |
| 222 | + - uvx nox -s publish-python |
| 223 | + after_script: |
| 224 | + - uv cache prune --ci |
| 225 | + rules: |
| 226 | + - if: $CI_COMMIT_TAG |
| 227 | + environment: |
| 228 | + name: production |
| 229 | + url: https://pypi.org/project/{{ cookiecutter.package_name }}/ |
0 commit comments