-
Notifications
You must be signed in to change notification settings - Fork 0
209 lines (186 loc) · 7.28 KB
/
python-release.yml
File metadata and controls
209 lines (186 loc) · 7.28 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
name: Python SDK Release
on:
push:
branches: [main]
workflow_dispatch:
permissions: {}
concurrency:
group: python-release-${{ github.ref }}
cancel-in-progress: false
jobs:
test:
if: "${{ !startsWith(github.event.head_commit.message, 'chore: release') }}"
runs-on: ubuntu-latest
permissions:
contents: read
env:
MUXI_SDK_E2E_SERVER_URL: ${{ secrets.MUXI_SDK_E2E_SERVER_URL }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v4
with:
fetch-depth: 0
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v5
with:
python-version: '3.10'
- name: Install
run: |
python -m pip install --upgrade pip
python -m pip install .
- name: Unit tests
run: python -m unittest discover tests -v
- name: Require test server
run: |
if [ -z "$MUXI_SDK_E2E_SERVER_URL" ]; then
echo "::error::MUXI_SDK_E2E_SERVER_URL secret is not set"
exit 1
fi
if ! curl -sf --max-time 10 "${MUXI_SDK_E2E_SERVER_URL}/ping" >/dev/null 2>&1 && \
! curl -sf --max-time 10 "${MUXI_SDK_E2E_SERVER_URL}" >/dev/null 2>&1; then
echo "::error::Test server is not reachable at ${MUXI_SDK_E2E_SERVER_URL}"
exit 1
fi
- name: Integration tests
env:
MUXI_SDK_E2E_KEY_ID: ${{ secrets.MUXI_SDK_E2E_KEY_ID }}
MUXI_SDK_E2E_SECRET_KEY: ${{ secrets.MUXI_SDK_E2E_SECRET_KEY }}
MUXI_SDK_E2E_FORMATION_ID: ${{ secrets.MUXI_SDK_E2E_FORMATION_ID }}
MUXI_SDK_E2E_CLIENT_KEY: ${{ secrets.MUXI_SDK_E2E_CLIENT_KEY }}
MUXI_SDK_E2E_ADMIN_KEY: ${{ secrets.MUXI_SDK_E2E_ADMIN_KEY }}
run: python -m unittest discover tests -v
release:
if: "${{ !startsWith(github.event.head_commit.message, 'chore: release') }}"
needs: test
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v4
with:
fetch-depth: 0
token: ${{ secrets.MUXI_RELEASE_TOKEN }}
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v5
with:
python-version: '3.10'
- name: Compute next version
id: version
run: |
current=$(python -c "from pathlib import Path, re; import sys; text=Path('muxi/version.py').read_text(); m=re.search(r'__version__\\s*=\\s*[\"\']([^\"\']+)[\"\']', text); sys.exit('version not found') if not m else print(m.group(1))")
major=$(echo "$current" | cut -d. -f1)
cdate=$(echo "$current" | cut -d. -f2)
cpatch=$(echo "$current" | cut -d. -f3)
today=$(date -u +%Y%m%d)
if [ "$cdate" = "$today" ]; then
nextpatch=$((cpatch + 1))
else
nextpatch=0
fi
next="${major}.${today}.${nextpatch}"
echo "version=$next" >> $GITHUB_OUTPUT
- name: Set version in source
run: |
NEXT_VERSION="${{ steps.version.outputs.version }}"
python -c "
from pathlib import Path; import re, os
v = os.environ['NEXT_VERSION']
p = Path('muxi/version.py')
p.write_text(re.sub(r'__version__\s*=\s*[\"\\x27][^\"\\x27]+[\"\\x27]', f'__version__ = \"{v}\"', p.read_text()))
"
env:
NEXT_VERSION: ${{ steps.version.outputs.version }}
- name: Build distributions
run: |
python -m pip install --upgrade pip build
python -m build
- name: Check if version exists on PyPI
id: check_pypi
run: |
VERSION="${{ steps.version.outputs.version }}"
if curl -sf "https://pypi.org/pypi/muxi/${VERSION}/json" > /dev/null 2>&1; then
echo "Version ${VERSION} already exists on PyPI, skipping publish"
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "Version ${VERSION} not found on PyPI, will publish"
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Publish to PyPI
if: steps.check_pypi.outputs.exists == 'false'
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # release/v1
- name: Commit version bump
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add muxi/version.py
git commit -m "chore: release v${{ steps.version.outputs.version }}"
git push origin HEAD:main
- name: Create and push tag
run: |
TAG="v${{ steps.version.outputs.version }}"
if git rev-parse "$TAG" >/dev/null 2>&1; then
echo "Tag $TAG already exists"
else
git tag "$TAG"
git push origin "$TAG"
fi
- name: Create GitHub Release
uses: softprops/action-gh-release@a06a81a03ee405af7f2048a818ed3f03bbf83c7b # v2.5.0
with:
tag_name: v${{ steps.version.outputs.version }}
name: v${{ steps.version.outputs.version }}
body: |
Python SDK v${{ steps.version.outputs.version }}
sync_develop:
if: "${{ !startsWith(github.event.head_commit.message, 'chore: release') }}"
needs: release
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v4
with:
ref: develop
fetch-depth: 0
token: ${{ secrets.MUXI_RELEASE_TOKEN }}
- name: Merge main into develop
run: |
git fetch origin main develop
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git merge origin/main --no-edit -m "chore: sync main to develop [skip ci]"
git push origin HEAD:develop
update_sdks_pointer:
if: "${{ !startsWith(github.event.head_commit.message, 'chore: release') }}"
needs: release
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout parent sdks repo
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v4
with:
repository: muxi-ai/sdks
ref: main
fetch-depth: 0
token: ${{ secrets.MUXI_RELEASE_TOKEN }}
path: sdks
- name: Update python submodule to latest main
run: |
cd sdks
git config --global url."https://x-access-token:${{ secrets.MUXI_RELEASE_TOKEN }}@github.com/".insteadOf "https://github.com/"
git config submodule.python.url https://github.com/muxi-ai/muxi-python.git
git submodule update --init --depth 1 python
cd python
git fetch origin main --depth 1
git reset --hard FETCH_HEAD
cd ..
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add python
if git diff --cached --quiet; then
echo "No submodule pointer change"
else
git commit -m "Update python submodule pointer"
git push origin main
fi