Skip to content

Commit b132e83

Browse files
authored
feat(ci): gate builds via vercel-ignore (keep previews, gate no-op prod) (#5)
1 parent 37f75fd commit b132e83

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

scripts/ci/vercel-ignore.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env bash
2+
# Vercel Ignored Build Step. Exit 1 => BUILD. Exit 0 => SKIP (no Build CPU Minutes).
3+
# Bias: when uncertain, BUILD. Canonical copy lives in @iserlabs/web-kit; vendored per repo.
4+
set -u
5+
6+
# 1) Kill automatic preview builds unless this project opts to keep them.
7+
if [ "${VERCEL_ENV:-}" = "preview" ] && [ "${KEEP_PREVIEWS:-}" != "1" ]; then
8+
echo "skip: automatic preview build"; exit 0
9+
fi
10+
11+
# 2) Explicit override for intentional no-code rebuilds (env-var change, redeploy).
12+
if [ "${FORCE_BUILD:-}" = "1" ] || git log -1 --pretty=%B 2>/dev/null | grep -qi '\[build\]'; then
13+
echo "build: forced"; exit 1
14+
fi
15+
16+
# 3) Diff base. Shallow clones may lack the parent => fail-safe to BUILD.
17+
BASE="${VERCEL_GIT_PREVIOUS_SHA:-}"
18+
[ -z "$BASE" ] && BASE="$(git rev-parse HEAD^ 2>/dev/null || true)"
19+
[ -z "$BASE" ] && { echo "build: no diff base (fail-safe)"; exit 1; }
20+
21+
CHANGED="$(git diff --name-only "$BASE" HEAD 2>/dev/null || true)"
22+
[ -z "$CHANGED" ] && { echo "build: empty/failed diff (fail-safe)"; exit 1; }
23+
24+
# 4) Inert allow-list ONLY. Never list content dirs (src/content/**, app pages, public/**).
25+
DEPLOYABLE="$(printf '%s\n' "$CHANGED" \
26+
| grep -vE '(^|/)(README|CLAUDE|AGENTS)\.md$|^docs/|^\.github/|\.(test|spec)\.[jt]sx?$|^\.editorconfig$|^\.vscode/' \
27+
|| true)"
28+
[ -z "$DEPLOYABLE" ] && { echo "skip: only inert paths changed"; exit 0; }
29+
30+
echo "build: deployable changes present"; exit 1

vercel.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
"path": "/api/cron/expire-shares",
66
"schedule": "0 3 * * *"
77
}
8-
]
8+
],
9+
"ignoreCommand": "KEEP_PREVIEWS=1 bash scripts/ci/vercel-ignore.sh"
910
}

0 commit comments

Comments
 (0)