Skip to content

build(edgeone): generate cloud-functions artifact at deploy time - #93

Merged
PIKACHUIM merged 1 commit into
mainfrom
build/edgeone-artifact-generated-at-deploy
Sep 29, 2026
Merged

PIKACHUIM merged 1 commit into
mainfrom
build/edgeone-artifact-generated-at-deploy

Conversation

@PIKACHUIM

@PIKACHUIM PIKACHUIM commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

build(edgeone): generate the cloud-functions artifact during deploy instead of committing it

Base: main ← Compare: build/edgeone-artifact-generated-at-deploy
Commit: 1788357 · Files changed: 20 (+113 / −604)
Open PR: https://github.com/OpenListTeam/OpenList-Worker/pull/new/build/edgeone-artifact-generated-at-deploy

Summary / 摘要

cloud-functions/[[default]].js is a build artifact of scripts/build-edge.mjs: the
EdgeOne Makers Node cloud-function entry that bundles the whole backend plus the
inlined dist/index.html. It was previously required to be committed and kept in
sync with the sources, so every backend change forced a full rebuild and a ~1.8 MB
minified blob commit (each chore(edgeone): refresh cloud-functions artifact).
This PR makes it a pure build output.

cloud-functions/[[default]].js 是 scripts/build-edge.mjs 的构建产物:EdgeOne
Makers 的 Node 云函数入口,内含全部后端代码与内联的 dist/index.html。此前它必须
提交进仓库并与源码保持同步,于是每次后端改动都要重建并提交一个约 1.8 MB 的压缩
产物(历史上那些 chore(edgeone): refresh cloud-functions artifact 提交)。本 PR
把它彻底变成构建产物。

Rationale / 理由: EdgeOne's one-click deploy already builds at deploy time —
edgeone.json → buildCommand: pnpm run build is exactly how the frontend dist/
is produced today. The cloud-function artifact is generated by the very same command,
so it does not need to live in the repository.

EdgeOne 一键部署本来就是部署期构建——edgeone.json 的
buildCommand: pnpm run build 就是现在前端 dist/ 的来源。云函数产物由同一条命令
生成,不需要在仓库里驻留。

用户可感知的行为变化

  • 仓库里不再有 1.8 MB 的构建产物,后端改动的 diff 只包含真实源码。
    不再需要 chore(edgeone): refresh cloud-functions artifact 这类提交。
  • 一键部署(EdgeOne Makers / Cloudflare Workers)对用户完全无感,流程不变。
  • CLI / 直接上传部署的用户需要注意:部署前需先 pnpm run build
    (edgeone makers deploy 会自动构建,不受影响)。

重要实现变化

  • .gitignore 重新忽略 cloud-functions/,并 git rm --cached 移除已提交的产物
    (cloud-functions/[[default]].js,1,921,744 字节)。
  • 删除 .github/workflows/edgeone-artifact-guard.yml 与 tests/artifact-guard.test.ts:
    产物入库才需要"新鲜度比对"守卫,现在这条开销整个消失。
  • 新增 .github/workflows/build-verify.yml:按平台一致流程
    install → fetch-frontend → build-edge,校验 dist/index.html、
    dist-server/api/[...route].js、cloud-functions/[[default]].js 均已生成,
    并断言该产物未被 git 跟踪(防止有人再次 git add 进来)。
  • README 及 13 个语言版本的 Build status badge 从 edgeone-artifact-guard.yml
    改指 build-verify.yml。
  • scripts/build-edge.mjs、middleware.js 的注释同步说明"产物由构建生成、不入库"。

配置 / 存储 / API 变化

无。edgeone.json、wrangler.jsonc、环境变量、API 路由、存储格式均未改动。

Related Issues / 关联 Issue

无直接 issue。来源是本仓库既有的「产物必须提交」约定:
e092379(引入 artifact guard)与 74b46ac(为该约定从 .gitignore 删掉
/cloud-functions)。本 PR 反过来把约定简化为「构建期生成」。

Background / 背景:为什么当初要提交,为什么现在不用

cd8e9e3 的结论是:Makers 在检出仓库时扫描 cloud-functions/ 决定是否启用 Node
函数,缺了会报 No server-handler detected 并退化为纯静态项目,因此产物必须提交。

