|
| 1 | +# .gitlab-ci.yml |
| 2 | +# See https://docs.gitlab.com/ee/ci/yaml/ |
| 3 | +# This is currently untested and serves as a best guess for what might be an equivalent pipeline |
| 4 | + |
| 5 | +# Global settings |
| 6 | +image: ghcr.io/astral-sh/uv:latest-python3.13-bookworm-slim |
| 7 | + |
| 8 | +variables: |
| 9 | + UV_CACHE_DIR: .uv-cache |
| 10 | + UV_LINK_MODE: copy |
| 11 | + PIP_CACHE_DIR: $CI_PROJECT_DIR/.cache/pip |
| 12 | + |
| 13 | +# Define stages |
| 14 | +stages: |
| 15 | + - quality |
| 16 | + - typecheck |
| 17 | + - test |
| 18 | + - security |
| 19 | + - build |
| 20 | + - release |
| 21 | + |
| 22 | +# Global cache configuration for uv |
| 23 | +.uv-cache: &uv-cache |
| 24 | + cache: |
| 25 | + key: |
| 26 | + files: |
| 27 | + - pyproject.toml |
| 28 | + - uv.lock |
| 29 | + - requirements*.txt |
| 30 | + - "**/requirements*.txt" |
| 31 | + paths: |
| 32 | + - $UV_CACHE_DIR |
| 33 | + - $PIP_CACHE_DIR |
| 34 | + policy: pull-push |
| 35 | + |
| 36 | +# Shared rules for when to run jobs |
| 37 | +.on-merge-requests-and-main: &on-merge-requests-and-main |
| 38 | + rules: |
| 39 | + - if: $CI_PIPELINE_SOURCE == "merge_request_event" |
| 40 | + - if: $CI_COMMIT_BRANCH == "main" |
| 41 | + - if: $CI_PIPELINE_SOURCE == "web" |
| 42 | + |
| 43 | +# File pattern anchors for different job types |
| 44 | +.python-quality-files: &python-quality-files |
| 45 | + - "src/**/*.py" |
| 46 | + - "tests/**/*.py" |
| 47 | + - "noxfile.py" |
| 48 | + - "pyproject.toml" |
| 49 | + - ".ruff.toml" |
| 50 | + - "pyrightconfig.json" |
| 51 | + - ".gitlab-ci.yml" |
| 52 | + |
| 53 | +.python-typecheck-files: &python-typecheck-files |
| 54 | + - "src/**/*.py" |
| 55 | + - "tests/**/*.py" |
| 56 | + - "noxfile.py" |
| 57 | + - "pyproject.toml" |
| 58 | + - "pyrightconfig.json" |
| 59 | + - ".gitlab-ci.yml" |
| 60 | + |
| 61 | +.python-security-files: &python-security-files |
| 62 | + - "src/**/*.py" |
| 63 | + - "tests/**/*.py" |
| 64 | + - "noxfile.py" |
| 65 | + - "pyproject.toml" |
| 66 | + - "bandit.yml" |
| 67 | + - ".gitlab-ci.yml" |
| 68 | + |
| 69 | +.python-test-files: &python-test-files |
| 70 | + - "src/**/*.py" |
| 71 | + - "tests/**/*.py" |
| 72 | + - "noxfile.py" |
| 73 | + - "pyproject.toml" |
| 74 | + - ".coveragerc" |
| 75 | + - ".gitlab-ci.yml" |
| 76 | + |
| 77 | +.docs-files: &docs-files |
| 78 | + - "docs/**/*" |
| 79 | + - "src/**/*.py" |
| 80 | + - "noxfile.py" |
| 81 | + - "pyproject.toml" |
| 82 | + - ".gitlab-ci.yml" |
| 83 | + |
| 84 | +.rust-files: &rust-files |
| 85 | + - "rust/**/*.rs" |
| 86 | + - "Cargo.toml" |
| 87 | + - ".gitlab-ci.yml" |
| 88 | + |
| 89 | +# Base job template for Python quality checks |
| 90 | +.quality-job: &quality-job |
| 91 | + stage: quality |
| 92 | + <<: *uv-cache |
| 93 | + <<: *on-merge-requests-and-main |
| 94 | + before_script: |
| 95 | + - uv --version |
| 96 | + after_script: |
| 97 | + - uv cache prune --ci |
| 98 | + |
| 99 | +# Python Quality Checks Job |
| 100 | +quality-python: |
| 101 | + <<: *quality-job |
| 102 | + script: |
| 103 | + - uvx nox -t quality |
| 104 | + rules: |
| 105 | + - if: $CI_PIPELINE_SOURCE == "merge_request_event" |
| 106 | + changes: *python-quality-files |
| 107 | + - if: $CI_COMMIT_BRANCH == "main" |
| 108 | + changes: *python-quality-files |
| 109 | + - if: $CI_PIPELINE_SOURCE == "web" |
| 110 | + changes: *python-quality-files |
| 111 | + |
| 112 | +typecheck-python: |
| 113 | + stage: typecheck |
| 114 | + <<: *uv-cache |
| 115 | + parallel: |
| 116 | + matrix: |
| 117 | + - PYTHON_VERSION: ["3.9", "3.10", "3.11", "3.12", "3.13"] |
| 118 | + image: ghcr.io/astral-sh/uv:latest-python$PYTHON_VERSION-bookworm-slim |
| 119 | + before_script: |
| 120 | + - uv --version |
| 121 | + script: |
| 122 | + - uvx nox -s typecheck-$PYTHON_VERSION |
| 123 | + after_script: |
| 124 | + - uv cache prune --ci |
| 125 | + rules: |
| 126 | + - if: $CI_PIPELINE_SOURCE == "merge_request_event" |
| 127 | + changes: *python-typecheck-files |
| 128 | + - if: $CI_COMMIT_BRANCH == "main" |
| 129 | + changes: *python-typecheck-files |
| 130 | + - if: $CI_PIPELINE_SOURCE == "web" |
| 131 | + changes: *python-typecheck-files |
| 132 | + |
| 133 | +# Security Checks |
| 134 | +security-python: |
| 135 | + stage: security |
| 136 | + <<: *uv-cache |
| 137 | + script: |
| 138 | + - uvx nox -s security-python |
| 139 | + after_script: |
| 140 | + - uv cache prune --ci |
| 141 | + allow_failure: true |
| 142 | + rules: |
| 143 | + - if: $CI_PIPELINE_SOURCE == "merge_request_event" |
| 144 | + changes: *python-security-files |
| 145 | + - if: $CI_COMMIT_BRANCH == "main" |
| 146 | + changes: *python-security-files |
| 147 | + - if: $CI_PIPELINE_SOURCE == "web" |
| 148 | + changes: *python-security-files |
| 149 | + |
| 150 | +# Python Tests - Using GitLab Matrix Strategy |
| 151 | +test-python: |
| 152 | + stage: test |
| 153 | + <<: *uv-cache |
| 154 | + parallel: |
| 155 | + matrix: |
| 156 | + - PYTHON_VERSION: ["3.9", "3.10", "3.11", "3.12", "3.13"] |
| 157 | + image: ghcr.io/astral-sh/uv:latest-python$PYTHON_VERSION-bookworm-slim |
| 158 | + script: |
| 159 | + - uvx nox -s tests-python-${PYTHON_VERSION//.} |
| 160 | + after_script: |
| 161 | + - uv cache prune --ci |
| 162 | + artifacts: |
| 163 | + reports: |
| 164 | + junit: tests/results/*.xml |
| 165 | + coverage_report: |
| 166 | + coverage_format: cobertura |
| 167 | + path: coverage.xml |
| 168 | + paths: |
| 169 | + - tests/results/ |
| 170 | + - coverage.xml |
| 171 | + expire_in: 5 days |
| 172 | + rules: |
| 173 | + - if: $CI_PIPELINE_SOURCE == "merge_request_event" |
| 174 | + changes: *python-test-files |
| 175 | + - if: $CI_COMMIT_BRANCH == "main" |
| 176 | + changes: *python-test-files |
| 177 | + - if: $CI_PIPELINE_SOURCE == "web" |
| 178 | + changes: *python-test-files |
| 179 | + |
| 180 | +# Cross-platform testing with macOS (GitLab.com SaaS runners) |
| 181 | +test-python-macos: |
| 182 | + stage: test |
| 183 | + tags: |
| 184 | + - saas-macos-medium-m1 |
| 185 | + before_script: |
| 186 | + - curl -LsSf https://astral.sh/uv/install.sh | sh |
| 187 | + - export PATH="$PATH:$HOME/.cargo/bin" |
| 188 | + script: |
| 189 | + - uvx nox -s tests-python-3.13 |
| 190 | + artifacts: |
| 191 | + reports: |
| 192 | + junit: tests/results/*.xml |
| 193 | + coverage_report: |
| 194 | + coverage_format: cobertura |
| 195 | + path: coverage.xml |
| 196 | + paths: |
| 197 | + - tests/results/ |
| 198 | + - coverage.xml |
| 199 | + expire_in: 5 days |
| 200 | + rules: |
| 201 | + - if: $CI_PIPELINE_SOURCE == "merge_request_event" |
| 202 | + changes: *python-test-files |
| 203 | + - if: $CI_COMMIT_BRANCH == "main" |
| 204 | + changes: *python-test-files |
| 205 | + - if: $CI_PIPELINE_SOURCE == "web" |
| 206 | + changes: *python-test-files |
| 207 | + |
| 208 | +# Cross-platform testing with Windows (GitLab.com SaaS runners) |
| 209 | +test-python-windows: |
| 210 | + stage: test |
| 211 | + tags: |
| 212 | + - saas-windows-medium-amd64 |
| 213 | + before_script: |
| 214 | + - powershell -c "irm https://astral.sh/uv/install.ps1 | iex" |
| 215 | + - $env:PATH += ";$env:USERPROFILE\.cargo\bin" |
| 216 | + script: |
| 217 | + - uvx nox -s tests-python-3.13 |
| 218 | + artifacts: |
| 219 | + reports: |
| 220 | + junit: tests/results/*.xml |
| 221 | + coverage_report: |
| 222 | + coverage_format: cobertura |
| 223 | + path: coverage.xml |
| 224 | + paths: |
| 225 | + - tests/results/ |
| 226 | + - coverage.xml |
| 227 | + expire_in: 5 days |
| 228 | + rules: |
| 229 | + - if: $CI_PIPELINE_SOURCE == "merge_request_event" |
| 230 | + changes: *python-test-files |
| 231 | + - if: $CI_COMMIT_BRANCH == "main" |
| 232 | + changes: *python-test-files |
| 233 | + - if: $CI_PIPELINE_SOURCE == "web" |
| 234 | + changes: *python-test-files |
| 235 | + |
| 236 | + |
| 237 | + |
| 238 | +# Build Stage |
| 239 | +build-python: |
| 240 | + stage: build |
| 241 | + <<: *uv-cache |
| 242 | + script: |
| 243 | + - uvx nox -s build-python |
| 244 | + after_script: |
| 245 | + - uv cache prune --ci |
| 246 | + artifacts: |
| 247 | + paths: |
| 248 | + - dist/ |
| 249 | + expire_in: 30 days |
| 250 | + rules: |
| 251 | + - if: $CI_COMMIT_TAG |
| 252 | + - if: $CI_COMMIT_BRANCH == "main" |
| 253 | + - if: $CI_PIPELINE_SOURCE == "web" |
| 254 | + |
| 255 | +# Documentation build validation (ReadTheDocs handles hosting) |
| 256 | +build-docs: |
| 257 | + stage: build |
| 258 | + <<: *uv-cache |
| 259 | + script: |
| 260 | + - uvx nox -s build-docs |
| 261 | + after_script: |
| 262 | + - uv cache prune --ci |
| 263 | + artifacts: |
| 264 | + paths: |
| 265 | + - docs/_build/html/ |
| 266 | + expire_in: 5 days |
| 267 | + rules: |
| 268 | + - if: $CI_PIPELINE_SOURCE == "merge_request_event" |
| 269 | + changes: *docs-files |
| 270 | + - if: $CI_COMMIT_BRANCH == "main" |
| 271 | + changes: *docs-files |
| 272 | + - if: $CI_PIPELINE_SOURCE == "web" |
| 273 | + changes: *docs-files |
| 274 | + |
| 275 | +# Documentation build (GitLab Pages - fallback/mirror) |
| 276 | +pages: |
| 277 | + stage: build |
| 278 | + <<: *uv-cache |
| 279 | + script: |
| 280 | + - uvx nox -s build-docs |
| 281 | + - mv docs/_build/html public |
| 282 | + after_script: |
| 283 | + - uv cache prune --ci |
| 284 | + artifacts: |
| 285 | + paths: |
| 286 | + - public |
| 287 | + expire_in: 30 days |
| 288 | + rules: |
| 289 | + - if: $CI_COMMIT_BRANCH == "main" |
| 290 | + changes: *docs-files |
| 291 | + |
| 292 | +# Test Release Job (TestPyPI) |
| 293 | +test-release-python: |
| 294 | + stage: release |
| 295 | + <<: *uv-cache |
| 296 | + script: |
| 297 | + - export PYPI_URL=https://test.pypi.org/legacy/ |
| 298 | + - uvx nox -s publish-python |
| 299 | + after_script: |
| 300 | + - uv cache prune --ci |
| 301 | + rules: |
| 302 | + - if: $CI_COMMIT_TAG |
| 303 | + environment: |
| 304 | + name: test |
| 305 | + url: https://test.pypi.org/project/robust_python_demo/ |
| 306 | + |
| 307 | +# Production Release Job (PyPI) |
| 308 | +release-python: |
| 309 | + stage: release |
| 310 | + <<: *uv-cache |
| 311 | + script: |
| 312 | + - uvx nox -s publish-python |
| 313 | + after_script: |
| 314 | + - uv cache prune --ci |
| 315 | + rules: |
| 316 | + - if: $CI_COMMIT_TAG |
| 317 | + environment: |
| 318 | + name: production |
| 319 | + url: https://pypi.org/project/robust_python_demo/ |
| 320 | + needs: |
| 321 | + - test-release-python |
| 322 | + when: manual |
0 commit comments