-
Notifications
You must be signed in to change notification settings - Fork 0
539 lines (524 loc) · 19.3 KB
/
Copy pathbuild.yml
File metadata and controls
539 lines (524 loc) · 19.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
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
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
name: Build & Release
on:
push:
branches: [main, develop]
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- 'LICENSE'
- '*.md'
workflow_dispatch: {}
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
# ─────────────────────────────────────────────────────────────────────────────
# TEST BUILD (develop only) — Verify code compiles and tests pass
# ─────────────────────────────────────────────────────────────────────────────
test-python:
if: github.ref == 'refs/heads/develop'
runs-on: ubuntu-latest
permissions:
contents: read
strategy:
matrix:
python-version: ['3.11', '3.12', '3.13']
steps:
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: python/requirements.txt
- name: Install and run tests
run: |
cd python
pip install -r requirements.txt -q
pip install pytest pytest-asyncio httpx -q
pytest tests/ -v
test-frontend:
if: github.ref == 'refs/heads/develop'
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: '22'
cache: npm
cache-dependency-path: frontend/package-lock.json
- name: Install and build
run: |
cd frontend
npm ci
npm run build
test-electron:
if: github.ref == 'refs/heads/develop'
needs: test-frontend
runs-on: ubuntu-latest
permissions:
contents: read
env:
ELECTRON_CACHE: ${{ github.workspace }}/.electron-cache
steps:
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
with:
python-version: '3.12'
cache: pip
cache-dependency-path: python/requirements.txt
- name: Install Python
run: |
cd python
pip install -r requirements.txt -q
pip install pyinstaller -q
- name: Build sidecar
run: |
cd python
python -m PyInstaller main.py --onefile --name metalens-sidecar --distpath dist --clean --noconfirm \
--hidden-import piexif \
--hidden-import mutagen \
--hidden-import hachoir \
--hidden-import olefile \
--hidden-import openpyxl \
--hidden-import docx \
--hidden-import pptx \
--hidden-import pypdf
- uses: actions/setup-node@v6
with:
node-version: '22'
cache: npm
cache-dependency-path: frontend/package-lock.json
- name: Build frontend
run: |
cd frontend
npm ci
npm run build
- name: Cache Electron download
uses: actions/cache@v4
with:
path: ${{ env.ELECTRON_CACHE }}
key: electron-${{ runner.os }}-${{ hashFiles('electron/package-lock.json') }}
- name: Test electron setup
run: |
cd electron
npm ci --include=dev
# ─────────────────────────────────────────────────────────────────────────────
# BETA RELEASE (develop only) — Package and publish a prerelease build
# ─────────────────────────────────────────────────────────────────────────────
get-version-beta:
if: github.ref == 'refs/heads/develop'
needs: [test-python, test-frontend, test-electron]
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
base_version: ${{ steps.ver.outputs.base_version }}
beta_version: ${{ steps.ver.outputs.beta_version }}
steps:
- uses: actions/checkout@v6
- id: ver
env:
GH_TOKEN: ${{ github.token }}
run: |
BASE=$(grep -oP 'VERSION\s*=\s*"\K[^"]+' python/config.py)
# Count existing beta releases for this exact base version and increment —
# keeps beta.N scoped to the version instead of the workflow's global run number.
LAST=$(gh release list --repo "${{ github.repository }}" --limit 200 \
| grep -oP "v${BASE}-beta\.\K[0-9]+" | sort -n | tail -1)
NEXT=$(( ${LAST:-0} + 1 ))
BETA="${BASE}-beta.${NEXT}"
echo "base_version=$BASE" >> "$GITHUB_OUTPUT"
echo "beta_version=$BETA" >> "$GITHUB_OUTPUT"
echo "Building MetaLens beta v$BETA"
build-windows-beta:
if: github.ref == 'refs/heads/develop'
needs: get-version-beta
runs-on: windows-latest
permissions:
contents: read
env:
ELECTRON_CACHE: ${{ github.workspace }}/.electron-cache
steps:
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
with:
python-version: '3.12'
cache: pip
cache-dependency-path: python/requirements.txt
- name: Build Python sidecar
shell: pwsh
run: |
cd python
pip install -r requirements.txt -q
pip install pyinstaller -q
python -m PyInstaller main.py --onefile --name metalens-sidecar --distpath dist --clean --noconfirm `
--hidden-import piexif `
--hidden-import mutagen `
--hidden-import hachoir `
--hidden-import olefile `
--hidden-import openpyxl `
--hidden-import docx `
--hidden-import pptx `
--hidden-import pypdf
- uses: actions/setup-node@v6
with:
node-version: '22'
cache: npm
cache-dependency-path: frontend/package-lock.json
- name: Build React frontend
run: |
cd frontend
npm ci
npm run build
- name: Copy frontend dist into electron
run: cp -r frontend/dist electron/frontend
- name: Sync electron version to beta
run: |
cd electron
npm version ${{ needs.get-version-beta.outputs.beta_version }} --no-git-tag-version --allow-same-version
- name: Cache Electron download
uses: actions/cache@v4
with:
path: ${{ env.ELECTRON_CACHE }}
key: electron-${{ runner.os }}-${{ hashFiles('electron/package-lock.json') }}
- name: Package with Electron Forge
run: |
cd electron
npm ci --include=dev
npx electron-forge make
- name: Upload Windows beta artifact
uses: actions/upload-artifact@v7
with:
name: windows-installer-beta
path: electron/out/make/**/*.exe
if-no-files-found: error
build-linux-beta:
if: github.ref == 'refs/heads/develop'
needs: get-version-beta
runs-on: ubuntu-latest
permissions:
contents: read
env:
ELECTRON_CACHE: ${{ github.workspace }}/.electron-cache
steps:
- uses: actions/checkout@v6
- name: Install system dependencies
run: sudo apt-get update -qq && sudo apt-get install -y rpm fakeroot
- uses: actions/setup-python@v6
with:
python-version: '3.12'
cache: pip
cache-dependency-path: python/requirements.txt
- name: Build Python sidecar
run: |
cd python
pip install -r requirements.txt -q
pip install pyinstaller -q
python -m PyInstaller main.py --onefile --name metalens-sidecar --distpath dist --clean --noconfirm \
--hidden-import piexif \
--hidden-import mutagen \
--hidden-import hachoir \
--hidden-import olefile \
--hidden-import openpyxl \
--hidden-import docx \
--hidden-import pptx \
--hidden-import pypdf
- uses: actions/setup-node@v6
with:
node-version: '22'
cache: npm
cache-dependency-path: frontend/package-lock.json
- name: Build React frontend
run: |
cd frontend
npm ci
npm run build
- name: Copy frontend dist into electron
run: cp -r frontend/dist electron/frontend
- name: Sync electron version to beta
run: |
cd electron
npm version ${{ needs.get-version-beta.outputs.beta_version }} --no-git-tag-version --allow-same-version
- name: Configure RPM macros
run: echo '%_build_id_links none' >> ~/.rpmmacros
- name: Cache Electron download
uses: actions/cache@v4
with:
path: ${{ env.ELECTRON_CACHE }}
key: electron-${{ runner.os }}-${{ hashFiles('electron/package-lock.json') }}
- name: Package with Electron Forge
run: |
cd electron
npm ci --include=dev
npx electron-forge make
- name: Create Linux tar.gz
run: |
VERSION=${{ needs.get-version-beta.outputs.beta_version }}
APP_DIR=$(find electron/out -maxdepth 1 -type d -name "MetaLens-linux-*" | head -1)
if [ -n "$APP_DIR" ]; then
tar -czf "electron/out/make/MetaLens-${VERSION}-Linux.tar.gz" \
-C "$(dirname "$APP_DIR")" "$(basename "$APP_DIR")"
echo "Created MetaLens-${VERSION}-Linux.tar.gz"
else
echo "Warning: no MetaLens-linux-* directory found, skipping tar.gz"
fi
- name: Upload Linux beta artifacts
uses: actions/upload-artifact@v7
with:
name: linux-packages-beta
path: |
electron/out/make/**/*.deb
electron/out/make/**/*.rpm
electron/out/make/**/*.tar.gz
if-no-files-found: error
release-beta:
if: github.ref == 'refs/heads/develop'
needs: [get-version-beta, build-windows-beta, build-linux-beta]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/download-artifact@v8
with:
path: artifacts
- name: List artifacts
run: find artifacts -type f
- name: Create beta GitHub Release
uses: softprops/action-gh-release@v3
with:
tag_name: v${{ needs.get-version-beta.outputs.beta_version }}
target_commitish: ${{ github.sha }}
name: MetaLens v${{ needs.get-version-beta.outputs.beta_version }} (beta)
draft: false
prerelease: true
generate_release_notes: true
make_latest: false
files: |
artifacts/windows-installer-beta/**
artifacts/linux-packages-beta/**
# ─────────────────────────────────────────────────────────────────────────────
# STABLE RELEASE (main only) — Rebuild from main with stable metadata
# ─────────────────────────────────────────────────────────────────────────────
get-version:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
version: ${{ steps.ver.outputs.version }}
steps:
- uses: actions/checkout@v6
- id: ver
run: |
VERSION=$(grep -oP 'VERSION\s*=\s*"\K[^"]+' python/config.py)
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "Building MetaLens v$VERSION"
find-latest-beta:
if: github.ref == 'refs/heads/main'
needs: get-version
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
beta_tag: ${{ steps.find.outputs.beta_tag }}
steps:
- id: find
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ needs.get-version.outputs.version }}
run: |
TAG=$(gh release list --repo "$GITHUB_REPOSITORY" --limit 200 --json tagName \
--jq '.[].tagName' \
| grep -E "^v${VERSION}-beta\.[0-9]+$" \
| sort -t. -k4 -n \
| tail -1)
if [ -z "$TAG" ]; then
echo "::error::Nessuna release beta trovata per v${VERSION}. Genera prima una beta da develop con la stessa VERSION in python/config.py."
exit 1
fi
echo "beta_tag=$TAG" >> "$GITHUB_OUTPUT"
echo "Validated matching beta $TAG for stable v${VERSION}"
build-windows-stable:
if: github.ref == 'refs/heads/main'
needs: [get-version, find-latest-beta]
runs-on: windows-latest
permissions:
contents: read
env:
ELECTRON_CACHE: ${{ github.workspace }}/.electron-cache
steps:
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
with:
python-version: '3.12'
cache: pip
cache-dependency-path: python/requirements.txt
- name: Build Python sidecar
shell: pwsh
run: |
cd python
pip install -r requirements.txt -q
pip install pyinstaller -q
python -m PyInstaller main.py --onefile --name metalens-sidecar --distpath dist --clean --noconfirm `
--hidden-import piexif `
--hidden-import mutagen `
--hidden-import hachoir `
--hidden-import olefile `
--hidden-import openpyxl `
--hidden-import docx `
--hidden-import pptx `
--hidden-import pypdf
- uses: actions/setup-node@v6
with:
node-version: '22'
cache: npm
cache-dependency-path: frontend/package-lock.json
- name: Build React frontend
run: |
cd frontend
npm ci
npm run build
- name: Copy frontend dist into electron
run: cp -r frontend/dist electron/frontend
- name: Cache Electron download
uses: actions/cache@v4
with:
path: ${{ env.ELECTRON_CACHE }}
key: electron-${{ runner.os }}-${{ hashFiles('electron/package-lock.json') }}
- name: Package with Electron Forge
run: |
cd electron
npm ci --include=dev
npx electron-forge make
- name: Verify Windows artifacts use stable version
shell: pwsh
run: |
$version = "${{ needs.get-version.outputs.version }}"
$bad = Get-ChildItem electron/out -Recurse -File | Where-Object { $_.Name -match 'beta' }
if ($bad) {
$bad | ForEach-Object { Write-Error "Unexpected beta artifact: $($_.FullName)" }
exit 1
}
$expected = "electron/out/make/squirrel.windows/x64/MetaLens-$version-win-x64.exe"
if (!(Test-Path $expected)) {
Write-Error "Missing expected stable installer: $expected"
exit 1
}
- name: Upload Windows stable artifact
uses: actions/upload-artifact@v7
with:
name: windows-installer-stable
path: electron/out/make/**/*.exe
if-no-files-found: error
build-linux-stable:
if: github.ref == 'refs/heads/main'
needs: [get-version, find-latest-beta]
runs-on: ubuntu-latest
permissions:
contents: read
env:
ELECTRON_CACHE: ${{ github.workspace }}/.electron-cache
steps:
- uses: actions/checkout@v6
- name: Install system dependencies
run: sudo apt-get update -qq && sudo apt-get install -y rpm fakeroot
- uses: actions/setup-python@v6
with:
python-version: '3.12'
cache: pip
cache-dependency-path: python/requirements.txt
- name: Build Python sidecar
run: |
cd python
pip install -r requirements.txt -q
pip install pyinstaller -q
python -m PyInstaller main.py --onefile --name metalens-sidecar --distpath dist --clean --noconfirm \
--hidden-import piexif \
--hidden-import mutagen \
--hidden-import hachoir \
--hidden-import olefile \
--hidden-import openpyxl \
--hidden-import docx \
--hidden-import pptx \
--hidden-import pypdf
- uses: actions/setup-node@v6
with:
node-version: '22'
cache: npm
cache-dependency-path: frontend/package-lock.json
- name: Build React frontend
run: |
cd frontend
npm ci
npm run build
- name: Copy frontend dist into electron
run: cp -r frontend/dist electron/frontend
- name: Configure RPM macros
run: echo '%_build_id_links none' >> ~/.rpmmacros
- name: Cache Electron download
uses: actions/cache@v4
with:
path: ${{ env.ELECTRON_CACHE }}
key: electron-${{ runner.os }}-${{ hashFiles('electron/package-lock.json') }}
- name: Package with Electron Forge
run: |
cd electron
npm ci --include=dev
npx electron-forge make
- name: Create Linux tar.gz
run: |
VERSION=${{ needs.get-version.outputs.version }}
APP_DIR=$(find electron/out -maxdepth 1 -type d -name "MetaLens-linux-*" | head -1)
if [ -n "$APP_DIR" ]; then
tar -czf "electron/out/make/MetaLens-${VERSION}-Linux.tar.gz" \
-C "$(dirname "$APP_DIR")" "$(basename "$APP_DIR")"
echo "Created MetaLens-${VERSION}-Linux.tar.gz"
else
echo "Warning: no MetaLens-linux-* directory found, skipping tar.gz"
fi
- name: Verify Linux artifacts use stable version
run: |
if find electron/out -type f -name '*beta*' | grep -q .; then
find electron/out -type f -name '*beta*'
echo "::error::Stable build produced beta-named artifacts."
exit 1
fi
- name: Upload Linux stable artifacts
uses: actions/upload-artifact@v7
with:
name: linux-packages-stable
path: |
electron/out/make/**/*.deb
electron/out/make/**/*.rpm
electron/out/make/**/*.tar.gz
if-no-files-found: error
release-stable:
if: github.ref == 'refs/heads/main'
needs: [get-version, find-latest-beta, build-windows-stable, build-linux-stable]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/download-artifact@v8
with:
path: artifacts
- name: List artifacts
run: find artifacts -type f
- name: Create stable GitHub Release
uses: softprops/action-gh-release@v3
with:
tag_name: v${{ needs.get-version.outputs.version }}
target_commitish: ${{ github.sha }}
name: MetaLens v${{ needs.get-version.outputs.version }}
draft: false
prerelease: false
generate_release_notes: true
make_latest: true
files: |
artifacts/windows-installer-stable/**
artifacts/linux-packages-stable/**