-
Notifications
You must be signed in to change notification settings - Fork 237
288 lines (247 loc) · 9.67 KB
/
Copy pathrelease.yml
File metadata and controls
288 lines (247 loc) · 9.67 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
name: Release Electron App
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
tag:
description: "Tag to release (e.g. v1.0.57)"
required: true
type: string
permissions:
contents: write
jobs:
build:
strategy:
fail-fast: false
matrix:
include:
- os: windows-latest
platform: win
artifact: windows
- os: macos-latest
platform: mac
arch: arm64
artifact: macos-arm64
- os: ubuntu-latest
platform: linux
artifact: linux
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ inputs.tag || github.ref }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
cache-dependency-path: |
package-lock.json
web/package-lock.json
native/package-lock.json
- name: Install all workspace dependencies
run: npm ci --ignore-scripts
- name: Install web frontend dependencies
run: cd web && npm ci
- name: Build core (web + tsc)
run: npm run build
- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Cache Rust build
uses: actions/cache@v4
with:
path: native/target
key: native-${{ runner.os }}-${{ matrix.arch || 'x64' }}-${{ hashFiles('native/Cargo.lock') }}
restore-keys: native-${{ runner.os }}-${{ matrix.arch || 'x64' }}-
- name: Install native addon dependencies
working-directory: native
run: npm ci
- name: Build native addon
working-directory: native
run: npm run build
- name: Bundle Electron (esbuild)
working-directory: packages/electron
run: node electron/build.mjs
- name: Prepare pack (copy root resources)
working-directory: packages/electron
run: node electron/prepare-pack.mjs
- name: Clean stale release assets
continue-on-error: true
run: |
TAG="${{ inputs.tag || github.ref_name }}"
ASSETS=$(gh release view "$TAG" --json assets -q '.assets[].name' 2>/dev/null || echo "")
[ -z "$ASSETS" ] && exit 0
case "${{ matrix.platform }}" in
mac) PATTERN="mac-${{ matrix.arch }}" ;;
win) PATTERN="win-" ;;
linux) PATTERN="linux-" ;;
esac
echo "$ASSETS" | grep -iE "$PATTERN" | while read -r name; do
echo "Removing stale asset: $name"
gh release delete-asset "$TAG" "$name" -y 2>/dev/null || true
done
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Pack (${{ matrix.platform }}${{ matrix.arch && format('-{0}', matrix.arch) || '' }})
working-directory: packages/electron
# shell: bash needed so the Windows runner uses Git Bash instead of pwsh
# (pwsh doesn't handle backslash line continuations the same way).
shell: bash
run: |
# Drive electron-builder version from the tag, not package.json. Required
# so beta tags (vX.Y.Z-beta.SHA, where bump-electron-beta.yml deliberately
# does NOT touch package.json) publish to the correct GitHub release and
# are detected as prerelease by electron-builder's semver suffix check.
TAG="${{ inputs.tag || github.ref_name }}"
VERSION="${TAG#v}"
npx electron-builder --config electron-builder.yml \
--${{ matrix.platform }} ${{ matrix.arch && format('--{0}', matrix.arch) || '' }} \
--config.extraMetadata.version="$VERSION" \
--publish always
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# macOS x64 runs AFTER arm64 to avoid release asset upload collisions
# (shared files like latest-mac.yml don't include arch in the name)
build-mac-x64:
needs: build
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ inputs.tag || github.ref }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
cache-dependency-path: |
package-lock.json
web/package-lock.json
native/package-lock.json
- name: Install all workspace dependencies
run: npm ci --ignore-scripts
- name: Install web frontend dependencies
run: cd web && npm ci
- name: Build core (web + tsc)
run: npm run build
- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: x86_64-apple-darwin
- name: Cache Rust build
uses: actions/cache@v4
with:
path: native/target
key: native-macos-x64-${{ hashFiles('native/Cargo.lock') }}
restore-keys: native-macos-x64-
- name: Install native addon dependencies
working-directory: native
run: npm ci
- name: Build native addon (x64)
working-directory: native
run: npx napi build --platform --release --target x86_64-apple-darwin
- name: Bundle Electron (esbuild)
working-directory: packages/electron
run: node electron/build.mjs
- name: Prepare pack (copy root resources)
working-directory: packages/electron
run: node electron/prepare-pack.mjs
- name: Clean stale x64 release assets
continue-on-error: true
run: |
TAG="${{ inputs.tag || github.ref_name }}"
ASSETS=$(gh release view "$TAG" --json assets -q '.assets[].name' 2>/dev/null || echo "")
[ -z "$ASSETS" ] && exit 0
echo "$ASSETS" | grep -iE "mac-x64" | while read -r name; do
echo "Removing stale asset: $name"
gh release delete-asset "$TAG" "$name" -y 2>/dev/null || true
done
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Pack (mac-x64)
working-directory: packages/electron
shell: bash
run: |
TAG="${{ inputs.tag || github.ref_name }}"
VERSION="${TAG#v}"
npx electron-builder --config electron-builder.yml \
--mac --x64 \
--config.extraMetadata.version="$VERSION" \
--publish never
- name: Upload x64 artifacts to release
run: |
TAG="${{ inputs.tag || github.ref_name }}"
cd packages/electron/release
for f in *; do
[ -f "$f" ] || continue
# Only upload x64 files; skip arm64 and yml manifests
echo "$f" | grep -qi "arm64" && continue
echo "$f" | grep -qiE "\.yml$" && continue
echo "Uploading: $f"
gh release upload "$TAG" "$f" --clobber 2>/dev/null || true
done
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Merge x64 entries into latest-mac.yml
run: |
TAG="${{ inputs.tag || github.ref_name }}"
gh release download "$TAG" --pattern "latest-mac.yml" --output /tmp/arm64-mac.yml --clobber 2>/dev/null || exit 0
LOCAL_YML="packages/electron/release/latest-mac.yml"
[ -f "$LOCAL_YML" ] || exit 0
node -e "
const fs = require('fs');
const yaml = require('js-yaml');
const arm64Yml = yaml.load(fs.readFileSync('/tmp/arm64-mac.yml', 'utf8'));
const x64Yml = yaml.load(fs.readFileSync('$LOCAL_YML', 'utf8'));
const arm64Files = (arm64Yml.files || []).filter(f => f.url.includes('arm64'));
const x64Files = (x64Yml.files || []).filter(f => !f.url.includes('arm64'));
arm64Yml.files = [...arm64Files, ...x64Files];
fs.writeFileSync('/tmp/merged-mac.yml', yaml.dump(arm64Yml, { lineWidth: -1, quotingType: '\"' }));
"
mv /tmp/merged-mac.yml /tmp/latest-mac.yml
gh release upload "$TAG" /tmp/latest-mac.yml --clobber
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
release:
needs: [build, build-mac-x64]
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v') || inputs.tag
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ inputs.tag || github.ref }}
fetch-depth: 0
- name: Resolve tag
id: tag
run: |
TAG="${{ inputs.tag || github.ref_name }}"
echo "name=$TAG" >> "$GITHUB_OUTPUT"
- name: Generate release notes and publish
run: |
TAG="${{ steps.tag.outputs.name }}"
PREV_TAG=$(git tag --sort=-v:refname | grep '^v' | grep -v "^${TAG}$" | head -1)
if [ -z "$PREV_TAG" ]; then
BODY="Initial release"
else
BODY=$(git log "${PREV_TAG}..${TAG}" --no-merges --pretty=format:"%s" \
| grep -vE "^(chore|docs|ci)(\(.*\))?:" \
| sed 's/^/- /')
if [ -z "$BODY" ]; then
BODY="Bug fixes and improvements"
fi
fi
echo "$BODY" > /tmp/release-notes.md
# Tag like v1.2.3-beta.SHA → mark as prerelease (semver convention).
# Defensive: electron-builder normally does this, but the create fallback
# below would miss it when electron-builder's draft creation didn't fire.
PRERELEASE_FLAG=""
case "$TAG" in *-*) PRERELEASE_FLAG="--prerelease" ;; esac
gh release edit "$TAG" --draft=false $PRERELEASE_FLAG --notes-file /tmp/release-notes.md 2>/dev/null || \
gh release create "$TAG" --title "$TAG" $PRERELEASE_FLAG --notes-file /tmp/release-notes.md
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}