-
Notifications
You must be signed in to change notification settings - Fork 1
397 lines (338 loc) · 12.6 KB
/
Copy pathrelease.yml
File metadata and controls
397 lines (338 loc) · 12.6 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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
name: Release (bump tag -> bump version -> Nuitka builds -> GitHub Release)
on:
push:
tags:
- "bump"
- "bump-*"
permissions:
contents: write
env:
PYTHON_VERSION: "3.12"
ENTRYPOINT: "src/spectUI/MainWindow.py"
RESOURCES_SRC_DIR: "src/spectUI/resources"
RESOURCES_DST_DIR: "resources"
WIN_ICON_ICO: "spectHR.ico"
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.final.outputs.version }}
release_tag: ${{ steps.final.outputs.release_tag }}
sha: ${{ steps.sha.outputs.sha }}
steps:
- name: Checkout full history
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Determine target version (tag 'bump' auto-patch OR 'bump-x.y.z' explicit)
id: final
shell: bash
run: |
python - <<'PY'
import os, re
from pathlib import Path
tag = os.environ["GITHUB_REF_NAME"]
pyproj = Path("pyproject.toml")
if not pyproj.exists():
raise SystemExit("pyproject.toml not found at repo root")
txt = pyproj.read_text(encoding="utf-8")
mproj = re.search(r"(?ms)^\[project\]\s*(.*?)(?=^\[|\Z)", txt)
if not mproj:
raise SystemExit("No [project] table found in pyproject.toml")
block = mproj.group(0)
mver = re.search(r'(?m)^version\s*=\s*"([^"]+)"\s*$', block)
if not mver:
raise SystemExit('No [project].version = "..." found in pyproject.toml')
current_raw = mver.group(1).strip()
def normalize_xy_to_xyz(v: str) -> str:
parts = v.split(".")
if len(parts) == 2 and all(p.isdigit() for p in parts):
return f"{parts[0]}.{parts[1]}.0"
return v
def is_stable_xyz(v: str) -> bool:
return re.match(r"^\d+\.\d+\.\d+$", v) is not None
def bump_patch(v: str) -> str:
mm = re.match(r"^(\d+)\.(\d+)\.(\d+)$", v)
if not mm:
raise ValueError(v)
a, b, c = map(int, mm.groups())
return f"{a}.{b}.{c+1}"
if tag == "bump":
base = normalize_xy_to_xyz(current_raw)
if not is_stable_xyz(base):
raise SystemExit(
f"Auto patch bump requires stable X.Y.Z (or X.Y). Current is '{current_raw}'. "
f"Use explicit bump-<version> for pre-releases."
)
version = bump_patch(base)
elif tag.startswith("bump-"):
version = normalize_xy_to_xyz(tag[len("bump-"):])
if not re.match(r"^[0-9]+\.[0-9]+\.[0-9]+([.-][0-9A-Za-z]+)*$", version):
raise SystemExit(f"Explicit bump tag not valid enough: '{tag}'")
else:
raise SystemExit(f"Unexpected tag: {tag}")
release_tag = f"v{version}"
out_path = Path(os.environ["GITHUB_OUTPUT"])
out_path.write_text(out_path.read_text() + f"version={version}\nrelease_tag={release_tag}\n", encoding="utf-8")
PY
- name: Bump pyproject.toml [project].version to target version
env:
VERSION: ${{ steps.final.outputs.version }}
shell: bash
run: |
python - <<'PY'
import os, re
from pathlib import Path
version = os.environ["VERSION"]
path = Path("pyproject.toml")
txt = path.read_text(encoding="utf-8")
mproj = re.search(r"(?ms)^\[project\]\s*(.*?)(?=^\[|\Z)", txt)
if not mproj:
raise SystemExit("No [project] table found in pyproject.toml")
block = mproj.group(0)
new_block, n = re.subn(
r'(?m)^version\s*=\s*".*?"\s*$',
f'version = "{version}"',
block,
count=1
)
if n != 1:
raise SystemExit("Could not replace [project].version exactly once")
path.write_text(txt[:mproj.start()] + new_block + txt[mproj.end():], encoding="utf-8")
PY
- name: Commit bump and push to default branch; create vX.Y.Z tag
shell: bash
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add pyproject.toml
git commit -m "chore(release): bump version to ${{ steps.final.outputs.version }}" || echo "No changes to commit"
DEFAULT_BRANCH="${{ github.event.repository.default_branch }}"
git push origin "HEAD:${DEFAULT_BRANCH}"
git tag -f "${{ steps.final.outputs.release_tag }}"
git push -f origin "${{ steps.final.outputs.release_tag }}"
- name: Export SHA used for builds
id: sha
shell: bash
run: |
echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
build:
needs: prepare
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout prepared commit
uses: actions/checkout@v4
with:
ref: ${{ needs.prepare.outputs.sha }}
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: "pip"
- name: Linux system deps (Qt runtime + Nuitka tooling)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y \
build-essential \
patchelf \
libgl1 \
libegl1 \
libglib2.0-0 \
libdbus-1-3 \
libxkbcommon0 \
libxkbcommon-x11-0 \
libx11-xcb1 \
libxcb-cursor0 \
libxcb-icccm4 \
libxcb-image0 \
libxcb-keysyms1 \
libxcb-randr0 \
libxcb-render-util0 \
libxcb-shape0 \
libxcb-xinerama0 \
libxcb-xfixes0 \
libxrender1 \
libxi6 \
libxext6 \
libfontconfig1 \
libfreetype6 \
libnss3 \
libasound2t64 \
fonts-dejavu-core \
libxcb-xinput0 \
libxcb-util1 \
libxcb-icccm4 \
libxcb-keysyms1 \
libxcb-render0 \
libxcb-render-util0 \
libxcb-shape0 \
libxcb-xfixes0 \
libxcb-xinerama0 \
libxcb-dri2-0 \
libxcb-dri3-0 \
libxcb-present0 \
libxcb-sync1 \
libxshmfence1 \
fonts-dejavu-core
- name: Install project + Nuitka tooling
shell: bash
run: |
python -m pip install --upgrade pip
python -m pip install .
python -m pip install nuitka zstandard
- name: Build + package (Windows/Linux onefile; macOS .app + iconset -> icns -> zip)
shell: bash
run: |
set -euo pipefail
VERSION="${{ needs.prepare.outputs.version }}"
OUTDIR="dist/${{ runner.os }}"
mkdir -p "$OUTDIR"
ENTRY="${{ env.ENTRYPOINT }}"
if [ ! -f "$ENTRY" ]; then
echo "Entry not found: $ENTRY"
exit 1
fi
COMMON_ARGS=(
"$ENTRY"
--standalone
--assume-yes-for-downloads
--enable-plugin=pyside6
--include-package=spectHR
--include-package=spectUI
--include-data-dir="${{ env.RESOURCES_SRC_DIR }}=${{ env.RESOURCES_DST_DIR }}"
--output-dir="$OUTDIR"
)
case "${{ runner.os }}" in
Windows)
if [ ! -f "${{ env.WIN_ICON_ICO }}" ]; then
echo "Missing icon file: ${{ env.WIN_ICON_ICO }} (repo root)"
exit 1
fi
python -m nuitka \
"${COMMON_ARGS[@]}" \
--onefile \
--windows-icon-from-ico="${{ env.WIN_ICON_ICO }}" \
--output-filename="spectHR.exe"
;;
macOS)
if [ ! -d "spectHR.iconset" ]; then
echo "Missing folder: spectHR.iconset (expected in repo root)"
exit 1
fi
/usr/bin/iconutil -c icns "spectHR.iconset" -o "spectHR.icns"
if [ ! -f "spectHR.icns" ]; then
echo "Failed to create spectHR.icns from spectHR.iconset"
exit 1
fi
python -m nuitka \
"${COMMON_ARGS[@]}" \
--macos-create-app-bundle \
--macos-app-name="spectHR" \
--macos-app-icon="spectHR.icns" \
--output-filename="spectHR"
;;
Linux)
python -m nuitka \
"${COMMON_ARGS[@]}" \
--onefile \
--output-filename="spectHR-Linux-v$VERSION"
;;
*)
echo "Unsupported OS: ${{ runner.os }}"
exit 1
;;
esac
env:
VERSION: ${{ needs.prepare.outputs.version }}
- name: Package Windows artifact
if: runner.os == 'Windows'
shell: pwsh
run: |
$version = "${{ needs.prepare.outputs.version }}"
$outdir = "dist/Windows"
if (!(Test-Path "$outdir/spectHR.exe")) { throw "Missing $outdir/spectHR.exe" }
if (!(Test-Path "ExampleData")) { throw "Missing ExampleData/ at repo root" }
$zip = "$outdir/spectHR-Windows-v$version.zip"
if (Test-Path $zip) { Remove-Item $zip -Force }
# ``-Path`` accepts multiple roots; each one lands at the top
# of the archive, so the .exe and the ExampleData/ folder sit
# side-by-side inside the zip.
Compress-Archive -Path "$outdir/spectHR.exe","ExampleData" -DestinationPath $zip
Remove-Item "$outdir/spectHR.exe" -Force
- name: Package macOS artifact
if: runner.os == 'macOS'
shell: bash
run: |
set -euo pipefail
VERSION="${{ needs.prepare.outputs.version }}"
OUTDIR="dist/macOS"
APP_PATH="$(find "$OUTDIR" -maxdepth 1 -type d -name "*.app" | head -n 1)"
if [ -z "${APP_PATH:-}" ]; then
echo "No .app produced in $OUTDIR"
ls -la "$OUTDIR"
exit 1
fi
if [ ! -d "ExampleData" ]; then
echo "Missing ExampleData/ at repo root"
exit 1
fi
APP_NAME="spectHR-macOS-v$VERSION.app"
mv "$APP_PATH" "$OUTDIR/$APP_NAME"
# Stage ExampleData/ next to the .app so both end up at the
# archive root after ``cd "$OUTDIR" && zip -r``.
cp -R ExampleData "$OUTDIR/ExampleData"
( cd "$OUTDIR" && /usr/bin/zip -r "spectHR-macOS-v$VERSION.zip" "$APP_NAME" "ExampleData" )
rm -rf "$OUTDIR/$APP_NAME" "$OUTDIR/ExampleData"
- name: Package Linux artifact
if: runner.os == 'Linux'
shell: bash
run: |
set -euo pipefail
VERSION="${{ needs.prepare.outputs.version }}"
OUTDIR="dist/Linux"
BIN="$OUTDIR/spectHR-Linux-v$VERSION"
if [ ! -f "$BIN" ]; then
echo "Missing $BIN"
ls -la "$OUTDIR"
exit 1
fi
if [ ! -d "ExampleData" ]; then
echo "Missing ExampleData/ at repo root"
exit 1
fi
# Stage ExampleData/ next to the binary so both sit at the
# archive root after ``cd "$OUTDIR" && tar``.
cp -R ExampleData "$OUTDIR/ExampleData"
( cd "$OUTDIR" && tar -czf "spectHR-Linux-v$VERSION.tar.gz" "spectHR-Linux-v$VERSION" "ExampleData" )
rm -f "$BIN"
rm -rf "$OUTDIR/ExampleData"
- name: Upload artifact (only packaged files)
uses: actions/upload-artifact@v4
with:
name: spectHR-${{ runner.os }}-v${{ needs.prepare.outputs.version }}
path: |
dist/${{ runner.os }}/*.zip
dist/${{ runner.os }}/*.tar.gz
release:
needs: [prepare, build]
runs-on: ubuntu-latest
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Create GitHub Release and upload assets
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.prepare.outputs.release_tag }}
name: ${{ needs.prepare.outputs.release_tag }}
generate_release_notes: true
files: |
artifacts/**/*.zip
artifacts/**/*.tar.gz