-
Notifications
You must be signed in to change notification settings - Fork 1
467 lines (401 loc) Β· 15.9 KB
/
release.yml
File metadata and controls
467 lines (401 loc) Β· 15.9 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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
name: Release and Deployment
on:
push:
tags:
- 'v*.*.*'
workflow_dispatch:
inputs:
version:
description: 'Version to release (e.g., 1.0.0)'
required: true
type: string
pre_release:
description: 'Is this a pre-release?'
required: false
default: false
type: boolean
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
permissions: {}
env:
PYTHON_VERSION: "3.11"
UV_VERSION: "0.5.7"
HYPOTHESIS_NO_NPY: "1"
jobs:
prepare-release:
name: Prepare Release
runs-on: ubuntu-latest
outputs:
version: ${{ steps.extract-version.outputs.version }}
tag: ${{ steps.extract-version.outputs.tag }}
is_prerelease: ${{ steps.extract-version.outputs.is_prerelease }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Extract version information
id: extract-version
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
VERSION="${{ github.event.inputs.version }}"
TAG="v${VERSION}"
IS_PRERELEASE="${{ github.event.inputs.pre_release }}"
else
TAG="${GITHUB_REF#refs/tags/}"
VERSION="${TAG#v}"
# Check if it's a prerelease (contains alpha, beta, rc, or dev)
if [[ "$VERSION" =~ (alpha|beta|rc|dev) ]]; then
IS_PRERELEASE="true"
else
IS_PRERELEASE="false"
fi
fi
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "tag=${TAG}" >> $GITHUB_OUTPUT
echo "is_prerelease=${IS_PRERELEASE}" >> $GITHUB_OUTPUT
echo "Release Details:"
echo " Version: ${VERSION}"
echo " Tag: ${TAG}"
echo " Pre-release: ${IS_PRERELEASE}"
- name: Validate version format
run: |
VERSION="${{ steps.extract-version.outputs.version }}"
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+([a-zA-Z0-9\.\-]+)?$ ]]; then
echo "β Invalid version format: $VERSION"
echo "Expected format: MAJOR.MINOR.PATCH or MAJOR.MINOR.PATCH-PRERELEASE"
exit 1
fi
echo "β
Version format is valid: $VERSION"
quality-gate:
name: Release Quality Gate
runs-on: ubuntu-latest
needs: prepare-release
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install UV
uses: astral-sh/setup-uv@v5
with:
version: ${{ env.UV_VERSION }}
- name: Set up Python
run: uv python install ${{ env.PYTHON_VERSION }}
- name: Install dependencies
run: |
uv sync --all-extras --dev
- name: Run comprehensive test suite
run: |
echo "π§ͺ Running comprehensive test suite for release..."
uv run pytest src/codomyrmex/tests/unit/ -v --tb=short --cov=src/codomyrmex --cov-report=xml --cov-fail-under=40
- name: Run security checks
run: |
echo "π Running security checks..."
uv run bandit -r src/codomyrmex/ -ll || true
- name: Run linting checks
run: |
echo "π Running linting checks..."
uv run ruff check . --output-format=github
uv run ruff format --check .
uv run black --check .
- name: Validate package metadata
run: |
echo "π Validating package metadata..."
uv build
uv run python -m pip install twine
uv run twine check dist/*
build-artifacts:
name: Build Release Artifacts
runs-on: ubuntu-latest
needs: [prepare-release, quality-gate]
strategy:
matrix:
include:
- target: "source"
build_cmd: "uv build --sdist"
- target: "wheel"
build_cmd: "uv build --wheel"
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install UV
uses: astral-sh/setup-uv@v5
with:
version: ${{ env.UV_VERSION }}
- name: Set up Python
run: uv python install ${{ env.PYTHON_VERSION }}
- name: Install dependencies
run: |
uv sync --all-extras --dev
- name: Update version in pyproject.toml
run: |
VERSION="${{ needs.prepare-release.outputs.version }}"
echo "π Updating version to $VERSION in pyproject.toml"
sed -i "s/version = \".*\"/version = \"$VERSION\"/" pyproject.toml
# Verify the change
grep "version = " pyproject.toml
- name: Build ${{ matrix.target }}
run: |
echo "ποΈ Building ${{ matrix.target }} artifact..."
${{ matrix.build_cmd }}
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: dist-${{ matrix.target }}
path: dist/
create-release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: [prepare-release, build-artifacts]
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: ./artifacts
- name: Prepare artifacts for release
run: |
echo "π¦ Preparing release artifacts..."
mkdir -p release-assets
# Collect all distribution files
find ./artifacts -name "*.whl" -o -name "*.tar.gz" | while read -r file; do
cp "$file" release-assets/
done
ls -la release-assets/
- name: Generate release notes
id: generate_notes
run: |
VERSION="${{ needs.prepare-release.outputs.version }}"
TAG="${{ needs.prepare-release.outputs.tag }}"
echo "# Release Notes for $TAG" > release-notes.md
echo "" >> release-notes.md
echo "## What's New" >> release-notes.md
echo "" >> release-notes.md
# Try to extract changelog information
if [ -f "CHANGELOG.md" ]; then
echo "π Extracting changelog for version $VERSION..."
# Look for version-specific changes
awk "/## \[$VERSION\]/{flag=1; next} /## \[/{flag=0} flag" CHANGELOG.md >> release-notes.md || true
if [ ! -s release-notes.md ] || [ "$(wc -l < release-notes.md)" -le 4 ]; then
echo "π No specific changelog found, using recent changes..."
echo "### Recent Changes" >> release-notes.md
echo "" >> release-notes.md
echo "- See [CHANGELOG.md](./CHANGELOG.md) for detailed changes" >> release-notes.md
fi
else
echo "### Features" >> release-notes.md
echo "" >> release-notes.md
echo "- This release includes various improvements and bug fixes" >> release-notes.md
fi
echo "" >> release-notes.md
echo "## Installation" >> release-notes.md
echo "" >> release-notes.md
echo "\`\`\`bash" >> release-notes.md
echo "uv pip install codomyrmex==$VERSION" >> release-notes.md
echo "\`\`\`" >> release-notes.md
echo "" >> release-notes.md
echo "## Assets" >> release-notes.md
echo "" >> release-notes.md
echo "- **Source Distribution**: \`codomyrmex-$VERSION.tar.gz\`" >> release-notes.md
echo "- **Wheel Distribution**: \`codomyrmex-$VERSION-py3-none-any.whl\`" >> release-notes.md
echo "Generated release notes:"
cat release-notes.md
- name: Create GitHub Release
id: create_release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.prepare-release.outputs.tag }}
name: ${{ needs.prepare-release.outputs.tag }}
body_path: ./release-notes.md
draft: false
prerelease: ${{ needs.prepare-release.outputs.is_prerelease }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload Release Assets
uses: softprops/action-gh-release@v2
with:
files: release-assets/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish-pypi:
name: Publish to PyPI
runs-on: ubuntu-latest
needs: [prepare-release, create-release]
environment: pypi
permissions:
id-token: write
if: needs.prepare-release.outputs.is_prerelease == 'false'
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: ./artifacts
- name: Prepare artifacts for PyPI
run: |
echo "π¦ Preparing artifacts for PyPI..."
mkdir -p dist
find ./artifacts -name "*.whl" -o -name "*.tar.gz" | while read -r file; do
cp "$file" dist/
done
ls -la dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://upload.pypi.org/legacy/
print-hash: true
verbose: true
publish-test-pypi:
name: Publish to Test PyPI
runs-on: ubuntu-latest
needs: [prepare-release, create-release]
environment: test-pypi
permissions:
id-token: write
if: needs.prepare-release.outputs.is_prerelease == 'true'
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: ./artifacts
- name: Prepare artifacts for Test PyPI
run: |
echo "π¦ Preparing artifacts for Test PyPI..."
mkdir -p dist
find ./artifacts -name "*.whl" -o -name "*.tar.gz" | while read -r file; do
cp "$file" dist/
done
ls -la dist/
- name: Publish to Test PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
print-hash: true
verbose: true
verify-release:
name: Verify Release
runs-on: ubuntu-latest
needs: [prepare-release, publish-pypi, publish-test-pypi]
if: always() && (needs.publish-pypi.result == 'success' || needs.publish-test-pypi.result == 'success')
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"]
steps:
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Determine PyPI source
id: pypi_source
run: |
if [[ "${{ needs.prepare-release.outputs.is_prerelease }}" == "true" ]]; then
echo "source=test-pypi" >> $GITHUB_OUTPUT
echo "index_url=--index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/" >> $GITHUB_OUTPUT
else
echo "source=pypi" >> $GITHUB_OUTPUT
echo "index_url=" >> $GITHUB_OUTPUT
fi
- name: Test installation from ${{ steps.pypi_source.outputs.source }}
run: |
VERSION="${{ needs.prepare-release.outputs.version }}"
echo "π§ͺ Testing installation of codomyrmex==$VERSION from ${{ steps.pypi_source.outputs.source }}"
# Retry installation with backoff to wait for package propagation
for i in {1..10}; do
uv pip install ${{ steps.pypi_source.outputs.index_url }} codomyrmex==$VERSION && break
echo "Attempt $i failed, retrying in 30 seconds..."
sleep 30
done
# Basic functionality test
python -c "
import codomyrmex
print('β
Package imported successfully')
print(f'Version: {getattr(codomyrmex, \"__version__\", \"unknown\")}')
"
- name: Test CLI functionality
run: |
echo "π§ͺ Testing CLI functionality..."
codomyrmex --help || echo "CLI test completed"
update-documentation:
name: Update Release Documentation
runs-on: ubuntu-latest
needs: [prepare-release, create-release]
if: needs.prepare-release.outputs.is_prerelease == 'false'
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Configure git identity
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Update version references
run: |
VERSION="${{ needs.prepare-release.outputs.version }}"
echo "π Updating version references in documentation..."
# Update README.md if it contains version references
if grep -q "version" README.md; then
sed -i "s/version [0-9]\+\.[0-9]\+\.[0-9]\+/version $VERSION/g" README.md || true
fi
# Update installation instructions
find . -name "*.md" -exec grep -l "uv pip install codomyrmex" {} \; | while read -r file; do
sed -i "s/codomyrmex==[0-9]\+\.[0-9]\+\.[0-9]\+/codomyrmex==$VERSION/g" "$file" || true
done
- name: Trigger documentation rebuild
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
event-type: release-documentation-update
client-payload: '{"version": "${{ needs.prepare-release.outputs.version }}"}'
release-status:
name: Release Status
runs-on: ubuntu-latest
needs: [prepare-release, quality-gate, build-artifacts, create-release, publish-pypi, publish-test-pypi, verify-release]
if: always()
steps:
- name: Generate Release Summary
run: |
echo "# π Release Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Version**: ${{ needs.prepare-release.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "**Tag**: ${{ needs.prepare-release.outputs.tag }}" >> $GITHUB_STEP_SUMMARY
echo "**Pre-release**: ${{ needs.prepare-release.outputs.is_prerelease }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "## Status" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [[ "${{ needs.quality-gate.result }}" == "success" ]]; then
echo "β
**Quality Gate**: Passed" >> $GITHUB_STEP_SUMMARY
else
echo "β **Quality Gate**: Failed" >> $GITHUB_STEP_SUMMARY
fi
if [[ "${{ needs.build-artifacts.result }}" == "success" ]]; then
echo "β
**Build Artifacts**: Success" >> $GITHUB_STEP_SUMMARY
else
echo "β **Build Artifacts**: Failed" >> $GITHUB_STEP_SUMMARY
fi
if [[ "${{ needs.create-release.result }}" == "success" ]]; then
echo "β
**GitHub Release**: Created" >> $GITHUB_STEP_SUMMARY
else
echo "β **GitHub Release**: Failed" >> $GITHUB_STEP_SUMMARY
fi
if [[ "${{ needs.publish-pypi.result }}" == "success" ]]; then
echo "β
**PyPI Publication**: Success" >> $GITHUB_STEP_SUMMARY
elif [[ "${{ needs.publish-test-pypi.result }}" == "success" ]]; then
echo "β
**Test PyPI Publication**: Success" >> $GITHUB_STEP_SUMMARY
else
echo "β **Package Publication**: Failed" >> $GITHUB_STEP_SUMMARY
fi
if [[ "${{ needs.verify-release.result }}" == "success" ]]; then
echo "β
**Release Verification**: Passed" >> $GITHUB_STEP_SUMMARY
else
echo "β **Release Verification**: Failed" >> $GITHUB_STEP_SUMMARY
fi
- name: Notify on failure
if: failure()
run: |
echo "β Release workflow failed. Please check the logs and fix any issues before retrying."
exit 1