但当时 EdgeOne 的构建链本身是坏的(7e0a4b2 绕过 corepack、e092379 fix edge build
chain 都在修这条链),所以「构建失败 → 产物没生成 → 判定为纯静态」同样能解释当时
观察到的现象,两种解释无法区分。而可以确认的是:

  1. buildCommand 一定在部署时执行——前端 dist/ 就是这么实时构建出来的;
  2. 官方 CLI 文档的手动构建路径要求「先构建产出输出目录,再把函数目录随输出目录
    一起部署」,即函数目录是随构建产物打包的。

因此本次把「产物必须入库」改为「构建期生成」。

Risk & Verification / 风险与验证

本 PR 的唯一假设:平台在 buildCommand 执行之后收集 cloud-functions/ 目录。

部署后 1 分钟即可判定:

curl -sS https://<your-domain>/api/public/settings | head -c 200   # 期望 200 + JSON
curl -sS -o /dev/null -w '%{http_code}\n' https://<your-domain>/healthz
  • 返回 200 / JSON → 假设成立,本 PR 即为正确方向;
  • 返回 404、或部署日志出现 No server-handler detected → 判定早于构建,
    执行 git revert 1788357 即可完全恢复原状(产物回到仓库,守卫工作流恢复);
    或者改走 CI/CLI 部署(见 Follow-ups)。

Testing / 测试

  • go test ./... — 本仓库为 TypeScript,不适用。
  • Manual test / 手动测试: 见上方「Risk & Verification」的部署后检查。

已执行的检查 / Verified on branch build/edgeone-artifact-generated-at-deploy:

Check / 检查 Result / 结果
git ls-tree -r <branch> -- cloud-functions 空 — 产物已不在分支树中
git show <branch>:.gitignore | grep cloud-functions cloud-functions/(第 54 行)已就位
git ls-tree -r <branch> -- .github/workflows tests 仅 build-verify.yml + sync_repo.yml;tests/ 仅剩 meta.test.ts
origin/build/edgeone-artifact-generated-at-deploy = 1788357,已推送
CI build-verify 本分支 push 后自动运行:install → fetch-frontend → build-edge → 三个产物存在性校验 + "产物未被跟踪"断言

未在本机重跑 pnpm run build:工作区当时存在其他会话未提交的改动,为避免互相干扰,
把构建验证交给 CI(build-verify.yml)执行。

New tests / 新增测试: 无新增单测。原先的 tests/artifact-guard.test.ts 断言的是已删除的
守卫工作流文本,其职责由 build-verify.yml 的两个 step 接替
("Verify artifacts exist" 与 "Assert the EdgeOne artifact is not tracked")。

Checklist / 检查清单

  • I have read CONTRIBUTING.
    / 我已阅读 CONTRIBUTING。
  • I confirm this contribution follows the repository license, contribution policy, and code of conduct.
    / 我确认此贡献符合仓库许可证、贡献规范和行为准则。
  • I have formatted the changed code with prettier where applicable.
    / 我已按适用情况使用 prettier 格式化变更代码。
  • I have requested review from relevant maintainers or code owners where applicable.
    / 我已在适用情况下请求相关维护者或代码所有者审查。

AI Disclosure / AI 使用声明

  • This PR includes AI-assisted content. / 此 PR 包含 AI 辅助内容。

Tools used / 使用工具:

  • ChatGPT
  • Codex
  • GitHub Copilot
  • Claude
  • Gemini
  • Other (please specify) / 其他(请注明): CodeBuddy (AI coding assistant)

Usage scope / 使用范围:

  • Code generation / 代码生成

  • Refactoring / 重构

  • Documentation / 文档

  • Tests / 测试(工作流校验步骤)

  • Translation / 翻译

  • Review assistance / 审查辅助

  • I have reviewed and validated all AI-assisted content included in this PR.
    / 我已审核并验证此 PR 中的所有 AI 辅助内容。

  • I have ensured that all AI-assisted commits include Co-Authored-By attribution.
    / 我已确保所有 AI 辅助提交都包含 Co-Authored-By 归属信息。

  • I can reproduce all AI-assisted content included in this PR without any AI tools.
    / 我可以在没有任何 AI 工具的情况下重现此 PR 中包含的所有 AI 辅助内容。

