forked from anomalyco/opencode
-
Notifications
You must be signed in to change notification settings - Fork 1
647 lines (537 loc) · 20.1 KB
/
Copy pathbuild-opencode.yml
File metadata and controls
647 lines (537 loc) · 20.1 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
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
name: Build OpenCode CLI
# 显式设置 run-name 为 commit 消息;GitHub Actions 默认 display_title 不再自动回退到 commit 消息
run-name: ${{ github.event.head_commit.message || github.workflow }}
on:
workflow_dispatch:
inputs:
version:
description: "Override version, for example 1.15.6-smark. Empty means packages/opencode/package.json version."
required: false
type: string
push:
branches:
- dev-smark
paths:
- ".github/workflows/build-opencode.yml"
- ".github/actions/setup-bun/action.yml"
- "packages/opencode/**"
- "packages/core/**"
- "packages/plugin/**"
- "packages/script/**"
- "packages/sdk/js/**"
- "packages/ui/**"
- "package.json"
- "bun.lock"
- "install"
permissions:
contents: write
concurrency:
group: build-opencode-${{ github.ref }}-${{ github.event.inputs.version || 'package-json' }}
cancel-in-progress: false
jobs:
version:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.pkg.outputs.version }}
tag: ${{ steps.pkg.outputs.tag }}
steps:
- uses: actions/checkout@v4
- id: pkg
shell: bash
run: |
set -euo pipefail
VERSION="${{ github.event.inputs.version || '' }}"
if [ -z "$VERSION" ]; then
VERSION="$(node -p "require('./packages/opencode/package.json').version")"
fi
VERSION="${VERSION#v}"
if [ -z "$VERSION" ] || [ "$VERSION" = "undefined" ]; then
echo "Failed to resolve packages/opencode/package.json version" >&2
exit 1
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "tag=v$VERSION" >> "$GITHUB_OUTPUT"
echo "Resolved version: $VERSION"
echo "Resolved tag: v$VERSION"
build-macos:
needs: version
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-bun
- name: Build macOS binaries
shell: bash
run: |
set -euo pipefail
cd packages/opencode
bun run script/build.ts \
--version=${{ needs.version.outputs.version }} \
--os=darwin \
--skip-embed-web-ui
- name: Sign and package macOS assets
shell: bash
run: |
set -euo pipefail
DIST="packages/opencode/dist"
ASSETS="release-assets"
mkdir -p "$ASSETS"
package_macos_target() {
local target="$1"
local bin="${DIST}/${target}/bin/opencode"
local out="${ASSETS}/${target}.zip"
if [ ! -f "$bin" ]; then
echo "Missing macOS binary: $bin" >&2
exit 1
fi
chmod +x "$bin"
# Ad-hoc signing prevents stale/broken signatures on downloaded CLI binaries.
codesign --force --sign - --timestamp=none "$bin"
codesign --verify --verbose=4 "$bin"
rm -f "$out"
(
cd "${DIST}/${target}/bin"
zip -9 -q "${GITHUB_WORKSPACE}/${out}" opencode
)
echo "Created $out"
}
package_macos_target opencode-darwin-arm64
package_macos_target opencode-darwin-x64
ls -lah "$ASSETS"
- name: Upload macOS workflow artifacts
uses: actions/upload-artifact@v4
with:
name: release-assets-macos
if-no-files-found: error
retention-days: 7
path: |
release-assets/opencode-darwin-arm64.zip
release-assets/opencode-darwin-x64.zip
build-linux:
needs: version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-bun
- name: Install Linux packaging tools
shell: bash
run: |
set -euo pipefail
sudo apt-get update
sudo apt-get install -y --no-install-recommends dpkg-dev
- name: Build Linux binaries
shell: bash
run: |
set -euo pipefail
cd packages/opencode
bun run script/build.ts \
--version=${{ needs.version.outputs.version }} \
--os=linux \
--skip-embed-web-ui
- name: Package Linux assets
shell: bash
run: |
set -euo pipefail
VERSION="${{ needs.version.outputs.version }}"
DIST="packages/opencode/dist"
ASSETS="release-assets"
mkdir -p "$ASSETS"
package_linux_tarball() {
local target="$1"
local bin="${DIST}/${target}/bin/opencode"
local out="${ASSETS}/${target}.tar.gz"
if [ ! -f "$bin" ]; then
echo "Skip missing Linux binary: $bin"
return 0
fi
chmod +x "$bin"
(
cd "${DIST}/${target}/bin"
tar -czf "${GITHUB_WORKSPACE}/${out}" opencode
)
echo "Created $out"
}
package_linux_tarball opencode-linux-x64
package_linux_tarball opencode-linux-arm64
if [ ! -f "${ASSETS}/opencode-linux-x64.tar.gz" ]; then
echo "Required Linux x64 asset was not created" >&2
exit 1
fi
# Debian/Ubuntu package for amd64. This intentionally uses /usr/local/bin
# to match the current manual binary install convention for this fork.
DEB_ROOT="/tmp/opencode-deb"
PKG_DIR="${DEB_ROOT}/opencode_${VERSION}_amd64"
BINARY="${DIST}/opencode-linux-x64/bin/opencode"
DEB_OUT="${ASSETS}/opencode_${VERSION}_amd64.deb"
rm -rf "$DEB_ROOT"
mkdir -p "${PKG_DIR}/DEBIAN"
mkdir -p "${PKG_DIR}/usr/local/bin"
install -m 0755 "$BINARY" "${PKG_DIR}/usr/local/bin/opencode"
cat > "${PKG_DIR}/DEBIAN/control" <<EOF
Package: opencode
Version: ${VERSION}
Section: utils
Priority: optional
Architecture: amd64
Maintainer: smark <smark@local>
Description: opencode AI-powered development tool (smark build)
A standalone AI coding assistant with TUI, version ${VERSION}.
EOF
# dpkg control files must not contain leading indentation.
sed -i 's/^ //' "${PKG_DIR}/DEBIAN/control"
dpkg-deb --build "$PKG_DIR" "$DEB_OUT"
ls -lah "$ASSETS"
- name: Upload Linux workflow artifacts
uses: actions/upload-artifact@v4
with:
name: release-assets-linux
if-no-files-found: error
retention-days: 7
path: |
release-assets/opencode-linux-x64.tar.gz
release-assets/opencode-linux-arm64.tar.gz
release-assets/opencode_*_amd64.deb
build-windows:
needs: version
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "22"
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- uses: microsoft/setup-msbuild@v2
# Keep macOS/Linux on the shared setup-bun action, but avoid it on Windows:
# restoring/saving the multi-GB Bun package cache is slower than a clean install
# on GitHub-hosted Windows runners.
- uses: oven-sh/setup-bun@v2
with:
bun-version-file: package.json
- name: Install Windows dependencies
shell: pwsh
env:
ELECTRON_SKIP_BINARY_DOWNLOAD: "1"
ELECTRON_SKIP_DOWNLOAD: "1"
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "1"
PUPPETEER_SKIP_DOWNLOAD: "1"
CYPRESS_INSTALL_BINARY: "0"
HUSKY: "0"
run: |
$ErrorActionPreference = "Stop"
python -c "import setuptools" 2>$null
if ($LASTEXITCODE -ne 0) {
python -m pip install setuptools
}
bun install --linker hoisted
- name: Build Windows x64 binary
shell: pwsh
run: |
$ErrorActionPreference = "Stop"
cd packages/opencode
bun run script/build.ts --version=${{ needs.version.outputs.version }} --os=win32 --arch=x64 --skip-embed-web-ui
- name: Package Windows assets
shell: pwsh
run: |
$ErrorActionPreference = "Stop"
$Dist = "packages/opencode/dist"
$Source = Join-Path $Dist "opencode-windows-x64/bin/opencode.exe"
$Assets = "release-assets"
$Stage = Join-Path $env:RUNNER_TEMP "opencode-windows-x64"
$ZipOut = Join-Path $Assets "opencode-windows-x64.zip"
$ExeOut = Join-Path $Assets "opencode-windows-x64.exe"
if (!(Test-Path $Source)) {
throw "Missing Windows binary: $Source"
}
New-Item -ItemType Directory -Force -Path $Assets | Out-Null
New-Item -ItemType Directory -Force -Path $Stage | Out-Null
Copy-Item $Source (Join-Path $Stage "opencode.exe") -Force
Copy-Item $Source $ExeOut -Force
if (Test-Path $ZipOut) {
Remove-Item $ZipOut -Force
}
Compress-Archive -Path (Join-Path $Stage "opencode.exe") -DestinationPath $ZipOut -CompressionLevel Optimal
Get-ChildItem $Assets | Format-Table Name, Length
- name: Upload Windows workflow artifacts
uses: actions/upload-artifact@v4
with:
name: release-assets-windows
if-no-files-found: error
retention-days: 7
path: |
release-assets/opencode-windows-x64.zip
release-assets/opencode-windows-x64.exe
smoke-macos:
# smoke必须下载刚刚打包的archive,而不是直接运行build目录,才能覆盖release层解压和权限行为。
needs:
- version
- build-macos
runs-on: macos-latest
strategy:
fail-fast: false
matrix:
target:
# arm64和x64分别保留target identity;不能把arm runner的结果冒充Intel runtime。
- opencode-darwin-arm64
- opencode-darwin-x64
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-bun
- name: Download macOS archive
uses: actions/download-artifact@v4
with:
name: release-assets-macos
path: release-assets
- name: Extract and smoke compiled artifact
shell: bash
run: |
# 每个matrix项使用独立runner temp,避免两个architecture覆盖同名opencode文件。
set -euo pipefail
mkdir -p "$RUNNER_TEMP/opentui-smoke"
unzip -q "release-assets/${{ matrix.target }}.zip" -d "$RUNNER_TEMP/opentui-smoke"
bun run --cwd packages/opencode script/smoke-opentui-artifact.ts \
--binary "$RUNNER_TEMP/opentui-smoke/opencode"
smoke-linux-x64:
# Linux x64在现有host执行,证明glibc archive能加载对应OpenTUI native闭包。
needs:
- version
- build-linux
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-bun
- name: Download Linux archives
uses: actions/download-artifact@v4
with:
name: release-assets-linux
path: release-assets
- name: Extract and smoke compiled artifact
shell: bash
run: |
# tarball内只允许最终opencode入口,harness的source依赖来自当前checkout而非archive旁路。
set -euo pipefail
mkdir -p "$RUNNER_TEMP/opentui-smoke"
tar -xzf release-assets/opencode-linux-x64.tar.gz -C "$RUNNER_TEMP/opentui-smoke"
bun run --cwd packages/opencode script/smoke-opentui-artifact.ts \
--binary "$RUNNER_TEMP/opentui-smoke/opencode"
smoke-linux-arm64:
# arm runner是真实执行而非cross-compile;缺少runner或smoke失败都必须阻断checksums。
needs:
- version
- build-linux
runs-on: ubuntu-24.04-arm
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-bun
- name: Download Linux archives
uses: actions/download-artifact@v4
with:
name: release-assets-linux
path: release-assets
- name: Extract and smoke compiled artifact
shell: bash
run: |
# aarch64 archive在原生arm host执行,不能使用qemu或metadata检查替代native加载。
set -euo pipefail
mkdir -p "$RUNNER_TEMP/opentui-smoke"
tar -xzf release-assets/opencode-linux-arm64.tar.gz -C "$RUNNER_TEMP/opentui-smoke"
bun run --cwd packages/opencode script/smoke-opentui-artifact.ts \
--binary "$RUNNER_TEMP/opentui-smoke/opencode"
smoke-windows:
# Windows使用ConPTY入口,不能用macOS PTY结果替代DLL加载和控制台退出证据。
needs:
- version
- build-windows
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
with:
bun-version-file: package.json
- name: Install dependencies
shell: pwsh
env:
ELECTRON_SKIP_BINARY_DOWNLOAD: "1"
ELECTRON_SKIP_DOWNLOAD: "1"
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "1"
PUPPETEER_SKIP_DOWNLOAD: "1"
CYPRESS_INSTALL_BINARY: "0"
HUSKY: "0"
run: bun install --linker hoisted
- name: Download Windows archive
uses: actions/download-artifact@v4
with:
name: release-assets-windows
path: release-assets
- name: Extract and smoke compiled artifact
shell: pwsh
run: |
# Expand-Archive后直接运行解压exe,确保zip中的最终文件而非构建目录接受ConPTY验证。
$ErrorActionPreference = "Stop"
$SmokeRoot = Join-Path $env:RUNNER_TEMP "opentui-smoke"
New-Item -ItemType Directory -Force -Path $SmokeRoot | Out-Null
Expand-Archive -Path "release-assets/opencode-windows-x64.zip" -DestinationPath $SmokeRoot -Force
bun run --cwd packages/opencode script/smoke-opentui-artifact.ts --binary (Join-Path $SmokeRoot "opencode.exe")
checksums:
# checksums和release只能在closure及所有host smoke成功后生成,避免发布半验证产物。
needs:
- version
- build-macos
- build-linux
- build-windows
- opentui-closure
- smoke-macos
- smoke-linux-x64
- smoke-linux-arm64
- smoke-windows
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # release notes 需要完整 commit 历史 + 全部 tag
- name: Download release workflow artifacts
uses: actions/download-artifact@v4
with:
pattern: release-assets-*
path: release-assets
merge-multiple: true
- name: Add install script and generate checksums
shell: bash
run: |
set -euo pipefail
if [ ! -f install ]; then
echo "Missing repository install script at ./install" >&2
exit 1
fi
cp install release-assets/install
chmod +x release-assets/install
cd release-assets
echo "Release assets before checksums:"
find . -maxdepth 1 -type f -printf '%f\n' | sort
find . -maxdepth 1 -type f ! -name checksums.txt -printf '%f\0' \
| sort -z \
| xargs -0 sha256sum > checksums.txt
echo "==== checksums.txt ===="
cat checksums.txt
- name: Generate release notes from commit log
env:
VERSION: ${{ needs.version.outputs.version }}
shell: bash
run: |
set -euo pipefail
# 上一个版本 tag(排除当前版本自身;匹配 v*-smark 格式)
PREV_TAG=$(git tag --sort=-creatordate \
| grep -E "^v[0-9]+\.[0-9]+\.[0-9]+(-smark)?$" \
| grep -vE "^v${VERSION}$" \
| head -1)
{
echo "## 更新内容"
echo ""
if [ -z "$PREV_TAG" ]; then
echo "(首次发布)"
git log --format="%h %s" --reverse | head -50
else
# 版本 bump commit:首个把当前版本号写进 package.json 的提交
BUMPCOMMIT=$(git log "${PREV_TAG}..HEAD" --reverse --format="%H" \
-S "\"version\": \"${VERSION}\"" -- packages/opencode/package.json | head -1)
if [ -n "$BUMPCOMMIT" ]; then
# 有版本 bump:分两节,避免上个版本期间积累的 commit 与本版本新增混在一起
POST_BUMP=$(git log "${BUMPCOMMIT}..HEAD" --format="%h %s" --reverse)
if [ -n "$POST_BUMP" ]; then
echo "### v${VERSION} 新增"
echo ""
echo "$POST_BUMP"
echo ""
fi
ACCUMULATED=$(git log "${PREV_TAG}..${BUMPCOMMIT}" --format="%h %s" --reverse)
if [ -n "$ACCUMULATED" ]; then
echo "### 自 \`${PREV_TAG}\` 积累"
echo ""
echo "$ACCUMULATED"
echo ""
fi
else
# 无版本 bump(同版本重新 push 或手动覆盖版本号):单节展示全部增量
echo "自 \`${PREV_TAG}\` 以来的变更:"
echo ""
git log "${PREV_TAG}..HEAD" --format="%h %s" --reverse
echo ""
fi
fi
echo "---"
echo "自动构建 from ${{ github.sha }}"
} > release-notes.md
echo "==== release-notes.md ===="
cat release-notes.md
- name: Create or update GitHub Release
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ needs.version.outputs.tag }}
shell: bash
run: |
set -euo pipefail
if gh release view "$TAG" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
echo "Release $TAG already exists; updating notes and assets."
gh release edit "$TAG" --repo "$GITHUB_REPOSITORY" --notes-file release-notes.md
else
gh release create "$TAG" \
--repo "$GITHUB_REPOSITORY" \
--target "$GITHUB_SHA" \
--title "$TAG" \
--notes-file release-notes.md
fi
- name: Upload release assets with retry
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ needs.version.outputs.tag }}
shell: bash
run: |
set -euo pipefail
upload_with_retry() {
local file="$1"
local max_attempts=5
local attempt=1
while true; do
echo "Uploading ${file} attempt ${attempt}/${max_attempts}"
if gh release upload "$TAG" "$file" \
--repo "$GITHUB_REPOSITORY" \
--clobber; then
echo "Uploaded ${file}"
return 0
fi
if [ "$attempt" -ge "$max_attempts" ]; then
echo "Failed to upload ${file} after ${max_attempts} attempts" >&2
return 1
fi
sleep $(( attempt * 15 ))
attempt=$(( attempt + 1 ))
done
}
cd release-assets
mapfile -t files < <(find . -maxdepth 1 -type f -printf '%f\n' | sort)
if [ "${#files[@]}" -eq 0 ]; then
echo "No release assets found" >&2
exit 1
fi
echo "Uploading release assets:"
printf ' %s\n' "${files[@]}"
for file in "${files[@]}"; do
upload_with_retry "$file"
done
opentui-closure:
needs: version
runs-on: ubuntu-latest
timeout-minutes: 30
defaults:
run:
shell: bash
steps:
- name: Checkout repository with OpenTUI provenance
uses: actions/checkout@v4
with:
submodules: recursive
- name: Setup Bun
uses: ./.github/actions/setup-bun
- name: Verify immutable OpenTUI closure
working-directory: packages/opencode
run: bun run script/verify-opentui-closure.ts --source-revision-authorized