-
Notifications
You must be signed in to change notification settings - Fork 0
165 lines (142 loc) · 4.73 KB
/
release.yml
File metadata and controls
165 lines (142 loc) · 4.73 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
name: Release
on:
push:
tags:
- 'v*'
permissions:
contents: read
env:
DO_NOT_TRACK: '1'
jobs:
# Preflight: validate CHANGELOG has a section for the tag being released
# BEFORE any publish step runs. A missing section fails the entire
# workflow cleanly rather than publishing to PyPI first and then failing
# at the GitHub release step.
preflight:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Extract CHANGELOG section
run: |
VERSION="${GITHUB_REF#refs/tags/v}"
awk -v ver="$VERSION" '$0 ~ "^## \\["ver"\\]" {p=1; next} p && /^## \[/ {exit} p {print}' CHANGELOG.md > /tmp/release-body.md
if [ ! -s /tmp/release-body.md ]; then
echo "::error::No CHANGELOG.md section found for version $VERSION — refusing to publish."
echo "::error::Add a '## [$VERSION] - YYYY-MM-DD' section to CHANGELOG.md and re-tag."
exit 1
fi
{
echo "## AxonFlow Python SDK v${VERSION}"
echo ""
echo "### Installation"
echo ""
echo '```bash'
echo "pip install axonflow==${VERSION}"
echo '```'
echo ""
cat /tmp/release-body.md
} > /tmp/release-body-final.md
echo "Release body: $(wc -l < /tmp/release-body-final.md) lines"
- name: Upload release body artifact
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
with:
name: release-body
path: /tmp/release-body-final.md
retention-days: 1
build:
needs: preflight
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Extract version from tag
id: version
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
- name: Update version in source
run: |
VERSION=${{ steps.version.outputs.VERSION }}
sed -i "s/^version = .*/version = \"${VERSION}\"/" pyproject.toml
sed -i "s/^__version__ = .*/__version__ = \"${VERSION}\"/" axonflow/__init__.py
echo "Updated version to ${VERSION}"
grep version pyproject.toml | head -1
grep __version__ axonflow/__init__.py
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
cache-dependency-path: 'pyproject.toml'
- name: Install dependencies
run: pip install -e ".[dev,all]"
- name: Run tests
run: pytest
- name: Install build tools
run: pip install build
- name: Build package
run: python -m build
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
publish-pypi:
needs: build
runs-on: ubuntu-latest
environment: pypi
permissions:
id-token: write
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: dist/
create-release:
needs: [preflight, publish-pypi]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Download dist artifacts
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Download release body artifact
uses: actions/download-artifact@v4
with:
name: release-body
path: /tmp/release-body
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
files: dist/*
name: Release ${{ github.ref_name }}
body_path: /tmp/release-body/release-body-final.md
generate_release_notes: false
verify-publish:
needs: [preflight, publish-pypi]
runs-on: ubuntu-latest
steps:
- name: Extract version from tag
id: version
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
- name: Wait for PyPI propagation
run: sleep 30
- name: Verify package on PyPI
run: |
VERSION=${{ steps.version.outputs.VERSION }}
for i in 1 2 3 4 5; do
echo "Attempt $i: Checking PyPI for axonflow==${VERSION}..."
if pip install --dry-run axonflow==${VERSION} 2>&1 | grep -q "Would install"; then
echo "SUCCESS: axonflow ${VERSION} is available on PyPI"
exit 0
fi
echo "Not yet available, waiting 30 seconds..."
sleep 30
done
echo "FAILURE: axonflow ${VERSION} not found on PyPI after 5 attempts"
exit 1