Skip to content

feat(ci): add GitHub Action workflow for auto deploy to Cloudflare Workers - #132

Open
smanx wants to merge 3 commits into
OpenListTeam:mainfrom
smanx:main
Open

smanx wants to merge 3 commits into
OpenListTeam:mainfrom
smanx:main

Conversation

@smanx

@smanx smanx commented Oct 18, 2026

Copy link
Copy Markdown

Summary / 摘要

新增 deploy-cf.yml GitHub Actions 工作流,为无法使用 Cloudflare Git 集成部署的用户提供自动部署通道;同时放开 wrangler.jsonc 中被注释的 KV 绑定声明,使自动部署链路开箱即用。

需求背景 / 动机

并非所有用户都能通过 Cloudflare 后台的 Git 集成(Workers Builds)完成部署:

  1. 账号受限:Workers Builds 要求 Cloudflare 账号完成 GitHub 连接授权并订阅 Workers 付费计划的部分功能;部分区域/账号类型(如未绑卡账号、受限地区账号)无法使用 Git 集成或其构建功能
  2. 仓库托管位置受限:Workers Builds 仅支持 GitHub/GitLab 云端仓库,自建 Git 服务(Gitea 等)或未公开的私有仓库无法接入
  3. 构建额度限制:Workers Builds 免费版每月构建次数有限,频繁提交会耗尽额度

对这类用户,GitHub Actions 部署是标准替代方案:构建跑在 GitHub 侧(无 CF 构建额度限制),只需一个 API Token 即可完成部署,不受上述账号/平台限制。

变更内容

  1. 新增 .github/workflows/deploy-cf.yml

    • 触发条件:push 到 main(限 src/scripts/wrangler 等相关路径)+ 手动触发(workflow_dispatch)
    • 流程:checkout → pnpm install(frozen lockfile)→ pnpm run build(拉取官方前端 + 构建 dist)→ 校验 dist/index.html 存在 → cloudflare/wrangler-action@v3 执行 wrangler deploy
    • 需要仓库配置 CLOUDFLARE_API_TOKEN(及可选 CLOUDFLARE_ACCOUNT_ID)Secrets
    • 并发组 cancel-in-progress: false,避免部署中途被取消导致版本不完整
  2. wrangler.jsonc:放开 KV 绑定声明

    • "kv_namespaces": [{ "binding": "KV" }](完全省略 id,依文件头注释中描述的 automatic provisioning 机制)
    • 首次部署由 wrangler 自动创建并绑定 KV,二次部署通过服务端 inherit 绑定复用,不会重复创建
    • 背景:绑定被注释时,Action 首次部署后无任何存储可用,环境检查报 "No storage backend available"。自动预配机制(wrangler >= 4.45)已解决当年注释掉该行所顾虑的空 id 冲突问题
    • 该声明对 CF 后台 Git 集成部署同样生效:两条部署链路(Git 集成 / GitHub Actions)行为一致、互不冲突

用户可感知的行为变化

  • 配置了 Secrets 的用户在 push 后即可通过 GitHub Actions 自动部署到 Cloudflare Workers,不再依赖 CF 侧 Git 集成

  • 首次部署会自动创建 openlist-tsworkers-kv 命名空间(此前需在控制台手动绑定)

  • This PR has breaking changes.

  • This PR changes public API, config, storage format, or migration behavior.
    (仅 wrangler.jsonc 声明变化:新增自动预配的 KV 绑定;不影响既有部署)

  • This PR requires corresponding changes in related repositories.

Related Issues / 关联 Issue

Relates to #34(一键部署/CI 无法绑定资源的问题;本 PR 在 GitHub Actions 场景下通过 automatic provisioning 解决)

Testing / 测试

  • 手动测试:
    • GitHub Actions 实际运行通过(构建 + 部署成功)
    • 部署后环境检查确认 KV 存储就绪(automatic provisioning 生效)
    • 与 CF 后台 Git 集成部署(Workers Builds)共存验证:两条链路部署同一 Worker,KV inherit 复用无冲突
  • 说明:本仓库为 TypeScript/Workers 移植版,go test 不适用;已跑通 pnpm run build 全链路

Checklist / 检查清单

  • I have read 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.

AI Disclosure / AI 使用声明

  • This PR includes AI-assisted content.

Tools used: Other(Trae / Claude)

Usage scope:

  • Code generation

  • Review assistance

  • I have reviewed and validated all AI-assisted content included in this PR.

  • I have ensured that all AI-assisted commits include Co-Authored-By attribution.

wumingzhinu added a commit to wumingzhinu/OpenList-Worker that referenced this pull request Oct 20, 2026
…oy to OpenListTeam#132

与 OpenListTeam#132(deploy-cf.yml)功能完全重叠:两者均为 push main 触发的 fetch-frontend + wrangler deploy。
若两个 PR 同时合并,push main 将触发双份并发部署争抢同一 Worker。
Cloudflare 自动部署统一由 OpenListTeam#132 承担;本 PR 收敛为 EdgeOne / ESA 部署与镜像同步三个纯新增 workflow。

如 OpenListTeam#132 最终未被采纳,可从本提交之前的 257a5c8 恢复该文件(含 workers_dev 入口兜底、
dry_run / route 手动输入、第三方 action 固定 SHA 等细节)。
@wumingzhinu

wumingzhinu commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

@wumingzhinu 这边看到 PR #96 已把与本 PR 功能重叠的 deploy-cloudflare.yml 移除,Cloudflare 自动部署归由本 PR,两边现在无文件级冲突,可并行评审。

协同处理,另三条小提醒,供第一轮跑通参考:

  1. 当前 wrangler.jsonc 为 "workers_dev": false 且未声明 routes,此时 wrangler deploy 会因「没有部署入口」报错 —— PR chore(ci): add Cloudflare / EdgeOne / Alibaba ESA deploy and upstream mirror sync workflows #96 被移除的版本里做过 runner 内兜底(仅当 route / 自定义域名都未配置时临时置 workers_dev,不写回仓库),必要时可参考;
  2. 部署凭据建议同时要求 CLOUDFLARE_API_TOKEN + CLOUDFLARE_ACCOUNT_ID 并在缺失时给出可操作的提示;
  3. 若评审在意供应链安全,可把第三方 action 固定到 commit SHA(PR chore(ci): add Cloudflare / EdgeOne / Alibaba ESA deploy and upstream mirror sync workflows #96 提交里有现成解析示例)。

@PIKACHUIM PIKACHUIM added duplicate This issue or pull request already exists enhancement New feature or request labels Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

duplicate This issue or pull request already exists enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants