|
6 | 6 | pull_request: |
7 | 7 | branches: [master] |
8 | 8 |
|
| 9 | +permissions: |
| 10 | + contents: read |
| 11 | + |
| 12 | +# A push to a pull request while the previous run is still going restarts it; |
| 13 | +# the old one is answering a question nobody is asking any more. A run on |
| 14 | +# master is left to finish: every commit there should end with a verdict. |
| 15 | +concurrency: |
| 16 | + group: ci-${{ github.workflow }}-${{ github.ref }} |
| 17 | + cancel-in-progress: ${{ github.event_name == 'pull_request' }} |
| 18 | + |
9 | 19 | jobs: |
10 | 20 | lint: |
11 | 21 | name: Lint & type check |
12 | 22 | runs-on: ubuntu-latest |
13 | 23 | steps: |
14 | 24 | - uses: actions/checkout@v7 |
15 | 25 | - uses: astral-sh/setup-uv@v7 |
16 | | - - run: uv sync --group dev |
| 26 | + with: |
| 27 | + enable-cache: true |
| 28 | + cache-dependency-glob: uv.lock |
| 29 | + # A lock file out of step with pyproject.toml fails here, in one line, |
| 30 | + # rather than in an image build three jobs away. |
| 31 | + - run: uv lock --check |
| 32 | + - run: uv sync --frozen --group dev |
17 | 33 | - run: uv run ruff check |
18 | 34 | - run: uv run ruff format --check |
19 | 35 | - run: uv run mypy pg_partsmith |
| 36 | + - name: The workflows parse, and their shell steps pass shellcheck |
| 37 | + run: docker run --rm -v "$PWD:/repo" -w /repo rhysd/actionlint:1.7.12 -color |
| 38 | + - name: Dockerfile lint |
| 39 | + run: docker run --rm -v "$PWD:/repo" -w /repo hadolint/hadolint:v2.15.1 hadolint Dockerfile |
| 40 | + # The Job and CronJob the running guide shows are what a team pastes into |
| 41 | + # a cluster: kubeconform checks them against the API schema, strictly, so |
| 42 | + # a misspelt field fails here and not at kubectl apply. |
| 43 | + - name: The Kubernetes manifests in the guide validate |
| 44 | + run: | |
| 45 | + uv run python scripts/k8s_manifests.py docs/guide/running.md manifests |
| 46 | + docker run --rm -v "$PWD/manifests:/manifests:ro" ghcr.io/yannh/kubeconform:v0.8.0 -strict -summary /manifests |
20 | 47 |
|
21 | | - test-unit: |
22 | | - name: Unit tests (Python ${{ matrix.python-version }}) |
| 48 | + # Every direct dependency at the lowest version pyproject.toml admits, on |
| 49 | + # the oldest Python. The bounds a library declares are a promise, and this |
| 50 | + # is the only job that tests it; everything else runs on the lock file. |
| 51 | + test-lowest: |
| 52 | + name: Lowest declared dependencies (Python 3.11) |
23 | 53 | needs: lint |
24 | 54 | runs-on: ubuntu-latest |
| 55 | + steps: |
| 56 | + - uses: actions/checkout@v7 |
| 57 | + - uses: astral-sh/setup-uv@v7 |
| 58 | + with: |
| 59 | + python-version: "3.11" |
| 60 | + enable-cache: true |
| 61 | + cache-dependency-glob: uv.lock |
| 62 | + cache-suffix: lowest |
| 63 | + - run: uv sync --resolution lowest-direct --no-default-groups --group test --extra cli --extra pydantic-settings |
| 64 | + # An old floor on a new transitive dependency deprecates things between |
| 65 | + # the two; that is theirs to fail on, not this library's. |
| 66 | + - run: uv run --no-sync pytest -W default::DeprecationWarning |
| 67 | + |
| 68 | + test-unit: |
| 69 | + name: Unit tests (${{ matrix.os }}, Python ${{ matrix.python-version }}) |
| 70 | + needs: lint |
| 71 | + runs-on: ${{ matrix.os }} |
25 | 72 | strategy: |
26 | 73 | fail-fast: false |
27 | 74 | matrix: |
28 | | - python-version: ["3.11", "3.12", "3.13"] |
| 75 | + os: [ubuntu-latest] |
| 76 | + python-version: ["3.11", "3.12", "3.13", "3.14"] |
| 77 | + # The other platforms at both ends of the range: the CLI runs |
| 78 | + # subprocesses and handles signals differently on each of them. |
| 79 | + include: |
| 80 | + - { os: windows-latest, python-version: "3.11" } |
| 81 | + - { os: windows-latest, python-version: "3.14" } |
| 82 | + - { os: macos-latest, python-version: "3.11" } |
| 83 | + - { os: macos-latest, python-version: "3.14" } |
| 84 | + - { os: ubuntu-24.04-arm, python-version: "3.14" } |
29 | 85 | steps: |
30 | 86 | - uses: actions/checkout@v7 |
31 | 87 | - uses: astral-sh/setup-uv@v7 |
32 | 88 | with: |
33 | 89 | python-version: ${{ matrix.python-version }} |
34 | | - - run: uv sync --group dev --extra pydantic-settings |
| 90 | + enable-cache: true |
| 91 | + cache-dependency-glob: uv.lock |
| 92 | + - run: uv sync --frozen --group dev --extra pydantic-settings |
35 | 93 | - run: uv run pytest -m unit --cov=pg_partsmith --cov-report=xml |
36 | 94 | - uses: codecov/codecov-action@v7 |
37 | | - if: matrix.python-version == '3.11' |
| 95 | + if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.11' |
38 | 96 | with: |
39 | 97 | token: ${{ secrets.CODECOV_TOKEN }} |
40 | 98 | files: coverage.xml |
41 | 99 | continue-on-error: true |
42 | 100 |
|
43 | | - test-integration: |
44 | | - name: Integration tests (PostgreSQL ${{ matrix.postgres }}) & coverage gate |
| 101 | + # A partition boundary is a moment. The suite runs where the clock is |
| 102 | + # furthest from UTC in either direction, so a naive datetime has nowhere |
| 103 | + # to hide. |
| 104 | + test-unit-far-from-utc: |
| 105 | + name: Unit tests (TZ=${{ matrix.tz }}) |
45 | 106 | needs: lint |
46 | 107 | runs-on: ubuntu-latest |
47 | 108 | strategy: |
48 | 109 | fail-fast: false |
49 | 110 | matrix: |
50 | | - postgres: ["15-alpine", "16-alpine", "17-alpine"] |
| 111 | + tz: [Pacific/Kiritimati, Etc/GMT+12] |
| 112 | + env: |
| 113 | + TZ: ${{ matrix.tz }} |
| 114 | + steps: |
| 115 | + - uses: actions/checkout@v7 |
| 116 | + - uses: astral-sh/setup-uv@v7 |
| 117 | + with: |
| 118 | + python-version: "3.14" |
| 119 | + enable-cache: true |
| 120 | + cache-dependency-glob: uv.lock |
| 121 | + - run: uv sync --frozen --group dev --extra pydantic-settings |
| 122 | + - run: uv run pytest -m unit |
| 123 | + |
| 124 | + test-integration: |
| 125 | + name: Integration tests (${{ matrix.name }}) |
| 126 | + needs: lint |
| 127 | + runs-on: ${{ matrix.os }} |
| 128 | + strategy: |
| 129 | + fail-fast: false |
| 130 | + matrix: |
| 131 | + include: |
| 132 | + - { name: PostgreSQL 15, os: ubuntu-latest, image: postgres:15-alpine } |
| 133 | + - { name: PostgreSQL 16, os: ubuntu-latest, image: postgres:16-alpine } |
| 134 | + - { name: PostgreSQL 17, os: ubuntu-latest, image: postgres:17-alpine } |
| 135 | + - { name: PostgreSQL 18, os: ubuntu-latest, image: postgres:18-alpine } |
| 136 | + - { name: PostgreSQL 17 on arm64, os: ubuntu-24.04-arm, image: postgres:17-alpine } |
| 137 | + # The server's clock at UTC+14 and the client's at UTC-12: a bound |
| 138 | + # written as a date must mean the same day on both sides. |
| 139 | + - name: PostgreSQL 17, server at UTC+14, client at UTC-12 |
| 140 | + os: ubuntu-latest |
| 141 | + image: postgres:17-alpine |
| 142 | + server-tz: Pacific/Kiritimati |
| 143 | + client-tz: Etc/GMT+12 |
| 144 | + # No Docker on these runners; the action brings a server of its own, |
| 145 | + # and the tests that reach into the container skip. |
| 146 | + - { name: PostgreSQL 17 on Windows, os: windows-latest, server: "17" } |
| 147 | + - { name: PostgreSQL 17 on macOS, os: macos-latest, server: "17" } |
51 | 148 | env: |
52 | | - PG_PARTSMITH_TEST_PG_IMAGE: postgres:${{ matrix.postgres }} |
| 149 | + PG_PARTSMITH_TEST_PG_IMAGE: ${{ matrix.image }} |
| 150 | + PG_PARTSMITH_TEST_PG_TZ: ${{ matrix.server-tz }} |
| 151 | + # An unset matrix value is an empty string here, and an empty TZ is not |
| 152 | + # "unset" to everything that reads it; the default is spelled out. |
| 153 | + TZ: ${{ matrix.client-tz || 'UTC' }} |
53 | 154 | steps: |
54 | 155 | - uses: actions/checkout@v7 |
55 | 156 | - uses: astral-sh/setup-uv@v7 |
56 | | - - run: uv sync --group dev --extra pydantic-settings |
| 157 | + with: |
| 158 | + enable-cache: true |
| 159 | + cache-dependency-glob: uv.lock |
| 160 | + - run: uv sync --frozen --group dev --extra pydantic-settings |
| 161 | + - name: A PostgreSQL server of the runner's own |
| 162 | + if: matrix.server |
| 163 | + id: postgres |
| 164 | + uses: ikalnytskyi/action-setup-postgres@v8 |
| 165 | + with: |
| 166 | + postgres-version: ${{ matrix.server }} |
| 167 | + username: partsmith |
| 168 | + password: partsmith |
| 169 | + database: partsmith |
57 | 170 | # Both suites together: the gate is on the whole library, not on one half of it. |
58 | | - - run: uv run pytest --cov=pg_partsmith --cov-report=xml --cov-fail-under=90 |
| 171 | + - name: Both suites, and the coverage gate |
| 172 | + if: ${{ !matrix.server }} |
| 173 | + run: uv run pytest --cov=pg_partsmith --cov-report=xml --cov-fail-under=90 |
| 174 | + - name: The integration suite against the runner's server |
| 175 | + if: matrix.server |
| 176 | + run: uv run pytest -m integration |
| 177 | + env: |
| 178 | + PG_PARTSMITH_TEST_DSN: ${{ steps.postgres.outputs.connection-uri }} |
59 | 179 | - uses: codecov/codecov-action@v7 |
60 | | - if: matrix.postgres == '17-alpine' |
| 180 | + if: matrix.name == 'PostgreSQL 17' |
61 | 181 | with: |
62 | 182 | token: ${{ secrets.CODECOV_TOKEN }} |
63 | 183 | files: coverage.xml |
64 | 184 | continue-on-error: true |
65 | 185 |
|
| 186 | + # What PyPI will get, installed from the wheel alone on each platform: the |
| 187 | + # entry point, the package data, the extra's dependencies, and the whole |
| 188 | + # stack up to the socket. |
| 189 | + package: |
| 190 | + name: Package (${{ matrix.os }}) |
| 191 | + needs: lint |
| 192 | + runs-on: ${{ matrix.os }} |
| 193 | + strategy: |
| 194 | + fail-fast: false |
| 195 | + matrix: |
| 196 | + os: [ubuntu-latest, windows-latest, macos-latest] |
| 197 | + steps: |
| 198 | + - uses: actions/checkout@v7 |
| 199 | + - uses: astral-sh/setup-uv@v7 |
| 200 | + with: |
| 201 | + python-version: "3.14" |
| 202 | + - run: uv build |
| 203 | + - name: The wheel and the sdist pass the checks PyPI and a reader would make |
| 204 | + shell: bash |
| 205 | + run: | |
| 206 | + uvx twine check --strict dist/* |
| 207 | + uvx check-wheel-contents dist/*.whl |
| 208 | + - name: Installed from the wheel alone, the command runs here |
| 209 | + shell: bash |
| 210 | + run: | |
| 211 | + uv venv --python 3.14 smoke |
| 212 | + if [ "$RUNNER_OS" = Windows ]; then BIN=smoke/Scripts; else BIN=smoke/bin; fi |
| 213 | + WHEEL=$("$BIN/python" -c 'import pathlib, sys; print(pathlib.Path(sys.argv[1]).resolve().as_uri())' dist/*.whl) |
| 214 | + # The environment directory, not its interpreter: uv resolves that the |
| 215 | + # same way on every platform, and Windows spells the interpreter differently. |
| 216 | + uv pip install --python smoke "pg-partsmith[cli] @ $WHEEL" |
| 217 | + "$BIN/pg-partsmith" --version |
| 218 | + "$BIN/pg-partsmith" schema | "$BIN/python" -c 'import json, sys; json.load(sys.stdin)' |
| 219 | + # Everything short of a server: the document parses, the driver loads, |
| 220 | + # the connection is refused, and that is exit 5 -- not a traceback. |
| 221 | + set +e |
| 222 | + PYTHONIOENCODING=ascii "$BIN/pg-partsmith" plan -c examples/partitions.minimal.yaml --dsn postgresql://nobody:nobody@127.0.0.1:1/none |
| 223 | + rc=$? |
| 224 | + set -e |
| 225 | + test "$rc" -eq 5 |
| 226 | + - name: Without the extra, the command on PATH says what to install |
| 227 | + shell: bash |
| 228 | + run: | |
| 229 | + uv venv --python 3.14 bare |
| 230 | + if [ "$RUNNER_OS" = Windows ]; then BIN=bare/Scripts; else BIN=bare/bin; fi |
| 231 | + WHEEL=$("$BIN/python" -c 'import pathlib, sys; print(pathlib.Path(sys.argv[1]).resolve().as_uri())' dist/*.whl) |
| 232 | + uv pip install --python bare "pg-partsmith @ $WHEEL" |
| 233 | + set +e |
| 234 | + "$BIN/pg-partsmith" --version 2> bare.err |
| 235 | + rc=$? |
| 236 | + set -e |
| 237 | + test "$rc" -eq 64 |
| 238 | + grep -q 'pip install "pg-partsmith\[cli\]"' bare.err |
| 239 | +
|
| 240 | + image: |
| 241 | + name: Container image (${{ matrix.os }}) |
| 242 | + needs: lint |
| 243 | + runs-on: ${{ matrix.os }} |
| 244 | + strategy: |
| 245 | + fail-fast: false |
| 246 | + matrix: |
| 247 | + # The release builds both architectures; both are built and run here. |
| 248 | + os: [ubuntu-latest, ubuntu-24.04-arm] |
| 249 | + steps: |
| 250 | + - uses: actions/checkout@v7 |
| 251 | + - uses: docker/setup-buildx-action@v3 |
| 252 | + - name: Build |
| 253 | + uses: docker/build-push-action@v6 |
| 254 | + with: |
| 255 | + context: . |
| 256 | + load: true |
| 257 | + tags: pg-partsmith:ci |
| 258 | + build-args: VERSION=ci |
| 259 | + cache-from: type=gha,scope=${{ runner.arch }} |
| 260 | + cache-to: type=gha,mode=max,scope=${{ runner.arch }} |
| 261 | + # Size is the first thing a team evaluating this reads, so a regression in |
| 262 | + # it is a build failure and not a note in a release. |
| 263 | + - name: Size budget |
| 264 | + run: | |
| 265 | + BYTES=$(docker image inspect pg-partsmith:ci -f '{{.Size}}') |
| 266 | + MB=$((BYTES / 1024 / 1024)) |
| 267 | + echo "image is ${MB} MB (budget ${IMAGE_SIZE_BUDGET_MB} MB)" |
| 268 | + test "$MB" -le "$IMAGE_SIZE_BUDGET_MB" |
| 269 | + env: |
| 270 | + IMAGE_SIZE_BUDGET_MB: 160 |
| 271 | + - uses: astral-sh/setup-uv@v7 |
| 272 | + with: |
| 273 | + enable-cache: true |
| 274 | + cache-dependency-glob: uv.lock |
| 275 | + - run: uv sync --frozen --no-default-groups --group test --extra pydantic-settings |
| 276 | + # The image as a container, against a database on a network of its own, |
| 277 | + # run the way the guides say to: read-only, no capabilities, the |
| 278 | + # document mounted, the commands the guides show, the codes they promise. |
| 279 | + - name: End to end |
| 280 | + run: uv run --no-sync pytest -m e2e |
| 281 | + env: |
| 282 | + PG_PARTSMITH_E2E_IMAGE: pg-partsmith:ci |
| 283 | + # One test builds an image FROM pg-partsmith:ci, which was loaded into |
| 284 | + # the daemon; the container builder set up above keeps a store of its |
| 285 | + # own and would go to the registry for it. The daemon's builder sees it. |
| 286 | + BUILDX_BUILDER: default |
| 287 | + - name: Scan |
| 288 | + uses: aquasecurity/trivy-action@v0.36.0 |
| 289 | + with: |
| 290 | + image-ref: pg-partsmith:ci |
| 291 | + severity: CRITICAL,HIGH |
| 292 | + ignore-unfixed: true |
| 293 | + exit-code: "1" |
| 294 | + |
| 295 | + # A dependency a pull request adds or bumps is looked up before it is |
| 296 | + # merged: a known vulnerability or an incompatible license fails the check. |
| 297 | + dependency-review: |
| 298 | + name: New dependencies carry no known vulnerability |
| 299 | + if: github.event_name == 'pull_request' |
| 300 | + runs-on: ubuntu-latest |
| 301 | + steps: |
| 302 | + - uses: actions/checkout@v7 |
| 303 | + - uses: actions/dependency-review-action@v5 |
| 304 | + with: |
| 305 | + fail-on-severity: high |
| 306 | + |
66 | 307 | # Sentinel job — use this as the single required status check in branch protection. |
67 | 308 | all-checks-passed: |
68 | 309 | name: All checks passed |
69 | 310 | if: always() |
70 | | - needs: [lint, test-unit, test-integration] |
| 311 | + needs: [lint, test-lowest, test-unit, test-unit-far-from-utc, test-integration, package, image, dependency-review] |
71 | 312 | runs-on: ubuntu-latest |
72 | 313 | steps: |
73 | 314 | - name: Check all jobs succeeded |
|
0 commit comments