Skip to content

Commit 9004768

Browse files
chore: v0.3.3 code quality, CI improvements, and test coverage
1 parent a29baae commit 9004768

10 files changed

Lines changed: 1032 additions & 386 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Setup Python Environment
2+
description: Setup Python, Poetry, and cache dependencies
3+
4+
inputs:
5+
python-version:
6+
description: Python version
7+
required: false
8+
default: '3.12'
9+
install-dependencies:
10+
description: Whether to install project dependencies
11+
required: false
12+
default: 'true'
13+
14+
runs:
15+
using: composite
16+
steps:
17+
- name: Set up Python
18+
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
19+
with:
20+
python-version: ${{ inputs.python-version }}
21+
22+
- name: Install Poetry
23+
uses: snok/install-poetry@76e04a911780d5b312d89783f7b1cd627778900a # v1.4.1
24+
with:
25+
version: "2.1.3"
26+
virtualenvs-create: true
27+
virtualenvs-in-project: true
28+
installer-parallel: true
29+
30+
- name: Cache virtualenv
31+
if: inputs.install-dependencies == 'true'
32+
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
33+
with:
34+
path: .venv
35+
key: ${{ runner.os }}-py${{ inputs.python-version }}-poetry-${{ hashFiles('**/poetry.lock') }}
36+
restore-keys: |
37+
${{ runner.os }}-py${{ inputs.python-version }}-poetry-
38+
39+
- name: Install dependencies
40+
if: inputs.install-dependencies == 'true'
41+
shell: bash
42+
run: |
43+
poetry sync -n
44+
poetry env info -n

.github/workflows/ci.yml

Lines changed: 48 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,57 @@ on:
66
pull_request:
77
branches: [main]
88

9+
concurrency:
10+
group: ci-${{ github.head_ref || github.sha }}
11+
cancel-in-progress: true
12+
913
jobs:
1014
lint-and-test:
1115
runs-on: ubuntu-latest
16+
timeout-minutes: 10
17+
outputs:
18+
code_changed: ${{ steps.changes.outputs.code_changed }}
1219

1320
steps:
1421
- name: Checkout code
15-
uses: actions/checkout@v4
16-
17-
- name: Set up Python
18-
uses: actions/setup-python@v5
22+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
1923
with:
20-
python-version: '3.12'
24+
fetch-depth: 0
2125

22-
- name: Install Poetry
23-
uses: snok/install-poetry@76e04a911780d5b312d89783f7b1cd627778900a # v1.4.1
24-
with:
25-
version: "2.1.3"
26-
virtualenvs-create: true
27-
virtualenvs-in-project: true
26+
- name: Detect code changes
27+
id: changes
28+
run: |
29+
if [ "${{ github.event_name }}" = "pull_request" ]; then
30+
BASE="${{ github.event.pull_request.base.sha }}"
31+
else
32+
BASE="${{ github.event.before }}"
33+
fi
34+
# Only track files that affect the distributed package.
35+
# Test, CI, and doc changes do not require a version bump or release.
36+
CHANGED=$(git diff --name-only "$BASE" HEAD -- \
37+
'squawk_alembic/' \
38+
'pyproject.toml' \
39+
'.pre-commit-hooks.yaml')
40+
if [ -n "$CHANGED" ]; then
41+
echo "code_changed=true" >> "$GITHUB_OUTPUT"
42+
echo "Code files changed:"
43+
echo "$CHANGED"
44+
else
45+
echo "code_changed=false" >> "$GITHUB_OUTPUT"
46+
echo "Only non-code files changed, skipping version check and release."
47+
fi
2848
29-
- name: Install dependencies
30-
run: poetry install --no-interaction
49+
- name: Setup Python and Poetry
50+
uses: ./.github/actions/setup-python-poetry
3151

3252
- name: Run pre-commit hooks
3353
run: poetry run pre-commit run --all-files
3454

