-
Notifications
You must be signed in to change notification settings - Fork 25
320 lines (288 loc) · 9.9 KB
/
Copy pathbuild.yml
File metadata and controls
320 lines (288 loc) · 9.9 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
name: Build
on:
push:
tags:
- "v*"
release:
types: [published]
workflow_dispatch:
inputs:
version:
description: "Version to build (e.g., 1.0.0)"
required: true
type: string
permissions:
contents: write
actions: write
pull-requests: write
jobs:
# Pre-build SvelteKit app once and share across all platforms
prebuild:
name: Build SvelteKit App
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: "24"
cache: "npm"
- name: Install dependencies
run: |
npm ci --prefer-offline || \
npm ci --prefer-offline || \
npm ci
env:
ONNXRUNTIME_NODE_INSTALL_CUDA: skip
- name: Build SvelteKit
run: npm run build
- name: Upload build artifact
uses: actions/upload-artifact@v7
with:
name: sveltekit-build
path: build/
retention-days: 1
build:
name: Build (${{ matrix.platform }})
runs-on: ${{ matrix.os }}
needs: prebuild
strategy:
fail-fast: false
matrix:
include:
- os: macos-14
platform: mac-arm64
arch: arm64
- os: macos-14
platform: mac-x64
arch: x64
- os: windows-latest
platform: win-x64
arch: x64
- os: windows-latest
platform: win-arm64
arch: arm64
- os: ubuntu-latest
platform: linux-x64
arch: x64
linux_targets: deb rpm AppImage
- os: ubuntu-latest
platform: linux-arm64
arch: arm64
linux_targets: AppImage
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Get version from tag, release or input
id: version
run: |
if [ "${{ github.event_name }}" = "release" ]; then
VERSION="${{ github.event.release.tag_name }}"
VERSION="${VERSION#v}"
elif [ "${{ github.event_name }}" = "push" ]; then
VERSION="${GITHUB_REF#refs/tags/v}"
else
VERSION="${{ inputs.version }}"
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
shell: bash
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: "24"
cache: "npm"
- name: Cache Electron binaries
uses: actions/cache@v5
with:
path: |
~/Library/Caches/electron
~/Library/Caches/electron-builder
~/.cache/electron
~/.cache/electron-builder
~/AppData/Local/electron/Cache
~/AppData/Local/electron-builder/Cache
key: ${{ runner.os }}-${{ matrix.arch }}-electron-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-${{ matrix.arch }}-electron-
- name: Install dependencies
run: |
npm ci --prefer-offline || \
npm ci --prefer-offline || \
npm ci
env:
ONNXRUNTIME_NODE_INSTALL_CUDA: skip
- name: Download SvelteKit build
uses: actions/download-artifact@v8
with:
name: sveltekit-build
path: build/
- name: Update package.json version
run: npm version ${{ steps.version.outputs.version }} --no-git-tag-version --allow-same-version
- name: Build Electron (macOS)
if: startsWith(matrix.platform, 'mac-')
run: npm run electron:build:mac -- --${{ matrix.arch }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build Electron (Windows)
if: startsWith(matrix.platform, 'win-')
run: npm run electron:build:win -- --${{ matrix.arch }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build Electron (Linux)
if: startsWith(matrix.platform, 'linux-')
run: npm run build && npx electron-builder --linux ${{ matrix.linux_targets }} --${{ matrix.arch }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload Artifacts
uses: actions/upload-artifact@v7
with:
name: build-${{ matrix.platform }}
path: |
dist-electron/*.dmg
dist-electron/*.zip
dist-electron/*.exe
dist-electron/*.deb
dist-electron/*.rpm
dist-electron/*.AppImage
retention-days: 7
publish-release:
name: Publish Release
runs-on: ubuntu-latest
needs: build
if: success()
steps:
- name: Get version from input
id: version
run: |
if [ "${{ github.event_name }}" = "release" ]; then
VERSION="${{ github.event.release.tag_name }}"
elif [ "${{ github.event_name }}" = "push" ]; then
VERSION="${GITHUB_REF#refs/tags/}"
else
VERSION="v${{ inputs.version }}"
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
shell: bash
- name: Publish Draft Release
uses: actions/github-script@v8
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { data: releases } = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo,
});
const draftRelease = releases.find(r => r.tag_name === '${{ steps.version.outputs.version }}' && r.draft);
if (draftRelease) {
await github.rest.repos.updateRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: draftRelease.id,
draft: false
});
console.log(`✅ Published release ${draftRelease.tag_name}`);
} else {
console.log('⚠️ No draft release found for ${{ steps.version.outputs.version }}');
}
- name: Sync main to dev
continue-on-error: true
uses: actions/github-script@v8
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { data: comparison } = await github.rest.repos.compareCommits({
owner: context.repo.owner,
repo: context.repo.repo,
base: 'dev',
head: 'main'
});
if (comparison.ahead_by > 0) {
// Check for existing PR
const { data: prs } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
head: `${context.repo.owner}:main`,
base: 'dev',
state: 'open'
});
let pr;
if (prs.length > 0) {
pr = prs[0];
console.log(`📋 Found existing PR #${pr.number}`);
} else {
const { data: newPr } = await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
head: 'main',
base: 'dev',
title: 'chore: sync main to dev after ${{ steps.version.outputs.version }}',
body: 'Automated PR to sync release changes from main to dev.'
});
pr = newPr;
console.log(`📋 Created PR #${pr.number}`);
}
// Enable auto-merge
try {
await github.rest.pulls.merge({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr.number,
merge_method: 'merge'
});
console.log('✅ Merged PR');
} catch (e) {
console.log('⚠️ Could not merge (may need manual approval):', e.message);
}
} else {
console.log('ℹ️ dev is up to date with main');
}
- name: Trigger Deploy Workflow
uses: actions/github-script@v8
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'deploy.yml',
ref: 'main'
})
cleanup-failed-release:
name: Cleanup Failed Release
runs-on: ubuntu-latest
needs: build
if: failure() || cancelled()
steps:
- name: Get version from input
id: version
run: |
if [ "${{ github.event_name }}" = "release" ]; then
VERSION="${{ github.event.release.tag_name }}"
elif [ "${{ github.event_name }}" = "push" ]; then
VERSION="${GITHUB_REF#refs/tags/}"
else
VERSION="v${{ inputs.version }}"
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
shell: bash
- name: Delete Draft Release
uses: actions/github-script@v8
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { data: releases } = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo,
});
const draftRelease = releases.find(r => r.tag_name === '${{ steps.version.outputs.version }}' && r.draft);
if (draftRelease) {
await github.rest.repos.deleteRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: draftRelease.id
});
console.log(`🗑️ Deleted failed draft release ${draftRelease.tag_name}`);
} else {
console.log('⚠️ No draft release found to delete for ${{ steps.version.outputs.version }}');
}