Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

feat: isolate monorepo deployment triggers

yoma0b1ab0d7dfc4
diff --git a/.env.local.example b/.env.local.example
index 027749c1..69d3bbfd 100644
--- a/.env.local.example
+++ b/.env.local.example
@@ -28,6 +28,12 @@ EDGE_EVER_BUILDS_API_TOKEN=
# The selected build token must be able to apply D1 migrations and deploy Workers.
EDGE_EVER_BUILDS_BUILD_TOKEN_UUID=
+# Optional: set this only when this repository also deploys an Astro/PAGES site.
+# `bun run deploy:builds:setup` then limits that Pages project's Git builds to
+# apps/site/* plus shared root dependency files. The User API Token also needs
+# Account -> Cloudflare Pages -> Edit. Leave empty for normal EdgeEver forks.
+EDGE_EVER_PAGES_PROJECT_NAME=
+
# Worker service name.
# Defaults to the `edgeever` Cloudflare Worker.
EDGE_EVER_WORKER_NAME=edgeever
diff --git a/docs/cloudflare-workers-builds.md b/docs/cloudflare-workers-builds.md
index 383557f9..a057e097 100644
--- a/docs/cloudflare-workers-builds.md
+++ b/docs/cloudflare-workers-builds.md
@@ -35,6 +35,12 @@ The setup API call requires a **User API Token**, not an **Account API Token**.
This token is used only by `bun run deploy:builds:setup` and is never uploaded to the Worker or Cloudflare Builds. You may instead reuse `CLOUDFLARE_API_TOKEN` only if it is a User API Token with the same permissions.
+## Monorepo Build Isolation
+
+The Worker trigger already ignores changes limited to `apps/site/*`, `apps/mobile/*`, `apps/extension/*`, `docs/*`, README files, and `.github/*`. Thus a website-only change does not deploy the EdgeEver Worker.
+
+For a Cloudflare Pages project in this repository, set `EDGE_EVER_PAGES_PROJECT_NAME` and rerun `bun run deploy:builds:setup`. The command configures Pages Build watch paths to `apps/site/*`, `bun.lock`, and `package.json`, so product-only changes do not rebuild the website. This optional step requires the User API Token to additionally have **Account** -> **Cloudflare Pages** -> **Edit**. Without automation, set the same paths in **Pages project** -> **Settings** -> **Build** -> **Build watch paths**.
+
### Manual fallback
If the command cannot be used, configure the Worker in the Cloudflare dashboard:
diff --git a/docs/cloudflare-workers-builds.zh-CN.md b/docs/cloudflare-workers-builds.zh-CN.md
index 4471566c..db2b151d 100644
--- a/docs/cloudflare-workers-builds.zh-CN.md
+++ b/docs/cloudflare-workers-builds.zh-CN.md
@@ -36,6 +36,12 @@ Cloudflare 有两项账号级授权,仓库脚本不能、也不应该绕过:
这个 token 仅供 `bun run deploy:builds:setup` 调用,不会上传到 Worker 或 Cloudflare Builds。只有在现有 `CLOUDFLARE_API_TOKEN` 同为 User API Token 且具备上述权限时,才可直接复用。
+## Monorepo 构建隔离
+
+Worker 触发器已经排除了仅发生在 `apps/site/*`、`apps/mobile/*`、`apps/extension/*`、`docs/*`、README 文件和 `.github/*` 中的变更。因此,仅改官网不会发布 EdgeEver Worker。
+
+如果这个仓库还部署了 Cloudflare Pages 官网,请设置 `EDGE_EVER_PAGES_PROJECT_NAME`,再重跑 `bun run deploy:builds:setup`。命令会将 Pages 的 Build watch paths 设为 `apps/site/*`、`bun.lock`、`package.json`;这样仅改产品代码不会重新构建官网。该可选步骤要求 User API Token 额外拥有 **Account** -> **Cloudflare Pages** -> **Edit**。不使用自动化时,在 **Pages 项目** -> **Settings** -> **Build** -> **Build watch paths** 填入同样的路径即可。
+
### 手动兜底
若不能运行命令,则在 Cloudflare Dashboard 中:
diff --git a/scripts/cloudflare-workers-builds.mjs b/scripts/cloudflare-workers-builds.mjs
index 433eaf1b..fb44ea58 100644
--- a/scripts/cloudflare-workers-builds.mjs
+++ b/scripts/cloudflare-workers-builds.mjs
@@ -63,6 +63,7 @@ const gitRepository = () => {
const cfToken = value("EDGE_EVER_BUILDS_API_TOKEN") || value("CLOUDFLARE_API_TOKEN");
const accountId = value("CLOUDFLARE_ACCOUNT_ID");
const workerName = instanceValue("WORKER_NAME");
+const pagesProjectName = value("EDGE_EVER_PAGES_PROJECT_NAME");
const request = async (method, path, body) => {
if (dryRun) return undefined;
@@ -146,6 +147,23 @@ const triggerPayload = (workerTag, repoConnectionUuid, buildTokenUuid) => ({
build_caching_enabled: true,
});
+const configurePagesWatchPaths = async () => {
+ if (!pagesProjectName) return;
+
+ await request("PATCH", `/accounts/${accountId}/pages/projects/${encodeURIComponent(pagesProjectName)}`, {
+ source: {
+ config: {
+ // `*` spans nested directories in Cloudflare Pages. Root lockfiles and
+ // package metadata are shared build inputs, so they intentionally trigger
+ // both projects when changed.
+ path_includes: ["apps/site/*", "bun.lock", "package.json"],
+ path_excludes: [],
+ },
+ },
+ });
+ console.log(`[ok] configured Pages watch paths for ${pagesProjectName}`);
+};
+
const setup = async () => {
if (!accountId) throw new Error("Missing CLOUDFLARE_ACCOUNT_ID.");
if (!workerName) throw new Error("Missing EDGE_EVER_WORKER_NAME.");
@@ -212,6 +230,7 @@ const setup = async () => {
await request("PATCH", `/accounts/${accountId}/builds/triggers/${triggerUuid}/environment_variables`, variables);
console.log(`[ok] ${existing ? "updated" : "created"} production trigger`);
+ await configurePagesWatchPaths();
if (!existing) {
const build = await request("POST", `/accounts/${accountId}/builds/triggers/${triggerUuid}/builds`, { branch: "main" });
console.log(`[ok] started first build${build?.build_uuid ? `: ${build.build_uuid}` : ""}`);