diff --git a/web/scripts/vercel-ignore.sh b/web/scripts/vercel-ignore.sh new file mode 100755 index 00000000..3c0861fd --- /dev/null +++ b/web/scripts/vercel-ignore.sh @@ -0,0 +1,15 @@ +#!/bin/bash +# Vercel `ignoreCommand`: exit 0 to skip the build, non-zero to build. +# Skips the build when neither web/ nor common/ changed since the previous deployed commit. +# Kept in a script (rather than inline in vercel.json) because `ignoreCommand` is capped at 256 chars. + +git fetch origin --unshallow || git fetch origin --deepen=200 || true + +echo "prev=$VERCEL_GIT_PREVIOUS_SHA cur=$VERCEL_GIT_COMMIT_SHA" + +if [ -z "$VERCEL_GIT_PREVIOUS_SHA" ] || ! git cat-file -e "$VERCEL_GIT_PREVIOUS_SHA^{commit}" 2>/dev/null; then + echo 'no usable previous sha - building' + exit 1 +fi + +git diff --quiet "$VERCEL_GIT_PREVIOUS_SHA" "$VERCEL_GIT_COMMIT_SHA" -- ./ ../common/ diff --git a/web/vercel.json b/web/vercel.json index 34f03ab2..9f7f2753 100644 --- a/web/vercel.json +++ b/web/vercel.json @@ -9,5 +9,5 @@ "headers": [{"key": "Cache-Control", "value": "no-cache"}] } ], - "ignoreCommand": "git fetch origin --unshallow || git fetch origin --deepen=200 || true; echo \"prev=$VERCEL_GIT_PREVIOUS_SHA cur=$VERCEL_GIT_COMMIT_SHA\"; if [ -z \"$VERCEL_GIT_PREVIOUS_SHA\" ] || ! git cat-file -e \"$VERCEL_GIT_PREVIOUS_SHA^{commit}\" 2>/dev/null; then echo 'no usable previous sha - building'; exit 1; fi; git diff --quiet \"$VERCEL_GIT_PREVIOUS_SHA\" \"$VERCEL_GIT_COMMIT_SHA\" -- ./ ../common/" + "ignoreCommand": "bash scripts/vercel-ignore.sh" }