-
Notifications
You must be signed in to change notification settings - Fork 0
144 lines (124 loc) · 4.62 KB
/
ci.yml
File metadata and controls
144 lines (124 loc) · 4.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
concurrency:
group: ci-${{ github.head_ref || github.sha }}
cancel-in-progress: true
jobs:
lint-and-test:
runs-on: ubuntu-latest
timeout-minutes: 10
outputs:
code_changed: ${{ steps.changes.outputs.code_changed }}
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- name: Detect code changes
id: changes
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
BASE="${{ github.event.pull_request.base.sha }}"
else
BASE="${{ github.event.before }}"
fi
# Only track files that affect the distributed package.
# Test, CI, and doc changes do not require a version bump or release.
CHANGED=$(git diff --name-only "$BASE" HEAD -- \
'squawk_alembic/' \
'pyproject.toml' \
'.pre-commit-hooks.yaml')
if [ -n "$CHANGED" ]; then
echo "code_changed=true" >> "$GITHUB_OUTPUT"
echo "Code files changed:"
echo "$CHANGED"
else
echo "code_changed=false" >> "$GITHUB_OUTPUT"
echo "Only non-code files changed, skipping version check and release."
fi
- name: Setup Python and Poetry
uses: ./.github/actions/setup-python-poetry
- name: Run pre-commit hooks
run: poetry run pre-commit run --all-files
- name: Check version consistency
if: steps.changes.outputs.code_changed == 'true'
run: |
PYPROJECT_VERSION=$(poetry version -s)
INIT_VERSION=$(python -c "import squawk_alembic; print(squawk_alembic.__version__)")
if [ "$PYPROJECT_VERSION" != "$INIT_VERSION" ]; then
echo "::error::Version mismatch: pyproject.toml ($PYPROJECT_VERSION) != __init__.py ($INIT_VERSION)"
echo "Run 'make bump VERSION=x.y.z' to update both files."
exit 1
fi
echo "Versions match: $PYPROJECT_VERSION"
if [ "${{ github.event_name }}" = "pull_request" ]; then
git fetch origin main --depth=1
MAIN_VERSION=$(git show origin/main:pyproject.toml | python -c "import sys, tomllib; print(tomllib.loads(sys.stdin.read())['tool']['poetry']['version'])" || true)
if [ -z "$MAIN_VERSION" ]; then
echo "::warning::Could not determine version on main, skipping version bump check"
elif [ "$PYPROJECT_VERSION" = "$MAIN_VERSION" ]; then
echo "::error::Version $PYPROJECT_VERSION is the same as on main. Please bump the version."
echo "Run 'make bump VERSION=x.y.z' to update both files."
exit 1
fi
fi
- name: Run tests
run: poetry run pytest tests/ -v
auto-tag:
needs: lint-and-test
if: github.event_name == 'push' && needs.lint-and-test.outputs.code_changed == 'true'
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: write
outputs:
tag: ${{ steps.tag.outputs.tag }}
created: ${{ steps.tag.outputs.created }}
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- name: Setup Python and Poetry
uses: ./.github/actions/setup-python-poetry
with:
install-dependencies: 'false'
- name: Create tag if needed
id: tag
run: |
VERSION=$(poetry version -s)
TAG="v${VERSION}"
echo "Detected version: $VERSION"
echo "Tag: $TAG"
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
if git rev-parse "$TAG" >/dev/null 2>&1; then
echo "Tag $TAG already exists. Nothing to do."
echo "created=false" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "Creating and pushing tag $TAG"
git tag "$TAG"
git push origin "$TAG"
echo "created=true" >> "$GITHUB_OUTPUT"
release:
needs: auto-tag
if: needs.auto-tag.outputs.created == 'true'
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ needs.auto-tag.outputs.tag }}
run: |
gh release create "$TAG" \
--title "Release $TAG" \
--generate-notes