mirror of
https://github.com/koala73/worldmonitor.git
synced 2026-04-25 17:14:57 +02:00
* fix(ci): vercel-ignore prefers merge-base over VERCEL_GIT_PREVIOUS_SHA on previews PR #3346 was incorrectly skipped with 'Canceled by Ignored Build Step' despite touching src/, pro-test/, and public/. Root cause: on a PR branch's FIRST push, Vercel populates VERCEL_GIT_PREVIOUS_SHA in ways that make the path-diff collapse to empty (e.g., same SHA as HEAD, or a parent commit that sees no net change in the allowed paths). The script preferred PREVIOUS_SHA and only fell back to `git merge-base HEAD origin/main` when PREVIOUS_SHA was literally empty or unresolvable — which misses the 'PREVIOUS_SHA resolves but gives wrong answer' case that Vercel hits on first-push PRs. Fix: flip the priority for PREVIEW deploys. Use merge-base first (the stable truth: 'everything on this PR since it left main'), fall back to PREVIOUS_SHA only for the rare shallow-clone scenario where origin/main isn't in Vercel's clone and merge-base returns empty. Main-branch branch (line 6) is UNCHANGED — it correctly wants PREVIOUS_SHA = the last deployed commit, not merge-base (which would be HEAD itself on main and skip every push). Tested locally: - PR branch + web change + PREVIOUS_SHA=HEAD → exit 1 (build) ✓ - PR branch + scripts-only change + PREVIOUS_SHA=HEAD → exit 0 (skip) ✓ - main + PREVIOUS_SHA=valid previous deploy → exit 1 (build) ✓ Related: PR #3346 needed an empty commit to retrigger the preview deploy. After this fix, first-push PRs should deploy without the dance. * chore: retrigger vercel deploy (previous attempt failed on git-provider transient)
64 lines
2.5 KiB
Bash
Executable File
64 lines
2.5 KiB
Bash
Executable File
#!/bin/bash
|
|
# Vercel Ignored Build Step: exit 0 = skip, exit 1 = build
|
|
# Only build when web-relevant files change. Skip desktop, docs, scripts, CI, etc.
|
|
|
|
# On main: skip if ONLY scripts/, docs/, .github/, or non-web files changed
|
|
if [ "$VERCEL_GIT_COMMIT_REF" = "main" ] && [ -n "$VERCEL_GIT_PREVIOUS_SHA" ]; then
|
|
git cat-file -e "$VERCEL_GIT_PREVIOUS_SHA" 2>/dev/null && {
|
|
WEB_CHANGES=$(git diff --name-only "$VERCEL_GIT_PREVIOUS_SHA" HEAD -- \
|
|
'src/' 'api/' 'server/' 'shared/' 'public/' 'blog-site/' 'pro-test/' 'proto/' 'convex/' \
|
|
'package.json' 'package-lock.json' 'vite.config.ts' 'tsconfig.json' \
|
|
'tsconfig.api.json' 'vercel.json' 'middleware.ts' | head -1)
|
|
[ -z "$WEB_CHANGES" ] && echo "Skipping: no web-relevant changes on main" && exit 0
|
|
}
|
|
exit 1
|
|
fi
|
|
|
|
# Skip preview deploys that aren't tied to a pull request
|
|
[ -z "$VERCEL_GIT_PULL_REQUEST_ID" ] && exit 0
|
|
|
|
# Resolve comparison base: prefer `merge-base HEAD origin/main` (the SHA
|
|
# where this PR branched off main), fall back to VERCEL_GIT_PREVIOUS_SHA.
|
|
#
|
|
# Why this ordering: on a PR branch's FIRST push, Vercel has historically
|
|
# set VERCEL_GIT_PREVIOUS_SHA to values that make the path-diff come back
|
|
# empty (the same SHA as HEAD, or a parent that sees no net change),
|
|
# causing "Canceled by Ignored Build Step" on PRs that genuinely touch
|
|
# web paths (PR #3346 incident: four web-relevant files changed, skipped
|
|
# anyway). merge-base is the stable truth: "everything on this PR since
|
|
# it left main", which is always a superset of any single push and is
|
|
# what the reviewer actually needs a preview for.
|
|
#
|
|
# PREVIOUS_SHA stays as the fallback for the rare shallow-clone edge case
|
|
# where `origin/main` isn't in Vercel's clone and merge-base returns
|
|
# empty. This is the opposite priority from the main-branch branch above
|
|
# (line 6), which correctly wants PREVIOUS_SHA = the last deployed commit.
|
|
COMPARE_SHA=$(git merge-base HEAD origin/main 2>/dev/null)
|
|
if [ -z "$COMPARE_SHA" ] && [ -n "$VERCEL_GIT_PREVIOUS_SHA" ]; then
|
|
git cat-file -e "$VERCEL_GIT_PREVIOUS_SHA" 2>/dev/null && COMPARE_SHA="$VERCEL_GIT_PREVIOUS_SHA"
|
|
fi
|
|
[ -z "$COMPARE_SHA" ] && exit 1
|
|
|
|
# Build if any of these web-relevant paths changed
|
|
git diff --name-only "$COMPARE_SHA" HEAD -- \
|
|
'src/' \
|
|
'api/' \
|
|
'server/' \
|
|
'shared/' \
|
|
'public/' \
|
|
'blog-site/' \
|
|
'pro-test/' \
|
|
'proto/' \
|
|
'convex/' \
|
|
'package.json' \
|
|
'package-lock.json' \
|
|
'vite.config.ts' \
|
|
'tsconfig.json' \
|
|
'tsconfig.api.json' \
|
|
'vercel.json' \
|
|
'middleware.ts' \
|
|
| grep -q . && exit 1
|
|
|
|
# Nothing web-relevant changed, skip the build
|
|
exit 0
|