Skip to content

Commit 4d8acd4

Browse files
author
Jürgen Zornig
committed
feat: CI workflows, Update fixture impl, runnable examples/
- .github/workflows/ci.yml: pytest on Python 3.12 + 3.13 + uv build - .github/workflows/publish.yml: PyPI Trusted Publishing on release - Update fixture: full DBFit-compatible impl with '=' WHERE-column convention (SQLite-backed unit tests, 7 cases) - examples/: three runnable .test.md suites - 01-hello: smallest possible Query test - 02-stored-procedure: Insert+capture, Execute Procedure, <<read, :bind - 03-schema-drift: Inspect Table as anti-flake schema lock - README: link to examples/ from Quickstart
1 parent 4cbc89e commit 4d8acd4

19 files changed

Lines changed: 468 additions & 9 deletions

.github/workflows/ci.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
# Cancel in-progress runs for the same ref when a new commit arrives.
10+
concurrency:
11+
group: ci-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
test:
16+
name: Tests (Python ${{ matrix.python }})
17+
runs-on: ubuntu-latest
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
python: ['3.12', '3.13']
22+
23+
steps:
24+
- uses: actions/checkout@v4
25+
26+
- name: Install uv
27+
uses: astral-sh/setup-uv@v6
28+
with:
29+
enable-cache: true
30+
31+
- name: Set up Python ${{ matrix.python }}
32+
run: uv python install ${{ matrix.python }}
33+
34+
- name: Install project + dev dependencies
35+
run: uv sync --python ${{ matrix.python }}
36+
37+
# Live database tests are gated behind `skipif` on the presence of
38+
# local connection.properties files — on CI runners they will skip
39+
# automatically, so unit-only execution is the default here.
40+
- name: Run tests
41+
run: uv run python -m pytest -q --tb=short
42+
43+
build:
44+
name: Build sdist + wheel
45+
runs-on: ubuntu-latest
46+
needs: test
47+
steps:
48+
- uses: actions/checkout@v4
49+
- uses: astral-sh/setup-uv@v6
50+
with:
51+
enable-cache: true
52+
- run: uv build
53+
- name: Upload artifacts
54+
uses: actions/upload-artifact@v4
55+
with:
56+
name: dist-${{ github.sha }}
57+
path: dist/
58+
retention-days: 7

.github/workflows/publish.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Publish to PyPI
2+
3+
# Triggered when a GitHub Release is published. Tag the release with
4+
# the version (e.g. `v0.2.0`) — the workflow builds wheel + sdist and
5+
# publishes via PyPI Trusted Publishing (OIDC, no API token).
6+
#
7+
# One-time setup on PyPI: create a Trusted Publisher entry under
8+
# https://pypi.org/manage/project/dbression/settings/publishing/
9+
# with:
10+
# * Owner: angrydat
11+
# * Repository name: dbression
12+
# * Workflow name: publish.yml
13+
# * Environment: pypi
14+
on:
15+
release:
16+
types: [published]
17+
18+
# Allow manual runs for emergencies / re-publishes from a tag.
19+
workflow_dispatch:
20+
21+
jobs:
22+
build:
23+
name: Build distributions
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v4
27+
- uses: astral-sh/setup-uv@v6
28+
- run: uv build
29+
- uses: actions/upload-artifact@v4
30+
with:
31+
name: dist
32+
path: dist/
33+
34+
publish:
35+
name: Publish to PyPI
36+
needs: build
37+
runs-on: ubuntu-latest
38+
environment:
39+
name: pypi
40+
url: https://pypi.org/p/dbression
41+
permissions:
42+
id-token: write # required for Trusted Publishing (OIDC)
43+
steps:
44+
- uses: actions/download-artifact@v4
45+
with:
46+
name: dist
47+
path: dist/
48+
- uses: pypa/gh-action-pypi-publish@release/v1
49+
with:
50+
# Optional belt-and-braces: verify package metadata before upload.
51+
verify-metadata: true

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,16 @@ the model gets every detail it needs to suggest a fix, no screenshots, no contex
5555

5656
```bash
5757
# install (we use uv, but pip works too)
58-
uv tool install git+https://github.com/<your-org>/dbression.git
58+
uv tool install git+https://github.com/angrydat/dbression.git
5959

6060
# run
6161
dbression run tests/
6262
```
6363

64+
There's also an [`examples/`](examples/) folder with three runnable demo suites
65+
(hello-SQL, stored-procedure-with-capture, schema-drift via `Inspect Table`) — each
66+
file is browsable Markdown *and* an executable test.
67+
6468
### Your first test
6569

6670
Drop a `.wiki` file in a folder with a `_root.wiki` and a `connection.properties`:

examples/01-hello/HelloSql.test.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Hello SQL
2+
3+
The smallest possible test: one Query, one expected row.
4+
5+
### Query
6+
7+
```sql
8+
select 'OK' as connection
9+
```
10+
11+
| connection |
12+
|------------|
13+
| OK |

examples/01-hello/_root.wiki

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
!|DatabaseEnvironment|postgres|
2+
|ConnectUsingFile|connection.properties|
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
### Point this at any Postgres you have lying around.
2+
service=${PG_HOST:-localhost}
3+
username=${PG_USER:-postgres}
4+
password=${POSTGRES_PASSWORD}
5+
database=${PG_DB:-postgres}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Bump counter
2+
3+
Demonstrates four DBFit conventions back-to-back:
4+
5+
1. **Insert** with a capture column (`>>row_id`) — Postgres `RETURNING` is generated automatically.
6+
2. **Set Parameter** stores a constant in the symbol table.
7+
3. **Execute Procedure** is dialect-aware: `SELECT name(args)` on Postgres, `EXEC name args` on SQL Server, `BEGIN name(args); END;` on Oracle.
8+
4. **Query** with `<<symbol_read` inside the expected cell, and `:bind` inside the SQL.
9+
10+
### Insert counter
11+
12+
| label | >>row_id |
13+
|---------|----------|
14+
| widgets | |
15+
16+
### Set Parameter expected_hits 3
17+
18+
### Execute Procedure bump_counter p_label
19+
20+
| p_label |
21+
|---------|
22+
| widgets |
23+
| widgets |
24+
| widgets |
25+
26+
### Query
27+
28+
```sql
29+
select hits from counter where id = :row_id
30+
```
31+
32+
| hits |
33+
|----------------|
34+
| <<expected_hits|
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Setup — a temp table and a procedure to test
2+
3+
Both DDL statements run inside the same suite transaction as the test, so they vanish
4+
when SuiteTearDown rolls back.
5+
6+
### Execute
7+
8+
```sql
9+
CREATE TEMP TABLE counter (id integer GENERATED ALWAYS AS IDENTITY, label text, hits integer NOT NULL DEFAULT 0)
10+
```
11+
12+
### Execute
13+
14+
```sql
15+
CREATE OR REPLACE FUNCTION bump_counter(p_label text)
16+
RETURNS void
17+
LANGUAGE plpgsql
18+
AS $$
19+
BEGIN
20+
UPDATE counter SET hits = hits + 1 WHERE label = p_label;
21+
END;
22+
$$
23+
```
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Teardown
2+
3+
The whole suite ran inside a single transaction. Roll it back to leave the database
4+
untouched — even the temp table and function disappear.
5+
6+
### DatabaseEnvironment
7+
8+
| rollback |
9+
|----------|
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
!|DatabaseEnvironment|postgres|
2+
|ConnectUsingFile|connection.properties|

0 commit comments

Comments
 (0)