Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions netlify-ignore.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash
# Netlify ignore script - Skip builds if website/ directory hasn't changed
# Based on official Netlify documentation: https://docs.netlify.com/configure-builds/ignore-builds/
# Exit code: 0 = skip build, 1 = proceed with build

# Base branch name (adjust if your default branch is named differently)
BASE_BRANCH="main"

# First, try using Netlify's environment variables (works for regular PRs)
if [ -n "$CACHED_COMMIT_REF" ] && [ -n "$COMMIT_REF" ]; then
if git diff --quiet $CACHED_COMMIT_REF $COMMIT_REF -- 'website/' 2>/dev/null; then
# No changes in website/ directory - skip build
exit 0
else
# Changes detected in website/ - proceed with build
exit 1
fi
fi

# For forked PRs or when env vars aren't available, fetch base branch and compare
# Fetch the latest commit on the base branch
git fetch origin $BASE_BRANCH:$BASE_BRANCH 2>/dev/null || true

# Check for changes in the website/ directory using three-dot syntax (merge base comparison)
# The three-dot syntax (BASE_BRANCH...HEAD) compares the merge base to HEAD
if git diff --quiet origin/$BASE_BRANCH...HEAD -- 'website/' 2>/dev/null; then
# No changes detected in website/ directory - skip build
exit 0
else
# Changes detected in website/ directory - proceed with build
exit 1
fi
6 changes: 3 additions & 3 deletions netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
publish = "build"

# Skip Netlify builds if there are no changes in the website/ directory
# Uses a script that handles both PRs (compares against base branch) and regular commits
# See https://docs.netlify.com/build/configure-builds/ignore-builds/
ignore = "git diff --quiet $COMMIT_REF $CACHED_COMMIT_REF -- website/"
# Based on official Netlify documentation: https://docs.netlify.com/configure-builds/ignore-builds/
# Works for both regular PRs and forked PRs
ignore = "./netlify-ignore.sh"