66 pull_request :
77 branches : [main]
88
9+ concurrency :
10+ group : ci-${{ github.head_ref || github.sha }}
11+ cancel-in-progress : true
12+
913jobs :
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."
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
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 :
0 commit comments