-
Notifications
You must be signed in to change notification settings - Fork 460
332 lines (289 loc) · 10.5 KB
/
cli-release-build.yml
File metadata and controls
332 lines (289 loc) · 10.5 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
name: Build CLI Binary
on:
workflow_call:
inputs:
binary-name:
required: true
type: string
description: 'Name of the CLI binary to build'
new-version:
required: true
type: string
description: 'Version string for the build'
artifact-name:
required: false
type: string
description: 'Optional artifact containing staging metadata'
default: ''
checkout-ref:
required: false
type: string
description: 'Git ref to checkout'
default: ''
env-overrides:
required: false
type: string
description: 'JSON object of environment variable overrides'
default: '{}'
jobs:
build-binaries:
strategy:
matrix:
include:
- os: ubuntu-latest
target: linux-x64
bun_target: bun-linux-x64
platform: linux
arch: x64
- os: ubuntu-latest
target: linux-arm64
bun_target: bun-linux-arm64
platform: linux
arch: arm64
# Cross-compiles on x64 runner; binary can't be executed here.
smoke_test: false
- os: macos-15-intel
target: darwin-x64
bun_target: bun-darwin-x64
platform: darwin
arch: x64
- os: macos-14
target: darwin-arm64
bun_target: bun-darwin-arm64
platform: darwin
arch: arm64
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.checkout-ref || github.sha }}
- uses: ./.github/actions/setup-project
- name: Download staging metadata
if: inputs.artifact-name != ''
uses: actions/download-artifact@v4
with:
name: ${{ inputs.artifact-name }}
path: cli/release-staging/
- name: Ensure CLI dependencies
run: bun install --frozen-lockfile --cwd cli
- name: Fix OpenTUI module symlinks
shell: bash
run: |
set -euo pipefail
bun - <<'BUN'
import fs from 'fs';
import path from 'path';
const rootDir = process.cwd();
const rootOpenTui = path.join(rootDir, 'node_modules', '@opentui');
const cliNodeModules = path.join(rootDir, 'cli', 'node_modules');
const cliOpenTui = path.join(cliNodeModules, '@opentui');
if (!fs.existsSync(rootOpenTui)) {
console.log('Root @opentui packages missing; skipping fix');
process.exit(0);
}
fs.mkdirSync(cliOpenTui, { recursive: true });
const packages = ['core', 'react'];
for (const pkg of packages) {
const target = path.join(rootOpenTui, pkg);
const link = path.join(cliOpenTui, pkg);
if (!fs.existsSync(target)) {
console.log(`Target ${target} missing; skipping ${pkg}`);
continue;
}
let linkStats = null;
try {
linkStats = fs.lstatSync(link);
} catch (error) {
if (error?.code !== 'ENOENT') {
throw error;
}
}
if (linkStats) {
let alreadyLinked = false;
try {
const actual = fs.realpathSync(link);
alreadyLinked = actual === target;
} catch {
// Broken symlink or unreadable target; we'll replace it.
}
if (alreadyLinked) {
continue;
}
fs.rmSync(link, { recursive: true, force: true });
}
const type = process.platform === 'win32' ? 'junction' : 'dir';
try {
fs.symlinkSync(target, link, type);
console.log(`Linked ${link} -> ${target}`);
} catch (error) {
if (error?.code === 'EEXIST') {
fs.rmSync(link, { recursive: true, force: true });
fs.symlinkSync(target, link, type);
console.log(`Re-linked ${link} -> ${target}`);
} else {
throw error;
}
}
}
BUN
- name: Configure environment variables
env:
SECRETS_CONTEXT: ${{ toJSON(secrets) }}
ENV_OVERRIDES: ${{ inputs.env-overrides }}
shell: bash
run: |
VAR_NAMES=$(bun scripts/generate-ci-env.ts --scope client)
echo "$SECRETS_CONTEXT" | jq -r --argjson vars "$VAR_NAMES" '
to_entries | .[] | select(.key as $k | $vars | index($k)) | .key + "=" + .value
' >> $GITHUB_ENV
echo "CODEBUFF_GITHUB_ACTIONS=true" >> $GITHUB_ENV
echo "CODEBUFF_GITHUB_TOKEN=${{ secrets.CODEBUFF_GITHUB_TOKEN }}" >> $GITHUB_ENV
if [ "$ENV_OVERRIDES" != "{}" ]; then
echo "$ENV_OVERRIDES" | jq -r 'to_entries | .[] | .key + "=" + .value' >> $GITHUB_ENV
fi
- name: Build binary
run: bun run scripts/build-binary.ts ${{ inputs.binary-name }} ${{ inputs.new-version }}
working-directory: cli
shell: bash
env:
VERBOSE: true
OVERRIDE_TARGET: ${{ matrix.bun_target }}
OVERRIDE_PLATFORM: ${{ matrix.platform }}
OVERRIDE_ARCH: ${{ matrix.arch }}
- name: Smoke test binary
if: matrix.smoke_test != false
shell: bash
run: |
cd cli/bin
if [[ "${{ runner.os }}" == "Windows" ]]; then
./${{ inputs.binary-name }}.exe --version
else
./${{ inputs.binary-name }} --version
fi
- name: Create tarball
shell: bash
run: |
BINARY_FILE="${{ inputs.binary-name }}"
if [[ "${{ runner.os }}" == "Windows" ]]; then
BINARY_FILE="${{ inputs.binary-name }}.exe"
fi
tar -czf ${{ inputs.binary-name }}-${{ matrix.target }}.tar.gz -C cli/bin "$BINARY_FILE"
- name: Upload binary artifact
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.binary-name }}-${{ matrix.target }}
path: ${{ inputs.binary-name }}-${{ matrix.target }}.tar.gz
build-windows-binary:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.checkout-ref || github.sha }}
- uses: ./.github/actions/setup-project
- name: Download staging metadata
if: inputs.artifact-name != ''
uses: actions/download-artifact@v4
with:
name: ${{ inputs.artifact-name }}
path: cli/release-staging/
- name: Ensure CLI dependencies
run: bun install --frozen-lockfile --cwd cli
- name: Fix OpenTUI module symlinks
shell: bash
run: |
set -euo pipefail
bun - <<'BUN'
import fs from 'fs';
import path from 'path';
const rootDir = process.cwd();
const rootOpenTui = path.join(rootDir, 'node_modules', '@opentui');
const cliNodeModules = path.join(rootDir, 'cli', 'node_modules');
const cliOpenTui = path.join(cliNodeModules, '@opentui');
if (!fs.existsSync(rootOpenTui)) {
console.log('Root @opentui packages missing; skipping fix');
process.exit(0);
}
fs.mkdirSync(cliOpenTui, { recursive: true });
const packages = ['core', 'react'];
for (const pkg of packages) {
const target = path.join(rootOpenTui, pkg);
const link = path.join(cliOpenTui, pkg);
if (!fs.existsSync(target)) {
console.log(`Target ${target} missing; skipping ${pkg}`);
continue;
}
let linkStats = null;
try {
linkStats = fs.lstatSync(link);
} catch (error) {
if (error?.code !== 'ENOENT') {
throw error;
}
}
if (linkStats) {
let alreadyLinked = false;
try {
const actual = fs.realpathSync(link);
alreadyLinked = actual === target;
} catch {
// Broken symlink or unreadable target; we'll replace it.
}
if (alreadyLinked) {
continue;
}
fs.rmSync(link, { recursive: true, force: true });
}
const type = process.platform === 'win32' ? 'junction' : 'dir';
try {
fs.symlinkSync(target, link, type);
console.log(`Linked ${link} -> ${target}`);
} catch (error) {
if (error?.code === 'EEXIST') {
fs.rmSync(link, { recursive: true, force: true });
fs.symlinkSync(target, link, type);
console.log(`Re-linked ${link} -> ${target}`);
} else {
throw error;
}
}
}
BUN
- name: Configure environment variables
env:
SECRETS_CONTEXT: ${{ toJSON(secrets) }}
ENV_OVERRIDES: ${{ inputs.env-overrides }}
shell: bash
run: |
VAR_NAMES=$(bun scripts/generate-ci-env.ts --scope client)
echo "$SECRETS_CONTEXT" | jq -r --argjson vars "$VAR_NAMES" '
to_entries | .[] | select(.key as $k | $vars | index($k)) | .key + "=" + .value
' >> $GITHUB_ENV
echo "CODEBUFF_GITHUB_ACTIONS=true" >> $GITHUB_ENV
echo "CODEBUFF_GITHUB_TOKEN=${{ secrets.CODEBUFF_GITHUB_TOKEN }}" >> $GITHUB_ENV
if [ "$ENV_OVERRIDES" != "{}" ]; then
echo "$ENV_OVERRIDES" | jq -r 'to_entries | .[] | .key + "=" + .value' >> $GITHUB_ENV
fi
- name: Build binary
run: bun run scripts/build-binary.ts ${{ inputs.binary-name }} ${{ inputs.new-version }}
working-directory: cli
shell: bash
env:
VERBOSE: true
OVERRIDE_TARGET: bun-windows-x64
OVERRIDE_PLATFORM: win32
OVERRIDE_ARCH: x64
- name: Smoke test binary
shell: bash
run: |
cd cli/bin
./${{ inputs.binary-name }}.exe --version
- name: Create tarball
shell: bash
run: |
BINARY_FILE="${{ inputs.binary-name }}.exe"
tar -czf ${{ inputs.binary-name }}-win32-x64.tar.gz -C cli/bin "$BINARY_FILE"
- name: Upload binary artifact
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.binary-name }}-win32-x64
path: ${{ inputs.binary-name }}-win32-x64.tar.gz