-
Notifications
You must be signed in to change notification settings - Fork 3
169 lines (151 loc) · 5.93 KB
/
Copy pathbuild-binaries.yml
File metadata and controls
169 lines (151 loc) · 5.93 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
name: Build binaries
# Cross-compile single-file native binaries for the major desktop targets
# and attach them to the GitHub release. Runs in parallel with release.yml;
# softprops/action-gh-release@v2 is idempotent so the npm-publish workflow
# creating the release and the binary jobs attaching assets coexist
# without coordination.
on:
push:
tags:
- "v2.*"
# Manual trigger so we can backfill binaries onto an existing release
# without bumping the version. Pass the tag name as input.
workflow_dispatch:
inputs:
tag:
description: "Tag to build (e.g. v2.0.0-pre.54)"
required: true
permissions:
contents: write
jobs:
build:
name: Build ${{ matrix.asset }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- target: bun-linux-x64-modern
asset: codebase-linux-x64
- target: bun-linux-arm64
asset: codebase-linux-arm64
- target: bun-darwin-x64
asset: codebase-darwin-x64
- target: bun-darwin-arm64
asset: codebase-darwin-arm64
- target: bun-windows-x64
asset: codebase-windows-x64.exe
steps:
- uses: actions/checkout@v4
with:
# For workflow_dispatch runs, check out the tag passed as input
# so the build matches that version. Falls back to GITHUB_REF
# on tag-push triggers.
ref: ${{ inputs.tag || github.ref }}
- uses: oven-sh/setup-bun@v2
with:
bun-version: "1.3.14"
- uses: actions/setup-node@v4
with:
node-version: "20"
cache: npm
- name: Install
run: npm ci
- name: Stub ink devtools
# ink's devtools entry has a top-level `import 'react-devtools-core'`
# behind a runtime gate, but bun's bundler eagerly resolves the
# dynamic import. Replace the entry with an empty stub so the
# compiled binary doesn't try to find react-devtools-core at
# runtime. Production paths never load this anyway (DEV != 'true').
run: |
cat > node_modules/ink/build/devtools.js <<'EOF'
export default { connectToDevTools() {} };
EOF
- name: Compile ${{ matrix.target }}
run: |
VERSION_JSON="$(node -p "JSON.stringify(require('./package.json').version)")"
bun build --compile --target=${{ matrix.target }} \
--define "CODEBASE_BUILD_VERSION=${VERSION_JSON}" \
src/cli.tsx --outfile=${{ matrix.asset }}
- name: Smoke-test binary
# Only the linux-x64 binary can run on the linux runner. The
# other targets are cross-compiled — we trust bun's compile output
# for them and verify post-release.
if: matrix.target == 'bun-linux-x64-modern'
run: |
EXPECTED="$(node -p "require('./package.json').version")"
ACTUAL="$(./${{ matrix.asset }} --version)"
test "${ACTUAL}" = "${EXPECTED}"
- name: Upload to GitHub release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ inputs.tag || github.ref_name }}
# --clobber so a re-run replaces the file rather than failing.
# The release itself is created by release.yml (or the first
# uploader, whichever wins the race).
run: |
# Wait briefly for release.yml to create the release shell.
for i in 1 2 3 4 5 6; do
if gh release view "${TAG}" >/dev/null 2>&1; then
break
fi
echo "Waiting for release ${TAG} (attempt $i)…"
sleep 10
done
# If release.yml hasn't run yet (or failed), create the release ourselves.
if ! gh release view "${TAG}" >/dev/null 2>&1; then
PRERELEASE_FLAG=""
if [[ "${TAG}" == *-* ]]; then PRERELEASE_FLAG="--prerelease"; fi
gh release create "${TAG}" \
--title "${TAG}" \
--generate-notes \
${PRERELEASE_FLAG}
fi
gh release upload "${TAG}" "${{ matrix.asset }}" --clobber
# Native Windows smoke test. The build matrix above cross-compiles the
# Windows .exe on ubuntu, but a binary built that way can still die at
# runtime on real Windows (missing DLL, path resolution quirk, console-
# vs-console-host differences). This job builds + invokes the .exe on
# an actual windows-latest runner so obvious breakage gates the release.
windows-smoke:
name: Smoke-test Windows binary
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.tag || github.ref }}
- uses: oven-sh/setup-bun@v2
with:
bun-version: "1.3.14"
- uses: actions/setup-node@v4
with:
node-version: "20"
cache: npm
- name: Install
run: npm ci
- name: Stub ink devtools
shell: bash
run: |
cat > node_modules/ink/build/devtools.js <<'EOF'
export default { connectToDevTools() {} };
EOF
- name: Compile native Windows binary
shell: pwsh
run: |
$versionJson = node -p "JSON.stringify(require('./package.json').version)"
bun build --compile --target=bun-windows-x64 `
--define "CODEBASE_BUILD_VERSION=$versionJson" `
src/cli.tsx --outfile=codebase.exe
- name: Invoke --version and --help
# Both should exit 0 on a healthy binary. Asking for --help also
# exercises argv parsing + the early return path so we catch
# crashes in startup code (config loading, dotenv, etc.) without
# needing real credentials.
shell: pwsh
run: |
$expected = node -p "require('./package.json').version"
$actual = ./codebase.exe --version
if ($actual.Trim() -ne $expected.Trim()) {
throw "Version mismatch: expected $expected, got $actual"
}
./codebase.exe --help