diff --git a/frontend/scripts/vercel-ignore-build.sh b/frontend/scripts/vercel-ignore-build.sh new file mode 100644 index 000000000..7ce3c5bef --- /dev/null +++ b/frontend/scripts/vercel-ignore-build.sh @@ -0,0 +1,47 @@ +#!/bin/sh + +case "${VERCEL_GIT_COMMIT_REF:-}" in dependabot/*) echo 'Dependabot branch, skipping preview'; exit 0;; esac + +if [ "${VERCEL_ENV:-}" = "production" ]; then + echo "Production build, building" + exit 1 +fi + +BASE="" + +if [ -n "${VERCEL_GIT_PREVIOUS_SHA:-}" ]; then + if git cat-file -e "${VERCEL_GIT_PREVIOUS_SHA}^{commit}" 2>/dev/null; then + BASE="$VERCEL_GIT_PREVIOUS_SHA" + fi +fi + +if [ -z "$BASE" ]; then + git fetch --quiet --depth=100 origin main 2>/dev/null || true + BASE="$(git merge-base HEAD FETCH_HEAD 2>/dev/null || true)" + if [ -z "$BASE" ]; then + if git cat-file -e origin/main^{commit} 2>/dev/null; then + BASE="origin/main" + elif git rev-parse --verify origin/main >/dev/null 2>&1; then + BASE="origin/main" + fi + fi +fi + +if [ -z "$BASE" ]; then + echo "No base commit found, building" + exit 1 +fi + +git diff --quiet "$BASE" HEAD -- . +STATUS=$? + +if [ "$STATUS" -eq 0 ]; then + echo "No frontend changes, skipping" + exit 0 +elif [ "$STATUS" -eq 1 ]; then + echo "frontend changed, building" + exit 1 +else + echo "Diff failed, building" + exit 1 +fi diff --git a/frontend/vercel.json b/frontend/vercel.json index 937e522f2..a651703a8 100644 --- a/frontend/vercel.json +++ b/frontend/vercel.json @@ -2,7 +2,7 @@ "version": 2, "buildCommand": "npm run build", "installCommand": "npm ci", - "ignoreCommand": "case \"${VERCEL_GIT_COMMIT_REF:-}\" in dependabot/*) exit 0;; *) exit 1;; esac", + "ignoreCommand": "sh scripts/vercel-ignore-build.sh", "framework": "nextjs", "outputDirectory": ".next", "regions": [