-
Notifications
You must be signed in to change notification settings - Fork 10
233 lines (199 loc) · 6.98 KB
/
publish-release.yml
File metadata and controls
233 lines (199 loc) · 6.98 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
name: Publish Release to PyPI
on:
workflow_dispatch:
inputs:
version:
description: 'Version number (e.g., 3.0.0)'
required: true
type: string
branch:
description: 'Branch or tag to publish from'
required: true
default: 'master'
type: string
prerelease:
description: 'Mark as pre-release'
required: false
default: false
type: boolean
permissions:
id-token: write
contents: read
jobs:
validate-version:
name: Validate Version
runs-on: ubuntu-latest
outputs:
version: ${{ steps.check-version.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ inputs.branch }}
- name: Check version format
id: check-version
run: |
VERSION="${{ inputs.version }}"
if [[ ! $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?$ ]]; then
echo "Error: Invalid version format. Expected: X.Y.Z or X.Y.Z-suffix"
exit 1
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "✓ Version format valid: $VERSION"
- name: Check if tag already exists
run: |
git fetch --tags
if git rev-parse "v${{ inputs.version }}" >/dev/null 2>&1; then
echo "Error: Tag v${{ inputs.version }} already exists!"
exit 1
fi
echo "✓ Tag v${{ inputs.version }} does not exist yet"
build-and-test:
name: Build and Test Package
runs-on: ubuntu-latest
needs: validate-version
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ inputs.branch }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Update version in __init__.py
run: |
sed -i 's/__version__ = ".*"/__version__ = "${{ inputs.version }}"/' sinricpro/__init__.py
echo "Updated version to ${{ inputs.version }}"
grep "__version__" sinricpro/__init__.py
- name: Build package
run: |
python -m build
echo "✓ Package built successfully"
- name: Check package with twine
run: |
twine check dist/*
echo "✓ Package passes twine checks"
- name: List package contents
run: |
echo "Package files:"
ls -lh dist/
- name: Install package locally
run: |
pip install dist/*.whl
echo "✓ Package installed successfully"
- name: Test package import
run: |
python -c "import sinricpro; print(f'✓ SinricPro version: {sinricpro.__version__}')"
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: dist-packages
path: dist/
retention-days: 5
publish-to-pypi:
name: Publish to PyPI
runs-on: ubuntu-latest
needs: build-and-test
environment:
name: pypi
url: https://pypi.org/project/sinricpro/
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ inputs.branch }}
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: dist-packages
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
verbose: true
- name: Wait for PyPI propagation
run: |
echo "Waiting 30 seconds for PyPI to propagate..."
sleep 30
- name: Verify package on PyPI
run: |
pip install sinricpro==${{ inputs.version }}
python -c "import sinricpro; print(f'✓ Verified PyPI package version: {sinricpro.__version__}')"
create-github-release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: publish-to-pypi
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ inputs.branch }}
fetch-depth: 0
- name: Update version in source
run: |
sed -i 's/__version__ = ".*"/__version__ = "${{ inputs.version }}"/' sinricpro/__init__.py
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add sinricpro/__init__.py
git commit -m "chore: bump version to ${{ inputs.version }}" || echo "No changes to commit"
- name: Create and push tag
run: |
git tag -a "v${{ inputs.version }}" -m "Release v${{ inputs.version }}"
git push origin "v${{ inputs.version }}"
echo "✓ Tag v${{ inputs.version }} created and pushed"
- name: Generate changelog
id: changelog
run: |
# Get the previous tag
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
if [ -z "$PREV_TAG" ]; then
echo "## Changes" > CHANGELOG.md
echo "Initial release" >> CHANGELOG.md
else
echo "## Changes from $PREV_TAG to v${{ inputs.version }}" > CHANGELOG.md
echo "" >> CHANGELOG.md
git log $PREV_TAG..HEAD --pretty=format:"- %s (%h)" >> CHANGELOG.md
fi
cat CHANGELOG.md
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: dist-packages
path: dist/
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ inputs.version }}
name: Release v${{ inputs.version }}
body_path: CHANGELOG.md
draft: false
prerelease: ${{ inputs.prerelease }}
files: |
dist/*.whl
dist/*.tar.gz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Release Summary
run: |
echo "## 🎉 Release Published Successfully!" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Version:** v${{ inputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "**Branch:** ${{ inputs.branch }}" >> $GITHUB_STEP_SUMMARY
echo "**PyPI:** https://pypi.org/project/sinricpro/${{ inputs.version }}/" >> $GITHUB_STEP_SUMMARY
echo "**GitHub Release:** https://github.com/${{ github.repository }}/releases/tag/v${{ inputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Installation" >> $GITHUB_STEP_SUMMARY
echo '```bash' >> $GITHUB_STEP_SUMMARY
echo "pip install sinricpro==${{ inputs.version }}" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY