设置页一键更新:不用 git、不用 GitHub #2
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "self-update"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
之前:住户要更新,只能有 git 或 GitHub,在电脑上拉代码再部署。没电脑、不会 git 的人更新不了。
之后:设置页最下面多了一行「更新」。有新版本时点一下就换上,聊天记录、设置、Secret 都不动。第一次要放一把 Cloudflare 钥匙:按钮直接打开 Cloudflare 建令牌的页面,权限已经勾好,只有 Workers Scripts: Edit,点「创建」再复制回来就行。
怎么做到的
CF_VERSION绑定,它不需要建任何资源。钥匙看不到自己就不存,不会去改别的 Worker。keep_bindings,变量和 Secret 都保留。scripts/release.mjs对着本机一个假的 Cloudflare API 跑一遍wrangler deploy,原样留下 wrangler 要上传的东西,然后签名、发布。用法见docs/releasing.md。测过的
npm run typecheck通过。test/self-update.mjs12 项,对着假的 git.dan9.si 和假的 Cloudflare:test/web-ui.mjs加了更新卡片的一组,其余单元测试和 main 上一样。alarm-activity、cache-history、letter-recovery-budget、startup-recovery四个在 main 上就编译不过,跟这次无关。aelios-resident-selftest,发布地址指向一个临时公开仓库。WEB_KEY和一个普通变量都还在,迁移标签还是 v3,页面和源码逐字节一致。aelios-resident。合了以后
node scripts/release.mjs --tag v1.0.0 --publish。🤖 Generated with Claude Code
The settings page gets an Update row. With a Cloudflare token (one tap opens Cloudflare's token page with only Workers Scripts: Edit ticked), the resident downloads the newest release from git.dan9.si, checks its Ed25519 signature and SHA-256, and redeploys itself the way wrangler does: static files through an upload session (only the ones Cloudflare lacks), the Durable Object migrations the live script has not had, and the script with keep_bindings so variables and secrets stay. It never installs an older release. - src/self-update.ts: release reading and checks, finding this Worker by its live version id (new CF_VERSION version_metadata binding) so a token can never point it at another Worker, the install, and the stored state. The work runs in the first resident's Durable Object, which gets 30 s of CPU where a free-plan Worker gets 10 ms. - /web/update{,/connect,/start,/forget}, web door key only. - scripts/release.mjs: runs `wrangler deploy` against a local stand-in for the Cloudflare API, keeps exactly what wrangler would upload, signs it and with --publish puts it on the releases page. docs/releasing.md says how. - RESIDENT_UPSTREAM_URL can point at another releases page; signatures are still required. - Tests: test/self-update.mjs (12, fake forge and Cloudflare) and the update card in test/web-ui.mjs. Also run end to end on a throwaway Worker in a real account: v0.0.1 installed over a source deploy, then v0.0.2 with no files to upload; WEB_KEY and a plain var survived, migration tag stayed v3. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>