Repository navigation
285 lines (256 loc) · 14.9 KB
/
Copy pathupdate-opencode-patched.yml
File metadata and controls
285 lines (256 loc) · 14.9 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
name: Update opencode-patched
on:
schedule:
# Every 8 hours (1h after opencode-patched's sync-cached schedule)
- cron: '0 2,10,18 * * *'
workflow_dispatch:
concurrency:
group: update-opencode-patched
cancel-in-progress: true
jobs:
update:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
# issues: write is load-bearing, not decoration. The divergence alarm
# below creates an issue, and an explicit permissions block sets every
# unlisted scope to `none` -- so without this the alarm 403s and a blocked
# auto-update stays exactly as silent as it would have been with no alarm
# at all. `bash -n` cannot catch that; only running it can.
issues: write
steps:
- name: Checkout repository
id: checkout
uses: actions/checkout@v4
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v14
- name: Check for new release
id: check
env:
GH_TOKEN: ${{ github.token }}
run: |
file="users/dev/home.base.nix"
# Current pinned identity from the nix file. home.base.nix derives
# releaseTag/version from these two vars, so they are the source of truth.
current_ver=$(grep 'upstreamVersion = ' "$file" | head -1 | sed 's/.*"\([^"]*\)".*/\1/')
current_rev=$(grep 'patchedRevision = ' "$file" | head -1 | sed 's/.*patchedRevision = "\([^"]*\)".*/\1/')
echo "current_ver=$current_ver" >> "$GITHUB_OUTPUT"
echo "current_rev=$current_rev" >> "$GITHUB_OUTPUT"
# Version hold (see `opencodePatchedHold` in home.base.nix). While
# non-empty, track the highest revision on the held upstream line instead
# of releases/latest, so an auto-bump can never carry us onto a new line
# (e.g. the 1.16 line whose v2 schema migration corrupts opencode.db).
# Empty = legacy behavior (track releases/latest faithfully).
hold=$(grep 'opencodePatchedHold = ' "$file" | head -1 | sed 's/.*"\([^"]*\)".*/\1/')
echo "hold=$hold" >> "$GITHUB_OUTPUT"
if [ -n "$hold" ]; then
# Highest "vX-patched.N" on the held line (sort by the numeric .N field;
# a base "vX-patched" with no .N sorts as 0, below any revision).
latest_tag=$(gh api repos/johnnymo87/opencode-patched/releases --paginate \
--jq ".[].tag_name | select(startswith(\"v${hold}-patched\"))" \
| sort -t. -k4 -n | tail -1)
if [ -z "$latest_tag" ]; then
echo "Held at ${hold}; no v${hold}-patched* release found. Nothing to do."
exit 0
fi
else
# Latest published release, tracked faithfully (base "vX-patched" or a
# manual "vX-patched.N" re-release -- whichever is marked latest). A
# missing release (upstream build failure) is the blocker.
latest_tag=$(gh api repos/johnnymo87/opencode-patched/releases/latest --jq '.tag_name')
fi
latest_ver=$(echo "$latest_tag" | sed 's/^v//;s/-patched.*//')
latest_rev=$(echo "$latest_tag" | sed -n 's/.*-patched\.\([0-9][0-9]*\)$/\1/p')
echo "latest_tag=$latest_tag" >> "$GITHUB_OUTPUT"
echo "latest_ver=$latest_ver" >> "$GITHUB_OUTPUT"
echo "latest_rev=$latest_rev" >> "$GITHUB_OUTPUT"
# Defense in depth: even if the selection above ever regressed, never
# bump off the held line.
if [ -n "$hold" ] && [ "$latest_ver" != "$hold" ]; then
echo "Held at ${hold}; refusing to bump to ${latest_ver}."
exit 0
fi
if [ "$current_ver" = "$latest_ver" ] && [ "$current_rev" = "$latest_rev" ]; then
echo "Identity unchanged (v${current_ver}-patched${current_rev:+.$current_rev}); will check for hash drift."
else
echo "Release bump: v${current_ver}-patched${current_rev:+.$current_rev} -> ${latest_tag}"
fi
- name: Compute hashes
id: hashes
run: |
base="https://github.com/johnnymo87/opencode-patched/releases/download/${{ steps.check.outputs.latest_tag }}"
for asset in opencode-linux-arm64.tar.gz opencode-darwin-arm64.zip opencode-linux-x64.tar.gz opencode-darwin-x64.zip; do
hash=$(nix-prefetch-url "${base}/${asset}" 2>/dev/null)
sri=$(nix hash convert --hash-algo sha256 --to sri "$hash")
# Convert asset name to output key: opencode-linux-arm64.tar.gz -> linux_arm64
key=$(echo "$asset" | sed 's/opencode-//;s/\.tar\.gz//;s/\.zip//;s/-/_/')
echo "${key}=${sri}" >> "$GITHUB_OUTPUT"
echo "$asset -> $sri"
done
# Cross-repo half of the loader-patch pin. The other half
# (users/dev/test-loader-pin.sh) recomposes and hashes the VENDORED copy
# offline in the flake-check sandbox; it cannot see the fork. This step
# can, and this is the moment that matters: the vendored copy's job is to
# describe the loader we DEPLOY, and a bump is when what we deploy changes.
#
# Fail-closed on divergence. Blocking the auto-PR leaves production on the
# release whose loader the fixtures actually describe, which is the safe
# side -- but it also means the auto-update pipeline is now silently dead,
# so a divergence opens an issue rather than only reddening a run nobody
# is watching.
- name: Verify vendored loader patch matches the fork
id: patchcheck
env:
GH_TOKEN: ${{ github.token }}
run: |
tag="${{ steps.check.outputs.latest_tag }}"
vendored="assets/opencode/plugins/test/fixtures/plugin-loader-observability.patch"
url="https://raw.githubusercontent.com/johnnymo87/opencode-patched/${tag}/patches/plugin-loader-observability.patch"
if [ ! -f "$vendored" ]; then
echo "::error::vendored loader patch missing at $vendored -- the pin is dead, not merely stale."
exit 1
fi
# -f so a 404 is an ERROR, not a "Not Found" body silently diffed as
# divergence. The patch legitimately does not exist on releases older
# than v1.17.13-patched.8, and misreporting that as drift would send
# the next reader hunting a loader change that never happened.
# --retry so a transient raw.githubusercontent.com blip is not reported as
# drift. This step runs on every 8-hourly cron, including no-op ones, so
# an un-retried fetch would manufacture false "diverged" alarms.
if ! curl -sfL --retry 3 --retry-all-errors --retry-delay 2 "$url" -o /tmp/fork-loader.patch; then
echo "::error::could not fetch the loader patch from ${tag} after retries."
echo "If ${tag} predates v1.17.13-patched.8 the patch genuinely is not there, and bumping"
echo "onto it would deploy a loader with NO failure logging while the fixtures claim otherwise."
echo "Otherwise this is a network/availability failure and the next cron will retry."
echo "reason=unreachable" >> "$GITHUB_OUTPUT"
exit 1
fi
if ! diff -u "$vendored" /tmp/fork-loader.patch; then
echo "::error::the fork's loader patch at ${tag} differs from the vendored copy."
echo "reason=diverged" >> "$GITHUB_OUTPUT"
exit 1
fi
echo "vendored loader patch matches ${tag}"
- name: Update home.base.nix
run: |
file="users/dev/home.base.nix"
# Update the version identity. releaseTag/version in home.base.nix are
# derived from these two vars, so we only rewrite upstreamVersion and
# patchedRevision (latest_rev is "" for base releases, "N" for .N).
sed -i "s/upstreamVersion = \"[^\"]*\"/upstreamVersion = \"${{ steps.check.outputs.latest_ver }}\"/" "$file"
sed -i "s/\(patchedRevision = \)\"[^\"]*\"/\1\"${{ steps.check.outputs.latest_rev }}\"/" "$file"
# Update hashes - match the line containing each asset name and replace the hash on that line
sed -i '/opencode-linux-arm64\.tar\.gz/,/hash =/{s|hash = "sha256-[^"]*"|hash = "${{ steps.hashes.outputs.linux_arm64 }}"|;}' "$file"
sed -i '/opencode-darwin-arm64\.zip/,/hash =/{s|hash = "sha256-[^"]*"|hash = "${{ steps.hashes.outputs.darwin_arm64 }}"|;}' "$file"
sed -i '/opencode-linux-x64\.tar\.gz/,/hash =/{s|hash = "sha256-[^"]*"|hash = "${{ steps.hashes.outputs.linux_x64 }}"|;}' "$file"
sed -i '/opencode-darwin-x64\.zip/,/hash =/{s|hash = "sha256-[^"]*"|hash = "${{ steps.hashes.outputs.darwin_x64 }}"|;}' "$file"
echo "Updated $file to ${{ steps.check.outputs.latest_tag }}"
git diff "$file"
- name: Create PR
env:
GH_TOKEN: ${{ secrets.UPDATE_TOKEN }}
run: |
file="users/dev/home.base.nix"
if git diff --quiet "$file"; then
echo "No drift in $file; nothing to PR."
exit 0
fi
version="${{ steps.check.outputs.latest_ver }}"
tag="${{ steps.check.outputs.latest_tag }}"
branch="auto/update-opencode-patched"
git checkout -B "$branch"
git add -A
git -c user.name="github-actions[bot]" \
-c user.email="41898282+github-actions[bot]@users.noreply.github.com" \
commit -m "chore(deps): update opencode-patched to ${version}"
git push -u origin "$branch" --force
# gh pr view matches merged/closed PRs too -- only skip if truly open
pr_state=$(gh pr view "$branch" --json state -q '.state' 2>/dev/null || echo "NONE")
if [ "$pr_state" = "OPEN" ]; then
echo "PR already open for $branch, force-pushed update"
else
pr_url=$(gh pr create \
--title "chore(deps): update opencode-patched to ${version}" \
--body "Automated update of \`opencode-patched\` to \`${tag}\` (caching + vim)." \
--label "dependencies,automated" \
--head "$branch")
pr_number=$(gh pr view "$branch" --json number -q '.number')
gh pr merge "$pr_number" --auto --squash
fi
# A blocked auto-update is invisible: the pipeline simply stops opening
# PRs and the fleet quietly stays where it is. Surface it as an issue so
# the silence has a voice. Deduped by title so an 8-hourly cron cannot
# manufacture an issue storm.
- name: Surface a blocked loader-patch pin
# Only on ACTUAL divergence. An unreachable-fetch run self-heals on the
# next cron, and raising "diverged" for it would misattribute a blip as a
# loader change -- sending the reader hunting something that never happened.
if: failure() && steps.patchcheck.outputs.reason == 'diverged'
env:
GH_TOKEN: ${{ github.token }}
run: |
tag="${{ steps.check.outputs.latest_tag }}"
title="opencode-patched auto-update blocked: loader patch diverged at ${tag}"
if gh issue list --state open --search "\"$title\" in:title" --json title \
-q '.[].title' | grep -qxF "$title"; then
echo "issue already open; not duplicating"
exit 0
fi
{
echo "The \`update-opencode-patched\` workflow refused to open its auto-bump PR."
echo
echo "\`assets/opencode/plugins/test/fixtures/plugin-loader-observability.patch\`"
echo "no longer matches the copy in \`johnnymo87/opencode-patched\` at the release"
echo "being bumped to (\`${tag}\`) -- or could not be fetched from it at all."
echo
echo "**Nothing is broken in production.** The fleet stays on the release whose"
echo "loader the vendored fixtures actually describe. But opencode auto-updates are"
echo "now STOPPED until this is resolved, and that is the failure this issue exists"
echo "to make audible."
echo
echo "Why it is fail-closed: that patch is the only reason plugin load failures are"
echo "visible at all. Upstream logs nothing at the four \`report.error\` stages or at"
echo "\`report.missing\`. Bumping onto a release whose loader patch we have not read"
echo "would deploy a loader the production canary's greps may no longer match --"
echo "which fails green."
echo
echo "To resolve -- and note the local guard is GREEN right now, because the"
echo "vendored copy is self-consistent; it is only stale relative to \`${tag}\`, so"
echo "it will not print a recipe. Run these, from the repo root:"
echo
echo '```bash'
echo "F=assets/opencode/plugins/test/fixtures"
echo "curl -sfL https://raw.githubusercontent.com/johnnymo87/opencode-patched/${tag}/patches/plugin-loader-observability.patch \\"
echo " -o \"\$F/plugin-loader-observability.patch\""
echo
echo "# READ THE DIFF before regenerating anything -- what changed in the loader"
echo "# patch is the whole question this issue is asking."
echo "git diff -- \"\$F/plugin-loader-observability.patch\""
echo
echo "# Recompose the patched loader fixture from pristine upstream + the new patch:"
echo "s=\$(mktemp -d); mkdir -p \"\$s/packages/opencode/src/plugin\""
echo "cp \"\$F/plugin-index.ts\" \"\$s/packages/opencode/src/plugin/index.ts\""
echo "(cd \"\$s\" && patch -p1 --silent < \"\$OLDPWD/\$F/plugin-loader-observability.patch\")"
echo "cp \"\$s/packages/opencode/src/plugin/index.ts\" \"\$F/plugin-index.patched.ts\"; rm -rf \"\$s\""
echo
echo "sha256sum \"\$F/plugin-loader-observability.patch\" # -> LOADER_PATCH_SHA256 marker"
echo '```'
echo
echo "Then paste that sha into the \`LOADER_PATCH_SHA256\` marker in"
echo "\`pkgs/opencode-plugin-canary-sh/opencode-plugin-canary.sh\`, confirm the greps"
echo "at :50/:97/:100 still match the reworded patch, and run"
echo "\`nix build .#checks.aarch64-linux.loader-pin\`."
echo
echo "See \`docs/plans/2026-08-04-step3-loader-patch-design.md\`, \"Pin machinery\"."
} > /tmp/issue-body.md
gh issue create --title "$title" --label "automated" --body-file /tmp/issue-body.md
- name: Report workflow status
if: always() && steps.checkout.outcome == 'success' && steps.patchcheck.outputs.reason != 'diverged' && steps.patchcheck.outputs.reason != 'unreachable'
env:
GH_TOKEN: ${{ github.token }}
run: |
python3 .github/scripts/report-workflow-failure.py \
--workflow "${{ github.workflow }}" \
--status "${{ job.status }}" \
--run-url "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"