Skip to content

🀯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

πŸ”¨ chore(vercel): skip preview builds for docs and test-only changes (#22368)

YuTengjing1942478e3f9a
diff --git a/scripts/vercelIgnoredBuildStep.js b/scripts/vercelIgnoredBuildStep.js
index d8a9bdecaa6..d6706b6a458 100644
--- a/scripts/vercelIgnoredBuildStep.js
+++ b/scripts/vercelIgnoredBuildStep.js
@@ -7,10 +7,20 @@ const GIT_FETCH_TIMEOUT_MS = 15_000;
const isValidCommitSha = (value) => /^[0-9a-f]{7,64}$/i.test(value);
+/** Top-level directories that never reach the deployed app. */
+const NON_RUNTIME_DIRS = ['.agents/', '.claude/', '.github/', '.husky/', 'docs/', 'e2e/'];
+
+/** Test files anywhere: `*.test.*`, `*.spec.*`, `__tests__/` and `__snapshots__/`. */
+const TEST_FILE_REGEX = /(^|\/)(__tests__|__snapshots__)\/|\.(test|spec)\.[cm]?[jt]sx?$/;
+
+/**
+ * Only root-level Markdown is skipped: packages import nested `.md` files at runtime
+ * (for example `packages/builtin-skills` and `packages/agent-templates`).
+ */
const isNonRuntimePath = (filePath) =>
- filePath === '.github' ||
- filePath.startsWith('.github/') ||
- (!filePath.includes('/') && /\.md$/i.test(filePath));
+ (!filePath.includes('/') && /\.mdx?$/i.test(filePath)) ||
+ NON_RUNTIME_DIRS.some((dir) => filePath.startsWith(dir)) ||
+ TEST_FILE_REGEX.test(filePath);
const runGit = async (args) => {
try {
@@ -95,10 +105,14 @@ const shouldProceedBuild = async () => {
}
};
-shouldProceedBuild()
- .catch(() => buildConservatively('Unable to inspect deployment diff; building conservatively.'))
- .then((shouldBuild) => {
- console.log('shouldBuild:', shouldBuild);
- console.log(shouldBuild ? 'βœ… - Build can proceed' : 'πŸ›‘ - Build cancelled');
- process.exitCode = shouldBuild ? 1 : 0;
- });
+module.exports = { isNonRuntimePath };
+
+if (require.main === module) {
+ shouldProceedBuild()
+ .catch(() => buildConservatively('Unable to inspect deployment diff; building conservatively.'))
+ .then((shouldBuild) => {
+ console.log('shouldBuild:', shouldBuild);
+ console.log(shouldBuild ? 'βœ… - Build can proceed' : 'πŸ›‘ - Build cancelled');
+ process.exitCode = shouldBuild ? 1 : 0;
+ });
+}
diff --git a/scripts/vercelIgnoredBuildStep.test.ts b/scripts/vercelIgnoredBuildStep.test.ts
new file mode 100644
index 00000000000..e57cc9c97fe
--- /dev/null
+++ b/scripts/vercelIgnoredBuildStep.test.ts
@@ -0,0 +1,35 @@
+// @vitest-environment node
+import { createRequire } from 'node:module';
+
+import { describe, expect, it } from 'vitest';
+
+const { isNonRuntimePath } = createRequire(import.meta.url)('./vercelIgnoredBuildStep.js') as {
+ isNonRuntimePath: (filePath: string) => boolean;
+};
+
+describe('isNonRuntimePath', () => {
+ it.each([
+ 'README.md',
+ 'CHANGELOG.mdx',
+ '.github/workflows/test.yml',
+ '.agents/skills/pr/SKILL.md',
+ '.claude/settings.json',
+ 'docs/usage/start.mdx',
+ 'e2e/src/steps/login.ts',
+ 'src/features/Foo/index.test.tsx',
+ 'packages/database/src/models/__tests__/agent.test.ts',
+ 'packages/utils/src/__snapshots__/format.test.ts.snap',
+ ])('skips %s', (file) => {
+ expect(isNonRuntimePath(file)).toBe(true);
+ });
+
+ it.each([
+ 'src/app/page.tsx',
+ 'packages/agent-templates/src/templates/claw/SOUL.md',
+ 'packages/builtin-skills/src/task/SKILL.md',
+ 'scripts/migrateServerDB/index.ts',
+ 'package.json',
+ ])('builds for %s', (file) => {
+ expect(isNonRuntimePath(file)).toBe(false);
+ });
+});