-
Notifications
You must be signed in to change notification settings - Fork 607
380 lines (336 loc) · 14.6 KB
/
Copy pathrelease.yml
File metadata and controls
380 lines (336 loc) · 14.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
name: Release
on:
push:
tags: ['v*']
jobs:
test:
name: Test
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v5
- name: Setup Node.js
uses: actions/setup-node@v5
with:
node-version: '24'
cache: 'npm'
- name: Verify tag matches package version
run: node scripts/verify-release-version.mjs
- name: Install dependencies
run: npm ci
- name: Secret scan
run: npm run secret-scan
- name: Run tests
run: npm run test:release
docker:
name: Docker Build & Push
needs: test
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v5
- name: Build metadata
run: |
echo "VERSION=${GITHUB_REF_NAME#v}" >> "$GITHUB_ENV"
echo "COMMIT_DATE=$(git log -1 --pretty=%cI)" >> "$GITHUB_ENV"
echo "BUILD_BRANCH=${GITHUB_REF_NAME}" >> "$GITHUB_ENV"
{
echo "COMMIT_MESSAGE<<EOF"
git log -1 --pretty=%s
echo "EOF"
} >> "$GITHUB_ENV"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Login to GHCR
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker metadata
id: meta
uses: docker/metadata-action@v6
with:
# github.repository (= dwgx/WindsurfAPI) lowercases to "windsurfapi"
# without the hyphen the package.json npm name uses. Hardcode the
# kebab form so the image name stays "windsurf-api".
images: ghcr.io/${{ github.repository_owner }}/windsurf-api
tags: |
# Only tag as latest for stable releases (no pre-release suffix like -rc, -alpha, -beta)
type=raw,value=latest,enable=${{ !contains(github.ref_name, '-') }}
# v2.0.6 -> 2.0.6
type=semver,pattern={{version}}
# v2.0.6 -> 2.0
type=semver,pattern={{major}}.{{minor}}
- name: Build and push
uses: docker/build-push-action@v7
with:
context: .
platforms: linux/amd64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
BUILD_VERSION=${{ env.VERSION }}
BUILD_COMMIT=${{ github.sha }}
BUILD_COMMIT_MESSAGE=${{ env.COMMIT_MESSAGE }}
BUILD_COMMIT_DATE=${{ env.COMMIT_DATE }}
BUILD_BRANCH=${{ env.BUILD_BRANCH }}
- name: Summary
run: |
echo "## Docker Image Published" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "**Tags:**" >> "$GITHUB_STEP_SUMMARY"
echo '${{ steps.meta.outputs.tags }}' | tr ',' '\n' | sed 's/^/- `/' | sed 's/$/`/' >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "**Platform:** \`linux/amd64\`" >> "$GITHUB_STEP_SUMMARY"
macos-exe-arm64:
name: macOS single-binary (arm64)
needs: test
runs-on: macos-latest
timeout-minutes: 30
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v5
- name: Setup Node.js
uses: actions/setup-node@v5
with:
node-version: '22'
- name: Build windsurfapi-macos-arm64
run: |
npm i -g @yao-pkg/pkg@6.21.0 esbuild
npm run build:bundle
mkdir -p dist-macos
pkg src/_bundle.cjs --config package.json --targets node22-macos-arm64 --output dist-macos/windsurfapi-macos-arm64
- name: Smoke-check the binary boots
run: node scripts/exe-boot-smoke.mjs dist-macos/windsurfapi-macos-arm64
- name: Upload binary artifact
uses: actions/upload-artifact@v6
with:
name: windsurfapi-macos-arm64
path: dist-macos/windsurfapi-macos-arm64
if-no-files-found: error
# Use an explicit Intel label so the x64 build does not move to ARM.
# It is NOT in the release `needs`, so a failed or delayed x64 build never
# blocks the release. If it finishes in time its artifact is picked up;
# otherwise the release ships without the x64 binary.
macos-exe-x64:
name: macOS single-binary (x64 — non-blocking)
needs: test
runs-on: macos-26-intel
continue-on-error: true
timeout-minutes: 45
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v5
- name: Setup Node.js
uses: actions/setup-node@v5
with:
node-version: '22'
- name: Build windsurfapi-macos-x64
run: |
npm i -g @yao-pkg/pkg@6.21.0 esbuild
npm run build:bundle
mkdir -p dist-macos
pkg src/_bundle.cjs --config package.json --targets node22-macos-x64 --output dist-macos/windsurfapi-macos-x64
- name: Smoke-check the binary boots
run: node scripts/exe-boot-smoke.mjs dist-macos/windsurfapi-macos-x64
- name: Upload binary artifact
uses: actions/upload-artifact@v6
with:
name: windsurfapi-macos-x64
path: dist-macos/windsurfapi-macos-x64
if-no-files-found: error
windows-exe:
name: Windows single-exe
needs: test
runs-on: windows-latest
timeout-minutes: 30
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v5
- name: Setup Node.js
uses: actions/setup-node@v5
with:
# Match the pkg target (node22-win-x64). pkg-fetch 3.6.4 ships prebuilt
# base binaries for node22/24/26 but NOT node20 — a node20 target 404s
# then falls back to compiling Node from source (no VS toolchain on the
# runner → fails). node22 is LTS and has multiple prebuilts.
node-version: '22'
# Build the single .exe. pkg can't ingest our ESM tree directly:
# package.json has "type":"module", so pkg loads each src/*.js as ESM but
# its bytecode/fallback path emits CommonJS (module.exports) → "module is
# not defined in ES module scope" at boot (seen in rc1/rc2). Fix: esbuild
# first bundles the whole ESM graph into ONE CommonJS file (src/_bundle.cjs)
# — no per-file ESM/CJS ambiguity — then pkg wraps that single CJS file.
# The bundle keeps import.meta.url meaningful via a banner shim
# (pathToFileURL(__filename)), so config.js/server.js/devin-connect-models
# still resolve dashboard/ + data/ relative to the bundle; pkg's `assets`
# (in package.json) map those files into the snapshot at the same paths.
# The Windows runner has the network to fetch pkg's node22 base binary
# (node20 has none → don't use it). Zero runtime deps, so no `npm ci`.
- name: Build windsurfapi.exe
run: |
npm i -g @yao-pkg/pkg@6.21.0 esbuild
npm run build:bundle
pkg src/_bundle.cjs --config package.json --targets node22-win-x64 --output dist-windows/windsurfapi.exe
- name: Smoke-check the exe boots
shell: pwsh
run: |
$env:DEVIN_CONNECT = '1'; $env:HOST = '127.0.0.1'; $env:PORT = '3999'
$env:API_KEY = 'ci-smoke'; $env:DATA_DIR = "$env:RUNNER_TEMP\wa-smoke"
$env:WINDSURFAPI_NO_OPEN = '1' # don't try to launch a browser on the headless runner
$out = "$env:RUNNER_TEMP\exe-out.log"; $err = "$env:RUNNER_TEMP\exe-err.log"
$p = Start-Process -FilePath dist-windows\windsurfapi.exe -PassThru -WindowStyle Hidden -RedirectStandardOutput $out -RedirectStandardError $err
$ok = $false
for ($i = 0; $i -lt 40; $i++) {
if ($p.HasExited) { break }
try { $r = Invoke-WebRequest 'http://127.0.0.1:3999/health' -UseBasicParsing -TimeoutSec 3; if ($r.StatusCode -eq 200) { $ok = $true; break } } catch {}
Start-Sleep -Milliseconds 500
}
try { $d = Invoke-WebRequest 'http://127.0.0.1:3999/dashboard' -UseBasicParsing -TimeoutSec 5; $dashOk = ($d.StatusCode -eq 200 -and $d.Content.Length -gt 1000) } catch { $dashOk = $false }
Stop-Process -Id $p.Id -Force -ErrorAction SilentlyContinue
Write-Host "--- exe stdout ---"; if (Test-Path $out) { Get-Content $out -Tail 40 }
Write-Host "--- exe stderr ---"; if (Test-Path $err) { Get-Content $err -Tail 40 }
if (-not $ok) { Write-Error 'exe did not answer /health'; exit 1 }
if (-not $dashOk) { Write-Error 'exe did not serve /dashboard (asset bundling broken?)'; exit 1 }
Write-Host 'exe smoke OK: /health 200 + /dashboard served from snapshot assets'
# Assemble the "解压即用" zip: the exe + the tray launcher scripts + icon,
# all in ONE flat folder. tray.ps1 auto-detects the sibling windsurfapi.exe
# and switches to EXE mode (no Node, no source tree). Double-click tray.vbs
# → system-tray icon; or double-click windsurfapi.exe → console window.
# Both are zero-dependency (the exe carries its own Node runtime).
- name: Package Windows zip (exe + tray)
shell: pwsh
run: |
$stage = "$env:RUNNER_TEMP\wa-zip"
New-Item -ItemType Directory -Path $stage -Force | Out-Null
Copy-Item dist-windows\windsurfapi.exe $stage\
Copy-Item deploy\windows\tray.vbs $stage\
Copy-Item deploy\windows\tray.ps1 $stage\
Copy-Item deploy\windows\tray.bat $stage\
Copy-Item deploy\windows\windsurfapi.ico $stage\ -ErrorAction SilentlyContinue
$readme = @(
'WindsurfAPI - Windows 免安装分发包',
'====================================',
'',
'两种启动方式(都无需安装 Node.js、无需源码):',
'',
'1) 系统托盘(推荐):双击 tray.vbs',
' -> 右下角系统匣出现图标,右键可【打开面板 / 复制面板密码 /',
' 复制 API Key / 状态 / 重启 / 退出】。无黑窗。',
'',
'2) 控制台:双击 windsurfapi.exe',
' -> 弹出一个控制台窗口显示日志。',
'',
'首次启动会自动生成 API_KEY 与 DASHBOARD_PASSWORD 并写入本目录的',
'.env,同时自动打开后台面板 http://127.0.0.1:3003/dashboard 。',
'在面板里贴上 Devin session token 即可上号,其余免配置。',
'',
'默认仅本机访问(HOST=127.0.0.1)。要对外提供服务,编辑 .env 把',
'HOST 改成 0.0.0.0 并保留一个强 API_KEY。'
) -join "`r`n"
Set-Content -Path "$stage\启动说明.txt" -Value $readme -Encoding UTF8
$zipPath = "$PWD\dist-windows\windsurfapi-windows.zip"
Get-ChildItem -Path $stage | Compress-Archive -DestinationPath $zipPath -Force
Write-Host "--- zip contents ---"
Add-Type -AssemblyName System.IO.Compression.FileSystem
$zr = [System.IO.Compression.ZipFile]::OpenRead($zipPath)
$have = $zr.Entries.FullName
$have | ForEach-Object { Write-Host $_ }
$zr.Dispose()
$must = @('windsurfapi.exe','tray.vbs','tray.ps1','tray.bat')
foreach ($m in $must) { if ($have -notcontains $m) { Write-Error "zip missing $m"; exit 1 } }
Write-Host 'zip OK: exe + tray scripts present'
- name: Upload exe artifact
uses: actions/upload-artifact@v6
with:
name: windsurfapi-windows-exe
path: |
dist-windows/windsurfapi.exe
dist-windows/windsurfapi-windows.zip
if-no-files-found: error
release:
name: GitHub Release
needs: [docker, windows-exe, macos-exe-arm64]
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v5
- name: Get version from tag
id: version
run: echo "VERSION=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"
- name: Check for release notes
id: notes
run: |
NEW_PATH="docs/releases/RELEASE_NOTES_${{ steps.version.outputs.VERSION }}.md"
OLD_PATH="RELEASE_NOTES_${{ steps.version.outputs.VERSION }}.md"
if [[ -f "$NEW_PATH" ]]; then
echo "file=$NEW_PATH" >> "$GITHUB_OUTPUT"
echo "found=true" >> "$GITHUB_OUTPUT"
elif [[ -f "$OLD_PATH" ]]; then
echo "file=$OLD_PATH" >> "$GITHUB_OUTPUT"
echo "found=true" >> "$GITHUB_OUTPUT"
else
echo "found=false" >> "$GITHUB_OUTPUT"
fi
- name: Download Windows exe
uses: actions/download-artifact@v7
with:
name: windsurfapi-windows-exe
path: dist-windows
- name: Download macOS arm64 binary
uses: actions/download-artifact@v7
with:
name: windsurfapi-macos-arm64
path: dist-macos
- name: Download macOS x64 binary (optional)
uses: actions/download-artifact@v7
continue-on-error: true
with:
name: windsurfapi-macos-x64
path: dist-macos
- name: Package macOS zip (arm64 + scripts; x64 included if available)
run: |
chmod +x dist-macos/windsurfapi-macos-arm64
[ -f dist-macos/windsurfapi-macos-x64 ] && chmod +x dist-macos/windsurfapi-macos-x64 || true
cp deploy/macos/run.sh dist-macos/
cp deploy/macos/run-background.sh dist-macos/
cp deploy/macos/stop.sh dist-macos/
cp deploy/macos/install-launchd.sh dist-macos/
cp deploy/macos/uninstall-launchd.sh dist-macos/
cp deploy/macos/README.md dist-macos/
chmod +x dist-macos/*.sh
cd dist-macos && zip -r ../windsurfapi-macos.zip . && cd ..
echo "macOS zip contents:"; unzip -l windsurfapi-macos.zip
- name: Create GitHub Release
uses: softprops/action-gh-release@v3
with:
name: v${{ steps.version.outputs.VERSION }}
body_path: ${{ steps.notes.outputs.found == 'true' && steps.notes.outputs.file || '' }}
generate_release_notes: ${{ steps.notes.outputs.found != 'true' }}
draft: false
prerelease: ${{ contains(github.ref_name, '-') }}
files: |
dist-windows/windsurfapi.exe
dist-windows/windsurfapi-windows.zip
dist-macos/windsurfapi-macos-arm64
windsurfapi-macos.zip