-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease_python_package_to_pypi.yml
More file actions
321 lines (257 loc) · 10.3 KB
/
release_python_package_to_pypi.yml
File metadata and controls
321 lines (257 loc) · 10.3 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
312
313
314
315
316
317
318
319
320
321
name: Release Python Package to PyPI
on:
workflow_dispatch:
release:
types: [published]
jobs:
build_deps_windows:
name: Build Windows Dependencies
runs-on: windows-latest
steps:
- uses: actions/checkout@v5
with:
lfs: true
- name: Setup Python
uses: actions/setup-python@v5
with:
cache: 'pip'
- name: Install Meson using Python
run: |
python -m pip install --upgrade pip meson
- name: Set branch name
run: echo "BRANCH_NAME=${{ runner.os }}_${{ runner.arch }}_build_cache" >> $GITHUB_ENV
shell: bash
- name: Configure and build C++ API via CMake
shell: pwsh
run: |
$ErrorActionPreference = "Stop"
git clone -b "$env:BRANCH_NAME" --single-branch https://github.com/PycraftDeveloper/PMMA.git build_cache
if ($LASTEXITCODE -ne 0) {
Write-Host "Cache branch missing, creating..."
} else {
Write-Host "Cache branch missing, creating..."
git checkout --orphan $env:BRANCH_NAME
git lfs install
git rm -rf .
git config --global user.email "github-actions@github.com"
git config --global user.name "GitHub Actions"
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/PycraftDeveloper/PMMA.git
git commit --allow-empty -m "Initial commit"
git push -u origin $env:BRANCH_NAME
cd ..
Remove-Item -Path "$env:GITHUB_WORKSPACE\PMMA" -Recurse -Force -ErrorAction SilentlyContinue
git clone https://github.com/${{ github.repository }} /PMMA
cd /PMMA
git lfs install
git clone -b $env:BRANCH_NAME --single-branch https://github.com/PycraftDeveloper/PMMA.git build_cache
}
python "build_tools/build_deps.py" -in_github_workflow
cd build_cache
git clean -fdx
cd ..
Get-ChildItem "build_tools" -Recurse -Force | Copy-Item -Destination "build_cache" -Recurse -Force
cd build_cache
git add .
git config --global user.email "github-actions@github.com"
git config --global user.name "GitHub Actions"
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/PycraftDeveloper/PMMA.git
git commit -m "Update Build Cache"
git push -u origin $env:BRANCH_NAME
build_deps_linux:
name: Build AnyLinux Dependencies
runs-on: ubuntu-latest
env:
DOCKER_IMAGE: docker.io/pycraftdev/pmma-manylinux:latest
steps:
- name: Pre-pull Docker image (cached by GitHub’s runner)
run: docker pull $DOCKER_IMAGE
- name: Set branch name
run: echo "BRANCH_NAME=${{ runner.os }}_${{ runner.arch }}_build_cache" >> $GITHUB_ENV
shell: bash
- name: Build Linux wheel inside Docker
run: |
docker run --rm \
-e TERM=xterm \
-e BRANCH_NAME=$BRANCH_NAME \
-v "${{ github.workspace }}/dist:/output_dist" \
$DOCKER_IMAGE \
/bin/bash -c '
set -e
git clone https://github.com/${{ github.repository }} /PMMA
cd /PMMA
if git clone -b "$BRANCH_NAME" --single-branch https://github.com/PycraftDeveloper/PMMA.git build_cache; then
echo "Cache branch exists, cloned successfully."
else
echo "Cache branch missing, creating..."
git checkout --orphan "$BRANCH_NAME"
git lfs install
git rm -rf .
git config --global user.email "github-actions@github.com"
git config --global user.name "GitHub Actions"
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/PycraftDeveloper/PMMA.git
git commit --allow-empty -m "Initial commit"
git push -u origin "$BRANCH_NAME"
cd ..
rm -rf /PMMA
git clone https://github.com/${{ github.repository }} /PMMA
cd /PMMA
git lfs install
git clone -b "$BRANCH_NAME" --single-branch https://github.com/PycraftDeveloper/PMMA.git build_cache
fi
python3 "build_tools/build_deps.py" -in_github_workflow
cd build_cache
git clean -fdx
cd ..
cp -r build_tools/* build_cache/
cp -r build_tools/.* build_cache/ 2>/dev/null || true
cd build_cache
git add .
git config --global user.email "github-actions@github.com"
git config --global user.name "GitHub Actions"
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/PycraftDeveloper/PMMA.git
git commit -m "Update Build Cache"
git push -u origin "$BRANCH_NAME"
'
build_linux: # How do I set the environment variable here?
name: Build Linux wheels
runs-on: ubuntu-latest
strategy:
matrix:
python-tag: ["cp38-cp38", "cp39-cp39", "cp310-cp310", "cp311-cp311"]
env:
DOCKER_IMAGE: docker.io/pycraftdev/pmma-manylinux:latest
needs: [build_deps_linux]
steps:
- name: Ensure dist directory exists
run: mkdir -p dist
- name: Pre-pull Docker image (cached by GitHub’s runner)
run: docker pull $DOCKER_IMAGE
- name: Set branch name
run: echo "BRANCH_NAME=${{ runner.os }}_${{ runner.arch }}_build_cache" >> $GITHUB_ENV
shell: bash
- name: Build Linux wheel inside Docker
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
docker run --rm \
-e TERM=xterm \
-e BRANCH_NAME=$BRANCH_NAME \
-e PYTHON_TAG=${{ matrix.python-tag }} \
-v "${{ github.workspace }}/dist:/output_dist" \
$DOCKER_IMAGE \
/bin/bash -c '
set -e
tag=$PYTHON_TAG
dir="/tmp/build_$tag"
git clone https://github.com/${{ github.repository }} "$dir"
cd "$dir"
git clone -b "$BRANCH_NAME" --single-branch https://github.com/PycraftDeveloper/PMMA.git build_cache
PYTHON_BIN="/opt/python/$tag/bin/python"
python3 "build_tools/workflow_integration.py" -in_github_workflow
$PYTHON_BIN "build_pmma.py" -in_github_workflow
original=$(ls dist/*.whl)
renamed=$(echo "$original" | sed "s/linux/manylinux_2_28/")
mv "$original" "$renamed"
cp dist/* /output_dist/
'
- name: Upload wheel
uses: actions/upload-artifact@v4
with:
name: wheel-linux-${{ matrix.python-tag }}
path: dist/*.whl
build_windows:
strategy:
matrix:
include:
- os: windows
runs-on: windows-latest
python-version: '3.8'
- os: windows
runs-on: windows-latest
python-version: '3.9'
- os: windows
runs-on: windows-latest
python-version: '3.10'
- os: windows
runs-on: windows-latest
python-version: '3.11'
runs-on: ${{ matrix.runs-on }}
needs: [build_deps_windows]
steps:
- uses: actions/checkout@v5
with:
lfs: true
# Python with built-in pip cache
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
# Install Python build deps (reuses pip cache above)
- name: Install Python build tools
run: |
python -m pip install --upgrade pip setuptools wheel cython numpy meson
- name: Set branch name
run: echo "BRANCH_NAME=${{ runner.os }}_${{ runner.arch }}_build_cache" >> $GITHUB_ENV
shell: bash
- name: Configure and build C++ API via CMake
run: |
git clone -b "$BRANCH_NAME" --single-branch https://github.com/PycraftDeveloper/PMMA.git build_cache
python "build_tools/workflow_integration.py" -in_github_workflow
python "build_tools/build_pmma.py" -in_github_workflow
- name: Upload wheel
uses: actions/upload-artifact@v4
with:
name: wheel-${{ matrix.os }}-${{ matrix.python-version }}
path: dist/*.whl
# ──────────────────────────────────────
# 3. sdist and publish
# ──────────────────────────────────────
sdist:
name: Build Source Distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- run: |
pip install setuptools wheel cython numpy
python setup.py sdist
- uses: actions/upload-artifact@v4
with:
name: sdist
path: dist/*.tar.gz
publish:
name: Publish to PyPI + GitHub Release
runs-on: ubuntu-latest
needs: [build_windows, sdist, build_linux]
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: ./artifacts
- name: Move distribution files
run: |
mkdir -p dist
find artifacts -type f \( -name "*.whl" -o -name "*.tar.gz" \) -exec mv {} dist/ \;
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@v1.12.4
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
packages_dir: dist
- name: Upload to GitHub Release
if: github.event_name == 'release'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
UPLOAD_URL: ${{ github.event.release.upload_url }}
run: |
for f in dist/*; do
echo "Uploading $f ..."
curl -X POST \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Content-Type: application/octet-stream" \
--data-binary @"$f" \
"${UPLOAD_URL%\{*}?name=$(basename "$f")"
done