-
Notifications
You must be signed in to change notification settings - Fork 11
319 lines (276 loc) · 10.8 KB
/
release.yml
File metadata and controls
319 lines (276 loc) · 10.8 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
name: Release
on:
schedule:
# Monday-Wednesday at 2 AM UTC: alpha builds from dev
- cron: "0 2 * * 1-3"
# Thursday at 2 AM UTC: beta builds from dev
- cron: "0 2 * * 4"
workflow_dispatch:
inputs:
release_type:
description: "Release type"
required: true
type: choice
options:
- alpha
- beta
- stable
dry_run:
description: "Dry run (skip PyPI publish)"
required: false
default: false
type: boolean
force_build:
description: "Force build even if no changes"
required: false
default: false
type: boolean
version_override:
description: "Override version (e.g. 4.4.0) — stable only"
required: false
type: string
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
jobs:
# ── 1. Determine release type and check for changes ──────────────────
determine-release:
runs-on: ubuntu-latest
outputs:
release_type: ${{ steps.resolve.outputs.release_type }}
has_changes: ${{ steps.changes.outputs.has_changes }}
target_branch: ${{ steps.resolve.outputs.target_branch }}
steps:
- name: Resolve release type
id: resolve
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
TYPE="${{ inputs.release_type }}"
elif [ "${{ github.event.schedule }}" = "0 2 * * 4" ]; then
TYPE="beta"
else
TYPE="alpha"
fi
if [ "$TYPE" = "stable" ]; then
BRANCH="main"
else
BRANCH="dev"
fi
echo "release_type=$TYPE" >> $GITHUB_OUTPUT
echo "target_branch=$BRANCH" >> $GITHUB_OUTPUT
echo "Release type: $TYPE from $BRANCH"
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ steps.resolve.outputs.target_branch }}
- name: Check for changes
id: changes
run: |
TYPE="${{ steps.resolve.outputs.release_type }}"
if [ "$TYPE" = "alpha" ]; then
LAST_TAG=$(git tag -l "*a*" --sort=-version:refname | head -n1)
elif [ "$TYPE" = "beta" ]; then
LAST_TAG=$(git tag -l "*b*" --sort=-version:refname | head -n1)
else
LAST_TAG=$(git describe --tags --abbrev=0 --match "v[0-9]*.[0-9]*.[0-9]*" 2>/dev/null || echo "")
fi
if [ -z "$LAST_TAG" ]; then
COMMIT_COUNT=$(git rev-list --count --since="7 days ago" HEAD)
else
COMMIT_COUNT=$(git rev-list --count ${LAST_TAG}..HEAD)
fi
echo "Commits since ${LAST_TAG:-'(none)'}: $COMMIT_COUNT"
if [ "$COMMIT_COUNT" -gt 0 ] || [ "${{ inputs.force_build }}" = "true" ]; then
echo "has_changes=true" >> $GITHUB_OUTPUT
else
echo "has_changes=false" >> $GITHUB_OUTPUT
echo "No changes detected, skipping release"
fi
# ── 2. Test gate ──────────────────────────────────────────────────────
test:
needs: determine-release
if: needs.determine-release.outputs.has_changes == 'true'
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ needs.determine-release.outputs.target_branch }}
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
- name: Install Tesseract OCR
run: |
sudo apt-get update
sudo apt-get install -y tesseract-ocr libtesseract-dev
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[all,dev]"
pip install -r requirements-dev.txt
pip install https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.7.1/en_core_web_sm-3.7.1.tar.gz
- name: Run tests with segfault protection
run: |
python run_tests.py tests/ --ignore=tests/test_gliner_annotator.py --cov-report=xml --cov-config=.coveragerc
- name: Run performance validation
run: |
OMP_NUM_THREADS=4 MKL_NUM_THREADS=4 OPENBLAS_NUM_THREADS=4 python tests/simple_performance_test.py
# ── 3. Build & Publish ────────────────────────────────────────────────
publish:
needs: [determine-release, test]
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ needs.determine-release.outputs.target_branch }}
token: ${{ secrets.GH_PAT }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build twine bump2version
- name: Configure git
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
- name: Generate version
id: version
run: |
set -e
git fetch --tags
TYPE="${{ needs.determine-release.outputs.release_type }}"
CURRENT=$(sed -n 's/^__version__ = "\([^"]*\)"/\1/p' datafog/__about__.py)
if [ -z "$CURRENT" ]; then
echo "Failed to parse current version from datafog/__about__.py"
exit 1
fi
echo "Current version: $CURRENT"
# Strip any pre-release suffix to get base version
BASE=$(echo "$CURRENT" | sed -E 's/(a|b)[0-9]+([.][0-9A-Za-z]+)?$//')
echo "Base version: $BASE"
if [ "$TYPE" = "alpha" ]; then
ALPHA_NUM=1
while git tag -l "v${BASE}a${ALPHA_NUM}" | grep -q .; do
ALPHA_NUM=$((ALPHA_NUM + 1))
done
VERSION="${BASE}a${ALPHA_NUM}"
elif [ "$TYPE" = "beta" ]; then
BETA_NUM=1
while git tag -l "v${BASE}b${BETA_NUM}" | grep -q .; do
BETA_NUM=$((BETA_NUM + 1))
done
VERSION="${BASE}b${BETA_NUM}"
else
# Stable: use override or base version
if [ -n "${{ inputs.version_override }}" ]; then
VERSION="${{ inputs.version_override }}"
else
VERSION="$BASE"
fi
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Publishing version: $VERSION"
sed -i "s/__version__ = \".*\"/__version__ = \"$VERSION\"/" datafog/__about__.py
if grep -q 'version="' setup.py 2>/dev/null; then
sed -i "s/version=\".*\"/version=\"$VERSION\"/" setup.py
fi
- name: Generate changelog
run: |
TYPE="${{ needs.determine-release.outputs.release_type }}"
if [ "$TYPE" = "alpha" ]; then
python scripts/generate_changelog.py --alpha --output RELEASE_CHANGELOG.md
elif [ "$TYPE" = "beta" ]; then
python scripts/generate_changelog.py --beta --output RELEASE_CHANGELOG.md
else
python scripts/generate_changelog.py --output RELEASE_CHANGELOG.md
fi
- name: Build package
run: |
python -m build
python scripts/check_wheel_size.py
- name: Publish to PyPI
if: inputs.dry_run != true
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
python -m twine upload dist/* --verbose
- name: Commit version bump & create release
if: inputs.dry_run != true
env:
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
run: |
VERSION="${{ steps.version.outputs.version }}"
TYPE="${{ needs.determine-release.outputs.release_type }}"
BRANCH="${{ needs.determine-release.outputs.target_branch }}"
git add datafog/__about__.py setup.py
git commit -m "chore: bump version to $VERSION [skip ci]" || echo "No version changes to commit"
git push origin "$BRANCH"
git tag -a "v$VERSION" -m "Release $VERSION"
git push origin "v$VERSION"
PRERELEASE_FLAG=""
TITLE=""
if [ "$TYPE" = "alpha" ]; then
PRERELEASE_FLAG="--prerelease"
TITLE="Nightly Alpha $VERSION"
elif [ "$TYPE" = "beta" ]; then
PRERELEASE_FLAG="--prerelease"
TITLE="Beta Release $VERSION"
else
TITLE="DataFog v$VERSION"
fi
gh release create "v$VERSION" \
--title "$TITLE" \
--notes-file RELEASE_CHANGELOG.md \
$PRERELEASE_FLAG \
--target "$BRANCH" \
dist/*
- name: Dry run summary
if: inputs.dry_run == true
run: |
echo "DRY RUN COMPLETE"
echo "Would have published: ${{ steps.version.outputs.version }}"
echo "Package contents:"
ls -la dist/
# ── 4. Cleanup old pre-releases ───────────────────────────────────────
cleanup:
needs: [determine-release, publish]
if: needs.determine-release.outputs.release_type != 'stable' && inputs.dry_run != true
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Prune old alpha releases (keep 7)
if: needs.determine-release.outputs.release_type == 'alpha'
env:
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
run: |
echo "Cleaning up old alpha releases (keep last 7)..."
ALPHA_RELEASES=$(gh release list --limit 50 | grep -i alpha | tail -n +8 | cut -f3)
for release in $ALPHA_RELEASES; do
echo "Deleting old alpha release: $release"
gh release delete "$release" --yes || true
git push --delete origin "$release" 2>/dev/null || true
done
- name: Prune old beta releases (keep 5)
if: needs.determine-release.outputs.release_type == 'beta'
env:
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
run: |
echo "Cleaning up old beta releases (keep last 5)..."
BETA_RELEASES=$(gh release list --limit 30 | grep -i beta | tail -n +6 | cut -f3)
for release in $BETA_RELEASES; do
echo "Deleting old beta release: $release"
gh release delete "$release" --yes || true
git push --delete origin "$release" 2>/dev/null || true
done