-
Notifications
You must be signed in to change notification settings - Fork 5
144 lines (130 loc) · 4.02 KB
/
release.yml
File metadata and controls
144 lines (130 loc) · 4.02 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: Create Release
on:
workflow_dispatch:
inputs:
version:
description: 'Version number (e.g., 0.2.0)'
required: true
type: string
permissions:
contents: write
jobs:
validate-changelog:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Validate changelog contains version
run: |
set -e
VERSION="${{ inputs.version }}"
PATTERN="^## \[(v)?${VERSION}\]"
echo "Checking CHANGELOG.md for header: $PATTERN"
MATCH_COUNT=$(grep -c -E "$PATTERN" CHANGELOG.md || true)
if [ "$MATCH_COUNT" -eq 0 ]; then
echo "ERROR: No changelog section found for v$VERSION" >&2
exit 1
fi
if [ "$MATCH_COUNT" -gt 1 ]; then
echo "ERROR: Multiple changelog sections found for v$VERSION" >&2
exit 1
fi
echo "Changelog validation passed."
extract-changelog:
runs-on: ubuntu-latest
needs: validate-changelog
outputs:
notes_artifact: release_notes
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Extract changelog section
run: |
set -e
VERSION="${{ inputs.version }}"
awk -v ver="$VERSION" '
$0 ~ ("^## \\[v?" ver "\\]") {flag=1}
/^## \[/{
if (flag && $0 !~ ("^## \\[v?" ver "\\]")) exit
}
flag
' CHANGELOG.md > raw_release_notes.md || {
echo "Failed to extract changelog section" >&2; exit 1; }
# Trim trailing blank lines
awk 'NF{p=1} p' raw_release_notes.md > release_notes.md
echo "Extracted release notes:"; cat release_notes.md
- name: Upload release notes artifact
uses: actions/upload-artifact@v4
with:
name: release_notes
path: release_notes.md
release:
runs-on: ubuntu-latest
needs: extract-changelog
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0 # Fetch all history for changelog generation
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.12"
- name: Install uv
uses: astral-sh/setup-uv@v7
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Bump version with uv
run: |
uv version ${{ inputs.version }}
- name: Commit version bump
run: |
git add pyproject.toml
git commit --allow-empty -m "Bump version to ${{ inputs.version }}"
git push
- name: Download extracted release notes
uses: actions/download-artifact@v4
with:
name: release_notes
path: release_notes
- name: Create and push tag
run: |
git tag "v${{ inputs.version }}"
git push origin "v${{ inputs.version }}"
- name: Create GitHub Release
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release create "v${{ inputs.version }}" \
--title "Release ${{ inputs.version }}" \
--notes-file release_notes/release_notes.md
add-wheel:
runs-on: ubuntu-latest
needs: release
environment: release
steps:
- uses: actions/checkout@v5
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.12"
- name: Install uv
uses: astral-sh/setup-uv@v7
- name: Bump version with uv
run: |
uv version ${{ inputs.version }}
- name: Build
run: |
uv build
- name: Upload wheel to release
env:
GH_TOKEN: ${{ github.token }}
run: |
RELEASE_TAG="v${{ inputs.version }}"
for wheel in dist/*.whl; do
gh release upload "$RELEASE_TAG" "$wheel" --clobber
done