From 5943440cd2c1bbc74af0665f137ad1e64594fc07 Mon Sep 17 00:00:00 2001 From: Maxime Normandin Date: Sat, 8 Nov 2025 13:43:07 -0500 Subject: [PATCH] improve with ignore script --- netlify-ignore.sh | 32 ++++++++++++++++++++++++++++++++ netlify.toml | 6 +++--- 2 files changed, 35 insertions(+), 3 deletions(-) create mode 100755 netlify-ignore.sh diff --git a/netlify-ignore.sh b/netlify-ignore.sh new file mode 100755 index 00000000..7391cc54 --- /dev/null +++ b/netlify-ignore.sh @@ -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 \ No newline at end of file diff --git a/netlify.toml b/netlify.toml index 19437556..bfdf789d 100644 --- a/netlify.toml +++ b/netlify.toml @@ -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"