Skip to content

Commit 34fb9ba

Browse files
Merge pull request #43 from bedrock-python/feat/cli-and-container
feat: a CLI, an image, and hooks reachable from a config file (#32)
2 parents da0e1d9 + 5009656 commit 34fb9ba

104 files changed

Lines changed: 11172 additions & 214 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.dockerignore‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Everything the build does not need: the image is measured, and a build
2+
# context that carries the test suite and a virtualenv is how it stops being.
3+
*
4+
!pyproject.toml
5+
!uv.lock
6+
!README.md
7+
!LICENSE
8+
!CHANGELOG.md
9+
!pg_partsmith/**
10+
pg_partsmith/**/__pycache__/

‎.github/dependabot.yml‎

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
1+
# What moves under this project without a commit of its own: the base images,
2+
# the actions the workflows run, and the lock file. Each gets one pull request
3+
# a week, so a security rebuild of the image is a merge and a release rather
4+
# than a hunt for which digest to bump.
15
version: 2
26
updates:
3-
- package-ecosystem: "pip"
4-
directory: "/"
7+
- package-ecosystem: docker
8+
directory: /
59
schedule:
6-
interval: "weekly"
7-
day: "monday"
10+
interval: weekly
11+
labels: [dependencies, image]
12+
13+
- package-ecosystem: github-actions
14+
directory: /
15+
schedule:
16+
interval: weekly
17+
labels: [dependencies, ci]
818
groups:
9-
dev-dependencies:
10-
dependency-type: "development"
11-
open-pull-requests-limit: 5
19+
actions:
20+
patterns: ["*"]
1221

13-
- package-ecosystem: "github-actions"
14-
directory: "/"
22+
- package-ecosystem: uv
23+
directory: /
1524
schedule:
16-
interval: "weekly"
17-
day: "monday"
18-
open-pull-requests-limit: 5
25+
interval: weekly
26+
labels: [dependencies]
27+
groups:
28+
dev:
29+
dependency-type: development

‎.github/workflows/ci.yml‎

Lines changed: 255 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,68 +6,309 @@ on:
66
pull_request:
77
branches: [master]
88

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+
919
jobs:
1020
lint:
1121
name: Lint & type check
1222
runs-on: ubuntu-latest
1323
steps:
1424
- uses: actions/checkout@v7
1525
- 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
1733
- run: uv run ruff check
1834
- run: uv run ruff format --check
1935
- 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
2047
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)
2353
needs: lint
2454
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 }}
2572
strategy:
2673
fail-fast: false
2774
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" }
2985
steps:
3086
- uses: actions/checkout@v7
3187
- uses: astral-sh/setup-uv@v7
3288
with:
3389
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
3593
- run: uv run pytest -m unit --cov=pg_partsmith --cov-report=xml
3694
- uses: codecov/codecov-action@v7
37-
if: matrix.python-version == '3.11'
95+
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.11'
3896
with:
3997
token: ${{ secrets.CODECOV_TOKEN }}
4098
files: coverage.xml
4199
continue-on-error: true
42100

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 }})
45106
needs: lint
46107
runs-on: ubuntu-latest
47108
strategy:
48109
fail-fast: false
49110
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" }
51148
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' }}
53154
steps:
54155
- uses: actions/checkout@v7
55156
- 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
57170
# 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 }}
59179
- uses: codecov/codecov-action@v7
60-
if: matrix.postgres == '17-alpine'
180+
if: matrix.name == 'PostgreSQL 17'
61181
with:
62182
token: ${{ secrets.CODECOV_TOKEN }}
63183
files: coverage.xml
64184
continue-on-error: true
65185

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+
66307
# Sentinel job — use this as the single required status check in branch protection.
67308
all-checks-passed:
68309
name: All checks passed
69310
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]
71312
runs-on: ubuntu-latest
72313
steps:
73314
- name: Check all jobs succeeded

0 commit comments

Comments
 (0)