-
Notifications
You must be signed in to change notification settings - Fork 1
311 lines (253 loc) · 9.42 KB
/
Copy pathrelease.yml
File metadata and controls
311 lines (253 loc) · 9.42 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
name: Release to PyPI
on:
push:
tags:
- 'v*'
permissions:
contents: write
id-token: write
jobs:
validate:
name: Validate Release
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get_version.outputs.version }}
changelog: ${{ steps.extract_changelog.outputs.changelog }}
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.11"
- name: Get version from tag
id: get_version
run: |
TAG_VERSION=${GITHUB_REF#refs/tags/v}
echo "version=$TAG_VERSION" >> $GITHUB_OUTPUT
echo "Tag version: $TAG_VERSION"
- name: Validate version consistency
run: |
TAG_VERSION=${{ steps.get_version.outputs.version }}
# Check pyproject.toml [project] version
# NOTE: `grep '^version = '` would match both [project].version and
# [tool.commitizen].version. Restrict to the first match.
PYPROJECT_VERSION=$(grep -m1 '^version = ' pyproject.toml | cut -d '"' -f 2)
echo "pyproject.toml version: $PYPROJECT_VERSION"
# Check __version__.py version
VERSION_PY=$(grep '^__version__ = ' src/flac_detective/__version__.py | cut -d '"' -f 2)
echo "__version__.py version: $VERSION_PY"
# Validate all versions match
if [ "$TAG_VERSION" != "$PYPROJECT_VERSION" ]; then
echo "❌ Error: Tag version ($TAG_VERSION) doesn't match pyproject.toml ($PYPROJECT_VERSION)"
exit 1
fi
if [ "$TAG_VERSION" != "$VERSION_PY" ]; then
echo "❌ Error: Tag version ($TAG_VERSION) doesn't match __version__.py ($VERSION_PY)"
exit 1
fi
echo "✅ All versions match: $TAG_VERSION"
- name: Install Commitizen
run: |
python -m pip install commitizen
- name: Extract changelog for this version
id: extract_changelog
run: |
VERSION=${{ steps.get_version.outputs.version }}
# Extract changelog section for this version using Commitizen format
python3 << 'EOF' > release_notes.md
import re
import sys
version = "${{ steps.get_version.outputs.version }}"
with open("CHANGELOG.md", "r", encoding="utf-8") as f:
content = f.read()
# Find the section for this version (Commitizen format: ## vX.Y.Z (date))
pattern = rf"## v{re.escape(version)}.*?\n(.*?)(?=\n## v|$)"
match = re.search(pattern, content, re.DOTALL)
if match:
changelog_text = match.group(1).strip()
print(changelog_text)
else:
print(f"⚠️ No changelog found for version {version}")
sys.exit(1)
EOF
# Store changelog in output (escaped for multiline)
{
echo 'changelog<<EOF'
cat release_notes.md
echo EOF
} >> $GITHUB_OUTPUT
echo "📝 Changelog extracted successfully"
- name: Validate CHANGELOG.md entry exists
run: |
VERSION=${{ steps.get_version.outputs.version }}
# Check for Commitizen format: ## vX.Y.Z (date)
if ! grep -q "## v$VERSION" CHANGELOG.md; then
echo "❌ Error: No CHANGELOG.md entry found for version $VERSION"
echo "Run 'cz changelog' to generate/update the changelog."
exit 1
fi
echo "✅ CHANGELOG.md entry exists for version $VERSION"
build:
name: Build Distribution
needs: validate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.11"
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Build package
run: |
python -m build
echo "📦 Package built successfully"
- name: Check distribution
run: |
twine check dist/*
echo "✅ Distribution check passed"
- name: List built files
run: |
echo "📋 Built files:"
ls -lh dist/
- name: Upload build artifacts
uses: actions/upload-artifact@v6
with:
name: dist-packages
path: dist/
retention-days: 7
test-package:
name: Test Package Installation
needs: build
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ["3.10", "3.12"]
steps:
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: Download build artifacts
uses: actions/download-artifact@v7
with:
name: dist-packages
path: dist/
- name: Install package from wheel
# `shell: bash` so the `dist/*.whl` glob expands on Windows runners
# too — PowerShell's default does not glob unquoted arguments to
# native executables, so `pip` would receive a literal "*".
shell: bash
run: |
pip install dist/*.whl
- name: Test CLI entry point
run: |
flac-detective --version
- name: Test Python import
# Plain ASCII print — Windows runners default to cp1252 for the
# process and an emoji here makes the test fail with UnicodeEncodeError.
run: |
python -c "import flac_detective; print('Import OK, version', flac_detective.__version__)"
publish-pypi:
name: Publish to PyPI
needs: [validate, build, test-package]
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/project/flac-detective/
steps:
- name: Download build artifacts
uses: actions/download-artifact@v7
with:
name: dist-packages
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
print-hash: true
verbose: true
- name: Confirm publication
run: |
echo "🎉 Package published to PyPI successfully!"
echo "📦 View at: https://pypi.org/project/flac-detective/${{ needs.validate.outputs.version }}/"
create-github-release:
name: Create GitHub Release
needs: [validate, publish-pypi]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Download build artifacts
uses: actions/download-artifact@v7
with:
name: dist-packages
path: dist/
- name: Create release notes file
run: |
cat > release_notes.md << 'EOF'
${{ needs.validate.outputs.changelog }}
EOF
# Add installation instructions
cat >> release_notes.md << 'EOF'
---
## Installation
Install via pip:
```bash
pip install flac-detective==${{ needs.validate.outputs.version }}
```
Or upgrade to this version:
```bash
pip install --upgrade flac-detective
```
## Links
- 📦 [PyPI Package](https://pypi.org/project/flac-detective/${{ needs.validate.outputs.version }}/)
- 📖 [Documentation](https://github.com/Guillain-RDCDE/FLAC_Detective#readme)
- 🐛 [Report Issues](https://github.com/Guillain-RDCDE/FLAC_Detective/issues)
## Checksums
SHA256 checksums for distribution files:
EOF
# Add checksums
cd dist
sha256sum * >> ../release_notes.md
cd ..
- name: Create GitHub Release
uses: softprops/action-gh-release@v3
with:
name: "Release v${{ needs.validate.outputs.version }}"
body_path: release_notes.md
files: dist/*
draft: false
prerelease: false
generate_release_notes: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Confirm release creation
run: |
echo "🎉 GitHub Release created successfully!"
echo "🔗 View at: https://github.com/${{ github.repository }}/releases/tag/${{ github.ref_name }}"
notify:
name: Post-Release Notifications
needs: [validate, create-github-release]
runs-on: ubuntu-latest
if: always()
steps:
- name: Release Summary
run: |
echo "## 🚀 Release Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Version:** ${{ needs.validate.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "**Tag:** ${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Status" >> $GITHUB_STEP_SUMMARY
echo "- ✅ Package built and validated" >> $GITHUB_STEP_SUMMARY
echo "- ✅ Published to PyPI" >> $GITHUB_STEP_SUMMARY
echo "- ✅ GitHub Release created" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Links" >> $GITHUB_STEP_SUMMARY
echo "- [PyPI Package](https://pypi.org/project/flac-detective/${{ needs.validate.outputs.version }}/)" >> $GITHUB_STEP_SUMMARY
echo "- [GitHub Release](https://github.com/${{ github.repository }}/releases/tag/${{ github.ref_name }})" >> $GITHUB_STEP_SUMMARY