ci(docs): skip Vercel preview builds when docs/ unchanged - #1399
Conversation
Vercel was deploying a preview for every PR even when nothing under docs/ changed (e.g. cua-driver-only PRs). Add an ignoreCommand that exits 0 — i.e. skip — when git diff finds no changes scoped to the project root (docs/). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughA new Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
docs/vercel.json (1)
7-8: Note:git diff HEAD^ HEADin shallow clones may fail if the parent commit is beyond the clone depth, but this is a documented pattern that Vercel explicitly recommends.The
git diff --quiet HEAD^ HEAD ./command can encounter issues in Vercel's shallow clones (depth=10), whereHEAD^may not exist if the parent commit is beyond the depth. However, Vercel's official documentation acknowledges this and still recommends this pattern as the standard approach—the safe fallback behavior (build continues on error) mitigates the risk.If you prefer more robust change detection, use Vercel's environment variables instead:
More reliable alternative using Vercel environment variables
- "ignoreCommand": "git diff --quiet HEAD^ HEAD ./" + "ignoreCommand": "git diff --quiet $VERCEL_GIT_PREVIOUS_SHA $VERCEL_GIT_COMMIT_SHA ./"This uses
VERCEL_GIT_PREVIOUS_SHA(the SHA of the last successful deployment) rather than git history, eliminating shallow clone limitations. Note: Requires "Automatically Expose System Environment Variables" to be enabled, andVERCEL_GIT_PREVIOUS_SHAwill be empty on the first deployment of a new branch.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@docs/vercel.json` around lines 7 - 8, The ignoreCommand using the literal "git diff --quiet HEAD^ HEAD ./" can fail in shallow Vercel clones where HEAD^ is unavailable; update the Vercel config to use Vercel-provided env vars instead by replacing the ignoreCommand logic to check VERCEL_GIT_PREVIOUS_SHA vs VERCEL_GIT_COMMIT_SHA (or fall back when VERCEL_GIT_PREVIOUS_SHA is empty) so change detection does not rely on git history; locate the "ignoreCommand" entry in the JSON and implement a check that uses VERCEL_GIT_PREVIOUS_SHA/VERCEL_GIT_COMMIT_SHA (with a safe default to allow the build when the previous SHA is missing).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@docs/vercel.json`:
- Around line 7-8: The ignoreCommand using the literal "git diff --quiet HEAD^
HEAD ./" can fail in shallow Vercel clones where HEAD^ is unavailable; update
the Vercel config to use Vercel-provided env vars instead by replacing the
ignoreCommand logic to check VERCEL_GIT_PREVIOUS_SHA vs VERCEL_GIT_COMMIT_SHA
(or fall back when VERCEL_GIT_PREVIOUS_SHA is empty) so change detection does
not rely on git history; locate the "ignoreCommand" entry in the JSON and
implement a check that uses VERCEL_GIT_PREVIOUS_SHA/VERCEL_GIT_COMMIT_SHA (with
a safe default to allow the build when the previous SHA is missing).
Summary
Vercel currently builds a docs preview on every PR, even ones that don't touch
docs/(e.g. #1378, which is a cua-driver-only fix). Add anignoreCommandtodocs/vercel.jsonso Vercel skips the build when nothing under the project root has changed.How it works
Vercel runs
ignoreCommandfrom the configured project root (alreadydocs/). The command exits 0 → skip build, exit 1 → continue../is relative to the Vercel project root, so the diff is naturally scoped todocs/. PRs that touch any file underdocs/still get a preview; PRs that don't are skipped immediately.Test plan
Summary by CodeRabbit