3555
- name: Check version consistency
56+
if: steps.changes.outputs.code_changed == 'true'
3657
run: |
37-
PYPROJECT_VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/' || true)
38-
INIT_VERSION=$(grep '^__version__ = ' squawk_alembic/__init__.py | sed 's/__version__ = "\(.*\)"/\1/' || true)
39-
if [ -z "$PYPROJECT_VERSION" ] || [ -z "$INIT_VERSION" ]; then
40-
echo "::error::Could not parse version from pyproject.toml or __init__.py"
41-
exit 1
42-
fi
58+
PYPROJECT_VERSION=$(poetry version -s)
59+
INIT_VERSION=$(python -c "import squawk_alembic; print(squawk_alembic.__version__)")
4360
if [ "$PYPROJECT_VERSION" != "$INIT_VERSION" ]; then
4461
echo "::error::Version mismatch: pyproject.toml ($PYPROJECT_VERSION) != __init__.py ($INIT_VERSION)"
4562
echo "Run 'make bump VERSION=x.y.z' to update both files."
@@ -49,7 +66,7 @@ jobs:
4966
5067
if [ "${{ github.event_name }}" = "pull_request" ]; then
5168
git fetch origin main --depth=1
52-
MAIN_VERSION=$(git show origin/main:pyproject.toml | grep '^version = ' | sed 's/version = "\(.*\)"/\1/' || true)
69+
MAIN_VERSION=$(git show origin/main:pyproject.toml | python -c "import sys, tomllib; print(tomllib.loads(sys.stdin.read())['tool']['poetry']['version'])" || true)
5370
if [ -z "$MAIN_VERSION" ]; then
5471
echo "::warning::Could not determine version on main, skipping version bump check"
5572
elif [ "$PYPROJECT_VERSION" = "$MAIN_VERSION" ]; then
@@ -64,8 +81,9 @@ jobs:
6481

6582
auto-tag:
6683
needs: lint-and-test
67-
if: github.event_name == 'push'
84+
if: github.event_name == 'push' && needs.lint-and-test.outputs.code_changed == 'true'
6885
runs-on: ubuntu-latest
86+
timeout-minutes: 5
6987
permissions:
7088
contents: write
7189
outputs:
@@ -74,14 +92,19 @@ jobs:
7492

7593
steps:
7694
- name: Checkout code
77-
uses: actions/checkout@v4
95+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
7896
with:
7997
fetch-depth: 0
8098

99+
- name: Setup Python and Poetry
100+
uses: ./.github/actions/setup-python-poetry
101+
with:
102+
install-dependencies: 'false'
103+
81104
- name: Create tag if needed
82105
id: tag
83106
run: |
84-
VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
107+
VERSION=$(poetry version -s)
85108
TAG="v${VERSION}"
86109
87110
echo "Detected version: $VERSION"
@@ -103,12 +126,13 @@ jobs:
103126
needs: auto-tag
104127
if: needs.auto-tag.outputs.created == 'true'
105128
runs-on: ubuntu-latest
129+
timeout-minutes: 5
106130
permissions:
107131
contents: write
108132

109133
steps:
110134
- name: Checkout code
111-
uses: actions/checkout@v4
135+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
112136

113137
- name: Create GitHub Release
114138
env:

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Add the following to your `.pre-commit-config.yaml`:
1111
```yaml
1212
repos:
1313
- repo: https://github.com/kintsugi-tax/squawk-pre-commit
14-
rev: v0.3.0
14+
rev: v0.3.3
1515
hooks:
1616
- id: squawk-alembic
1717
```
@@ -25,7 +25,7 @@ The hook depends on `squawk-cli >= 2.0`. To pin a specific squawk version (match
2525
```yaml
2626
repos:
2727
- repo: https://github.com/kintsugi-tax/squawk-pre-commit
28-
rev: v0.3.0
28+
rev: v0.3.3
2929
hooks:
3030
- id: squawk-alembic
3131
additional_dependencies: ["squawk-cli==2.41.0"]
@@ -40,7 +40,7 @@ To skip migrations that already exist on a branch (useful for repos with existin
4040
```yaml
4141
repos:
4242
- repo: https://github.com/kintsugi-tax/squawk-pre-commit
43-
rev: v0.3.0
43+
rev: v0.3.3
4444
hooks:
4545
- id: squawk-alembic
4646
args: [--diff-branch, main]
@@ -92,6 +92,16 @@ Squawk reads its configuration from `.squawk.toml` in the consumer repo root. Se
9292

9393
Some integration tests in `tests/test_squawk_config.py` require `squawk` on PATH and are automatically skipped if it is not installed.
9494

95+
**Versioning:**
96+
97+
PRs that change package files (`squawk_alembic/`, `pyproject.toml`, `.pre-commit-hooks.yaml`) must include a version bump. CI enforces this. To bump:
98+
99+
```bash
100+
make bump VERSION=0.3.3
101+
```
102+
103+
This updates both `pyproject.toml` and `squawk_alembic/__init__.py`. On merge to main, CI automatically creates a git tag and GitHub release from the new version. Changes to tests, docs, or CI config do not require a version bump.
104+
95105
To test the hook against a consumer repo locally:
96106

97107
```bash

0 commit comments

Comments
 (0)