Operational Note / 运维提示

  • 一键部署用户:无变化。部署时 pnpm run build 会生成 dist/ 与
    cloud-functions/[[default]].js。
  • EdgeOne CLI 用户:edgeone makers deploy 自带构建;若采用「先构建再上传」的
    手动方式(edgeone makers deploy ./dist),必须先在本地跑 pnpm run build,
    并按平台要求让函数目录随输出目录一起上传——产物不再由仓库提供。
  • 首次部署/冷启动时间:构建步骤现在包含云函数打包,部署耗时与之前一致
    (此前同样执行 pnpm run build,只是产物被提交覆盖过一次而已)。

Scope / Follow-ups / 范围与后续

  • In scope / 本 PR 范围: 产物改为构建期生成;移除产物同步守卫;新增构建校验。
  • Not in scope / 不在本 PR 范围:
    • 若线上验证表明平台"判定早于构建",则改为 CI/CLI 部署:
      GitHub Actions 中 pnpm run build → 将 cloud-functions/ 放入 dist/ →
      npx edgeone makers deploy ./dist -n openlist-tsworker -t ${{ secrets.EDGEONE_API_TOKEN }},
      并相应调整 README 的一键部署按钮说明。
    • 消除 tests/ 目前没有 CI 覆盖的现状(meta.test.ts 等未被任何工作流执行)。

Commits / 提交

  • 1788357 — build(edgeone): generate cloud-functions artifact at deploy time instead of committing it
    (20 files changed, +113 / −604)

…ead of committing it

- .gitignore 重新忽略 cloud-functions/,并 git rm --cached 移除已提交的 cloud-functions/[[default]].js(1.8 MB 构建产物,每次后端改动都要重建提交)
- 删除 .github/workflows/edgeone-artifact-guard.yml 与 tests/artifact-guard.test.ts:产物不再入库,无需再做与源码的新鲜度比对
- 新增 .github/workflows/build-verify.yml:按平台一致流程 install -> fetch-frontend -> build-edge,校验 dist/index.html、dist-server/api/[...route].js、cloud-functions/[[default]].js 均已生成,并断言该产物未被 git 跟踪
- README 及 13 个语言版本的 Build status badge 指向 build-verify
- scripts/build-edge.mjs、middleware.js 注释同步说明产物由构建生成、不入库

EdgeOne 一键部署的 buildCommand(edgeone.json -> pnpm run build)已在前端 dist/ 上长期验证为部署期实时构建,云函数产物走同一条链路即可。
@PIKACHUIM PIKACHUIM changed the title build(edgeone): generate cloud-functions artifact at deploy time inst… build(edgeone): generate cloud-functions artifact at deploy time Sep 29, 2026
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
openlist-work 1788357 Sep 29 2026, 06:44 AM

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
openlist-tsworkers 1788357 Sep 29 2026, 06:45 AM

@PIKACHUIM PIKACHUIM added the enhancement New feature or request label Sep 29, 2026
@PIKACHUIM

Copy link
Copy Markdown
Member Author

此PR先合并并进入CI测试,如果有问题再回退

@PIKACHUIM
PIKACHUIM merged commit bfb963e into main Sep 29, 2026
3 checks passed
zxsos added a commit to zxsos/openlist that referenced this pull request Sep 29, 2026
同步上游 bfb963e(OpenListTeam#93:EdgeOne 产物改为部署时生成,不再入库)。

冲突处理(人工确认):
- cloud-functions/[[default]].js、tests/artifact-guard.test.ts、
  .github/workflows/edgeone-artifact-guard.yml —— 跟随上游删除,本仓库部署走 Cloudflare Workers。
- .github/workflows/sync-upstream.yml —— fork 自有,保留并强化:
  上游删除某路径时不再盲目 checkout --theirs(那会因缺少 theirs 版本让整步失败),
  改为先探测上游版本是否存在,不存在则 git rm;冲突清单改用 NUL 分隔读取。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant