Repository navigation
423 lines (398 loc) · 19.5 KB
/
Copy pathopencode.yml
File metadata and controls
423 lines (398 loc) · 19.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
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
name: opencode
run-name: opencode ${{ inputs.channel }}${{ inputs.upstream_ref && format(' @ {0}', inputs.upstream_ref) || '' }}${{ inputs.draft && ' (draft)' || '' }}
# One workflow for every channel and both modes:
# channel=auto detect what's new upstream and build each pending line
# in one run (intended trigger: a poller, or a manual run)
# channel=X force one line (stable/beta/dev); `upstream_ref`/`version`
# pick the tree; rolling tags are replaced, stable tags
# never are.
#
# Each leg checks out the branch carrying its patch kit:
# stable -> main (vX.Y.Z) beta -> beta (vX.Y.Z-beta.<sha>)
# dev -> dev (vX.Y.Z-dev.<sha>)
# Keep this file byte-identical on all three branches.
on:
workflow_dispatch:
inputs:
channel:
description: "auto = scan all lines; or force one"
type: choice
options: [auto, stable, beta, dev]
default: auto
upstream_ref:
description: "With channel!=auto: upstream branch/sha/tag to build (default: the channel's branch head)"
required: false
default: ""
version:
description: "Force the published version (hotfix re-ships; blank = derive)"
required: false
default: ""
prerelease:
description: "Only honored with an explicit version on stable"
type: boolean
default: false
draft:
description: "Create releases as drafts"
type: boolean
default: false
dry_run:
description: "Report the plan, build nothing, commit nothing"
type: boolean
default: false
concurrency:
group: opencode
cancel-in-progress: false
env:
UPSTREAM: anomalyco/opencode
OURS: ${{ github.repository }}
jobs:
detect:
runs-on: ubuntu-24.04
permissions:
contents: write
timeout-minutes: 10
outputs:
legs: ${{ steps.plan.outputs.legs }}
count: ${{ steps.plan.outputs.count }}
steps:
- uses: actions/checkout@v5
- uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Sync stability of existing releases
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -eu
gh release list --repo "$OURS" -L 20 \
--json tagName,isPrerelease,isDraft --jq '.[]' > "$RUNNER_TEMP/ours.jsonl" || true
flipped=0
while IFS= read -r row; do
tag="$(echo "$row" | jq -r .tagName)"
our_pre="$(echo "$row" | jq -r .isPrerelease)"
[ "$(echo "$row" | jq -r .isDraft)" = "true" ] && continue
up_pre="$(gh release view "$tag" --repo "$UPSTREAM" --json isPrerelease --jq .isPrerelease 2>/dev/null || true)"
[ -z "$up_pre" ] && continue
if [ "$our_pre" != "$up_pre" ]; then
echo " $tag: ours=$our_pre upstream=$up_pre -> flipping"
gh release edit "$tag" --repo "$OURS" --prerelease="$up_pre"
flipped=$((flipped + 1))
fi
done < "$RUNNER_TEMP/ours.jsonl"
echo "flipped $flipped release(s) to match upstream stability"
- name: Plan release legs
id: plan
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CHANNEL: ${{ inputs.channel }}
REF_IN: ${{ inputs.upstream_ref }}
VERSION_IN: ${{ inputs.version }}
PRE_IN: ${{ inputs.prerelease }}
DRAFT_IN: ${{ inputs.draft }}
DRY: ${{ inputs.dry_run }}
run: |
set -euo pipefail
LEGS="$RUNNER_TEMP/legs"; rm -rf "$LEGS"; mkdir -p "$LEGS"
[ "$DRAFT_IN" = "true" ] && DRAFT_JSON=true || DRAFT_JSON=false
add_leg() { # channel kit upstream_ref version prerelease
jq -cn --arg c "$1" --arg k "$2" --arg r "$3" --arg v "$4" --arg p "$5" \
--argjson d "$DRAFT_JSON" \
'{channel:$c, kit:$k, upstream_ref:$r, version:$v, prerelease:($p=="true"), draft:$d}' \
> "$LEGS/$1.json"
echo "leg: $1 (kit=$2 upstream_ref=${3:-versions.json} version=${4:-auto} prerelease=$5)"
}
probe_version() { # sha -> version at that commit, or empty.
# Upstream moved the version from packages/opencode to root
# package.json after 1.x; probe both and never emit empty.
local v
v="$(gh api "repos/$UPSTREAM/contents/package.json?ref=$1" \
--jq .content 2>/dev/null | base64 -d 2>/dev/null | jq -r .version 2>/dev/null || true)"
if [ -z "$v" ] || [ "$v" = "null" ]; then
v="$(gh api "repos/$UPSTREAM/contents/packages/opencode/package.json?ref=$1" \
--jq .content 2>/dev/null | base64 -d 2>/dev/null | jq -r .version 2>/dev/null || true)"
fi
{ [ -n "$v" ] && [ "$v" != "null" ]; } && printf '%s' "$v" || true
}
head_is_release() { # sha -> release tag it sits on, or empty
local rt rs
rt="$(gh release list --repo "$UPSTREAM" --exclude-drafts -L 20 \
--json tagName --jq '[.[]|select(.tagName|test("^v[0-9]+\\.[0-9]+\\.[0-9]+$"))] | .[0].tagName // empty')"
[ -n "$rt" ] || return 0
rs="$(gh api "repos/$UPSTREAM/commits/$rt" --jq .sha 2>/dev/null || true)"
[ "$rs" = "$1" ] && printf '%s' "$rt" || true
}
if [ "$CHANNEL" != "auto" ]; then
# Forced single line.
if [ "$CHANNEL" = "stable" ] && [ -z "$REF_IN" ] && [ -z "$VERSION_IN" ]; then
echo "channel=stable without ref/version: use auto for the stable bump" >&2; exit 1
fi
SHA=""; VER="$VERSION_IN"; PRE="$PRE_IN"
if [ "$CHANNEL" != "stable" ]; then
REF="${REF_IN:-$CHANNEL}" # default: the channel's own branch
SHA="$(gh api "repos/$UPSTREAM/commits/$REF" --jq .sha)"
elif [ -n "$REF_IN" ]; then
SHA="$(gh api "repos/$UPSTREAM/commits/$REF_IN" --jq .sha)"
fi
if [ -z "$VER" ] && [ -n "$SHA" ]; then
VER="$(probe_version "$SHA")"
[ -n "$VER" ] || { echo "error: cannot determine version at $SHA" >&2; exit 1; }
fi
[ "$CHANNEL" = "stable" ] || { [ -n "$VERSION_IN" ] || PRE=true; }
KIT="$CHANNEL"; [ "$CHANNEL" = "stable" ] && KIT="main"
# Rolling lines must leave version empty: the build job derives
# `<ver>-<channel>.<sha8>` from the ref. A leaked probe version
# would tag a bare vX.Y.Z prerelease instead (§ tags scheme).
[ "$CHANNEL" = "stable" ] || VER="$VERSION_IN"
add_leg "$CHANNEL" "$KIT" "$SHA" "$VER" "$PRE"
else
# --- stable: newest semver release we don't mirror yet ----------
row="$(gh release list --repo "$UPSTREAM" --exclude-drafts -L 20 \
--json tagName,isPrerelease \
--jq '[.[]|select(.tagName|test("^v[0-9]+\\.[0-9]+\\.[0-9]+$"))] | .[0]')"
[ "$row" != "null" ] && [ -n "$row" ] || { echo "::error::no semver release on $UPSTREAM" >&2; exit 1; }
LATEST_TAG="$(echo "$row" | jq -r .tagName)"
LATEST="${LATEST_TAG#v}"
UP_PRE="$(echo "$row" | jq -r .isPrerelease)"
CUR="$(jq -r .opencode versions.json)"
if gh release view "$LATEST_TAG" --repo "$OURS" >/dev/null 2>&1; then
[ "$CUR" = "$LATEST" ] || echo "pin lags upstream ($CUR -> $LATEST) though the release exists; leaving it"
echo "stable $LATEST_TAG already mirrored"
else
if [ "${GITHUB_REF:-}" != "refs/heads/main" ]; then
echo "::warning::auto must run from main (stable bump commits there); stable skipped"
else
# Bump the pin in-memory so the preflight clones the new tree,
# and commit it only if the kit still applies.
jq --arg v "$LATEST" '.opencode=$v' versions.json > "$RUNNER_TEMP/vj" && mv "$RUNNER_TEMP/vj" versions.json
bun termux/ci/versions.ts apply >/dev/null
bun termux/ci/versions.ts check >/dev/null
if [ "$DRY" != "true" ] && bash termux/ci/prepare-build-tree.sh "$RUNNER_TEMP/preflight-$LATEST" >/dev/null 2>&1; then
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add versions.json README.md
if ! git diff --cached --quiet; then
git commit -q -m "chore(upstream): bump opencode $CUR -> $LATEST" \
-m "Auto-bumped by opencode.yml from $UPSTREAM."
git push -q origin HEAD:main
fi
add_leg stable main "" "$LATEST" "$UP_PRE"
elif [ "$DRY" = "true" ]; then
add_leg stable main "" "$LATEST" "$UP_PRE"
else
echo "::error::patches do not apply to upstream $LATEST_TAG — stable skipped; fix the kit on main"
git checkout -q -- versions.json README.md
fi
fi
fi
# --- rolling lines ----------------------------------------------
for line in dev beta; do
sha="$(gh api "repos/$UPSTREAM/commits/$line" --jq .sha)"
short="${sha:0:8}"
ver="$(probe_version "$sha")"
if [ -z "$ver" ]; then echo "no version at $line/$short — skipping"; continue; fi
tag="v${ver}-${line}.${short}"
if gh release view "$tag" --repo "$OURS" >/dev/null 2>&1; then
echo "$line: $tag already released"; continue
fi
# One build per upstream version: if any release for this
# version already exists on this line, later commits carrying
# the same package version are skipped until upstream bumps.
shipped="$(gh api "repos/$OURS/releases?per_page=100" --paginate \
--jq "[.[]|select((.tag_name|startswith(\"v${ver}-${line}.\")) and (.draft|not))][0].tag_name // empty" | head -1 || true)"
if [ -n "$shipped" ]; then
echo "$line: $ver already shipping as $shipped — skipping until upstream bumps"; continue
fi
if [ -n "$(head_is_release "$sha")" ]; then
echo "$line head is a release tag — stable path covers it"; continue
fi
add_leg "$line" "$line" "$sha" "" true
done
fi
if [ "$DRY" = "true" ]; then
echo "dry run: legs below, building nothing"
cat "$LEGS"/*.json 2>/dev/null || echo "(none)"
echo "legs=[]" >> "$GITHUB_OUTPUT"; echo "count=0" >> "$GITHUB_OUTPUT"
elif compgen -G "$LEGS/*.json" > /dev/null; then
LEGS_JSON="$(jq -s -c . "$LEGS"/*.json)"
echo "legs=$LEGS_JSON" >> "$GITHUB_OUTPUT"
echo "count=$(echo "$LEGS_JSON" | jq length)" >> "$GITHUB_OUTPUT"
else
echo "legs=[]" >> "$GITHUB_OUTPUT"; echo "count=0" >> "$GITHUB_OUTPUT"
echo "nothing new upstream"
fi
build:
needs: detect
if: needs.detect.outputs.count != '0'
runs-on: ubuntu-24.04-arm
permissions:
actions: write
contents: write
timeout-minutes: 45
strategy:
fail-fast: false
matrix:
leg: ${{ fromJson(needs.detect.outputs.legs) }}
name: ${{ matrix.leg.channel }}
env:
CHANNEL: ${{ matrix.leg.channel }}
steps:
- name: Checkout kit branch
uses: actions/checkout@v5
with:
ref: ${{ matrix.leg.kit }}
- uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Resolve version
id: version
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
INPUT_VERSION: ${{ matrix.leg.version }}
INPUT_UPSTREAM_REF: ${{ matrix.leg.upstream_ref }}
INPUT_PRERELEASE: ${{ matrix.leg.prerelease }}
run: |
set -eu
PRERELEASE="$INPUT_PRERELEASE"
if [ -n "$INPUT_UPSTREAM_REF" ]; then
SHA="$INPUT_UPSTREAM_REF"
SHORT="${SHA:0:8}"
VERSION="$(gh api "repos/$UPSTREAM/contents/package.json?ref=$SHA" \
--jq .content 2>/dev/null | base64 -d 2>/dev/null | jq -r .version 2>/dev/null || true)"
if [ -z "$VERSION" ] || [ "$VERSION" = "null" ]; then
VERSION="$(gh api "repos/$UPSTREAM/contents/packages/opencode/package.json?ref=$SHA" \
--jq .content 2>/dev/null | base64 -d 2>/dev/null | jq -r .version 2>/dev/null || true)"
fi
if [ -z "$VERSION" ] || [ "$VERSION" = "null" ]; then
echo "error: no version resolvable at $SHA" >&2; exit 1
fi
if [ -n "$INPUT_VERSION" ]; then
RELEASE="${INPUT_VERSION#v}"
else
RELEASE="${VERSION}-${CHANNEL}.${SHORT}"
PRERELEASE=true
fi
echo "ref=$SHA" >> "$GITHUB_OUTPUT"
else
if [ "$CHANNEL" != "stable" ]; then
echo "error: channel=$CHANNEL requires an upstream_ref leg" >&2; exit 1
fi
VERSION="${INPUT_VERSION#v}"
[ -n "$VERSION" ] || VERSION="$(bun termux/ci/versions.ts print | grep '^OPENCODE_VERSION=' | cut -d= -f2)"
RELEASE="$VERSION"
echo "ref=" >> "$GITHUB_OUTPUT"
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "release=$RELEASE" >> "$GITHUB_OUTPUT"
echo "tag=v$RELEASE" >> "$GITHUB_OUTPUT"
echo "prerelease=$PRERELEASE" >> "$GITHUB_OUTPUT"
echo "channel=$CHANNEL" >> "$GITHUB_OUTPUT"
- name: Verify tag is usable
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ steps.version.outputs.tag }}
run: |
set -eu
if gh release view "$TAG" >/dev/null 2>&1; then
if [ "$CHANNEL" = "stable" ]; then
echo "error: stable release $TAG already exists." >&2; exit 1
fi
echo "replacing existing rolling release $TAG"
gh release delete "$TAG" --cleanup-tag --yes
fi
- name: Apply pinned versions
run: bun termux/ci/versions.ts apply
- name: Confirm versions match
run: bun termux/ci/versions.ts check
- name: Build inside termux-docker
env:
OPENCODE_VERSION: ${{ steps.version.outputs.release }}
OPENCODE_UPSTREAM_REF: ${{ steps.version.outputs.ref }}
OPENCODE_CHANNEL: ${{ steps.version.outputs.channel }}
run: bash termux/ci/build-on-runner.sh
- name: Package .deb
env:
VERSION: ${{ steps.version.outputs.release }}
run: |
set -eux
OUT_HOST="$(cd "$GITHUB_WORKSPACE/../out" && pwd)"
mkdir -p "$GITHUB_WORKSPACE/dist"
bash termux/ci/package-deb.sh "$OUT_HOST/opencode" "$VERSION" "$GITHUB_WORKSPACE/dist"
cp "$OUT_HOST/opencode" "$GITHUB_WORKSPACE/dist/opencode"
( cd "$GITHUB_WORKSPACE/dist" && sha256sum opencode "opencode_${VERSION}_aarch64.deb" > SHA256SUMS )
- name: Create GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ steps.version.outputs.tag }}
VERSION: ${{ steps.version.outputs.version }}
RELEASE: ${{ steps.version.outputs.release }}
REF: ${{ steps.version.outputs.ref }}
DRAFT: ${{ matrix.leg.draft }}
PRERELEASE: ${{ steps.version.outputs.prerelease }}
run: |
set -eu
FLAGS=""
[ "$DRAFT" = "true" ] && FLAGS="$FLAGS --draft"
[ "$PRERELEASE" = "true" ] && FLAGS="$FLAGS --prerelease"
NOTES="$RUNNER_TEMP/release-notes.md"
if [ -n "$REF" ]; then
SOURCE="Built from [\`$(printf '%s' "$REF" | cut -c1-8)\`](https://github.com/anomalyco/opencode/commit/$REF) — upstream reports itself as v$VERSION at that commit."
UP_DESC="$(gh api "repos/$UPSTREAM/commits/$REF" --jq '.commit.message // empty' 2>/dev/null || true)"
UP_TITLE="Upstream commit"
else
SOURCE="Built from upstream tag [\`v$VERSION\`](https://github.com/anomalyco/opencode/releases/tag/v$VERSION)."
UP_DESC="$(gh api "repos/$UPSTREAM/releases/tags/v$VERSION" --jq '.body // empty' 2>/dev/null || true)"
UP_TITLE="Upstream release notes"
fi
if [ "$PRERELEASE" = "true" ]; then
INSTALL_ENV="OPENCODE_VERSION=$RELEASE "
else
INSTALL_ENV=""
fi
{
printf 'opencode v%s — Termux/Bionic aarch64 build (%s channel).\n\n%s\n' "$RELEASE" "$CHANNEL" "$SOURCE"
printf '\n> **Channels:** [stable](https://github.com/%s/releases/latest) · [all prereleases (beta & dev)](https://github.com/%s/releases?q=prerelease%%3Atrue&expanded=true) · [tags](https://github.com/%s/tags) — install one-liners: https://github.com/%s#channels\n' "$GITHUB_REPOSITORY" "$GITHUB_REPOSITORY" "$GITHUB_REPOSITORY" "$GITHUB_REPOSITORY"
if [ -n "$UP_DESC" ]; then printf '\n## %s\n\n%s\n' "$UP_TITLE" "$UP_DESC"; fi
printf '\nInstall:\n\n```\ncurl -fsSL https://raw.githubusercontent.com/%s/main/install.sh | %sbash\n```\n\n' "$GITHUB_REPOSITORY" "$INSTALL_ENV"
printf 'Legacy: curl -LO https://github.com/%s/releases/download/%s/opencode_%s_aarch64.deb && dpkg -i opencode_%s_aarch64.deb\n\n' "$GITHUB_REPOSITORY" "$TAG" "$RELEASE" "$RELEASE"
printf 'Files:\n- opencode_%s_aarch64.deb — Termux package\n- opencode — raw aarch64 ELF binary\n- SHA256SUMS — checksums\n\nBundled versions:\n- opencode: v%s\n- @opentui/*: %s\n' "$RELEASE" "$VERSION" "$(bun termux/ci/versions.ts print | grep OPENTUI_CORE= | cut -d= -f2)"
} > "$NOTES"
TITLE="v$RELEASE"
[ "$CHANNEL" != "stable" ] && TITLE="$TITLE ($CHANNEL)"
# shellcheck disable=SC2086
gh release create "$TAG" $FLAGS \
--title "$TITLE" \
--notes-file "$NOTES" \
dist/opencode_${RELEASE}_aarch64.deb \
dist/opencode \
dist/SHA256SUMS
- name: Chain package-repo sync
if: ${{ matrix.leg.draft != true && github.event.inputs.dry_run != 'true' }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -eu
gh workflow run termux-repo.yml --ref main
echo "dispatched termux-repo.yml (apt repo + pages channel index)"
- name: Update rolling pin after build
if: ${{ matrix.leg.channel != 'stable' && github.event.inputs.dry_run != 'true' }}
env:
CHANNEL: ${{ steps.version.outputs.channel }}
PKGVER: ${{ steps.version.outputs.version }}
run: |
set -eu
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git fetch -q origin "$CHANNEL"
git reset -q --hard "origin/$CHANNEL"
CUR="$(jq -r .opencode versions.json)"
if [ "$CUR" != "$PKGVER" ]; then
jq --arg v "$PKGVER" '.opencode=$v' versions.json > "$RUNNER_TEMP/vj" && mv "$RUNNER_TEMP/vj" versions.json
fi
bun termux/ci/versions.ts apply >/dev/null
git add versions.json README.md
if git diff --cached --quiet; then
echo "pin and README already match $PKGVER"
exit 0
fi
git commit -q -m "chore(kit): rolling point -> opencode $PKGVER (built v${PKGVER}-${CHANNEL})"
git push -q origin "HEAD:$CHANNEL"