|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Netlify ignore script: Skip builds if no docs-related files changed |
| 3 | +# Exit 0 = skip build, Exit 1 = proceed with build |
| 4 | +# |
| 5 | +# This script runs from the barretenberg/docs/ directory (Netlify base) |
| 6 | +# |
| 7 | +# Strategy: |
| 8 | +# - Production deploys (next branch): Compare against CACHED_COMMIT_REF (last deployed commit) |
| 9 | +# - PR previews (other branches): Compare against merge-base with next (changes introduced by PR) |
| 10 | +# |
| 11 | +# This ensures: |
| 12 | +# - Production builds when docs change on next (including nightly releases) |
| 13 | +# - PR previews only build when the PR has docs changes (no clutter on non-docs PRs) |
| 14 | + |
| 15 | +set -euo pipefail |
| 16 | + |
| 17 | +BASE_BRANCH="next" |
| 18 | + |
| 19 | +# Determine the comparison reference based on deploy context |
| 20 | +if [ "${BRANCH:-}" = "$BASE_BRANCH" ]; then |
| 21 | + # Production deploy on the base branch - use CACHED_COMMIT_REF |
| 22 | + if [ -z "${CACHED_COMMIT_REF:-}" ]; then |
| 23 | + echo "Production deploy without cached commit reference - proceeding with build" |
| 24 | + exit 1 |
| 25 | + fi |
| 26 | + COMPARE_REF="$CACHED_COMMIT_REF" |
| 27 | + echo "Production deploy: comparing $COMMIT_REF against last deployed commit $COMPARE_REF" |
| 28 | +else |
| 29 | + # PR preview or branch deploy - use merge-base to detect PR-specific changes |
| 30 | + # Fetch the base branch to ensure we have it available for merge-base comparison |
| 31 | + git fetch origin "$BASE_BRANCH" 2>/dev/null || true |
| 32 | + |
| 33 | + COMPARE_REF=$(git merge-base "origin/$BASE_BRANCH" "$COMMIT_REF" 2>/dev/null || echo "") |
| 34 | + |
| 35 | + if [ -z "$COMPARE_REF" ]; then |
| 36 | + echo "Could not determine merge base with $BASE_BRANCH - proceeding with build" |
| 37 | + exit 1 |
| 38 | + fi |
| 39 | + echo "PR preview: comparing $COMMIT_REF against merge base $COMPARE_REF (from $BASE_BRANCH)" |
| 40 | +fi |
| 41 | + |
| 42 | +# Check for ANY changes in the docs/ directory (current directory in Netlify context) |
| 43 | +if ! git diff --quiet "$COMPARE_REF" "$COMMIT_REF" -- .; then |
| 44 | + echo "Changes detected in barretenberg/docs/ directory - proceeding with build" |
| 45 | + exit 1 |
| 46 | +fi |
| 47 | + |
| 48 | +# Check for changes in barretenberg/cpp/src/barretenberg (Doxygen source for API docs) |
| 49 | +if ! git diff --quiet "$COMPARE_REF" "$COMMIT_REF" -- ../cpp/src/barretenberg; then |
| 50 | + echo "Changes detected in barretenberg/cpp/src/barretenberg - proceeding with build" |
| 51 | + exit 1 |
| 52 | +fi |
| 53 | + |
| 54 | +# Check for changes in barretenberg/cpp/docs (Doxygen config and additional source) |
| 55 | +if ! git diff --quiet "$COMPARE_REF" "$COMMIT_REF" -- ../cpp/docs; then |
| 56 | + echo "Changes detected in barretenberg/cpp/docs - proceeding with build" |
| 57 | + exit 1 |
| 58 | +fi |
| 59 | + |
| 60 | +# Extract all #include_code file references from markdown files |
| 61 | +# Pattern: #include_code identifier /path/to/file language |
| 62 | +# Paths are relative to repo root (may start with /) or relative to docs |
| 63 | +INCLUDE_CODE_PATHS=$( |
| 64 | + find . -type f \( -name "*.md" -o -name "*.mdx" \) 2>/dev/null | \ |
| 65 | + xargs grep -h '^#include_code' 2>/dev/null | \ |
| 66 | + awk '{ gsub("^/", "", $3); print $3 }' | \ |
| 67 | + sort -u || true |
| 68 | +) |
| 69 | + |
| 70 | +# Check each referenced external file for changes |
| 71 | +for path in $INCLUDE_CODE_PATHS; do |
| 72 | + if [ -n "$path" ]; then |
| 73 | + # Check if path exists relative to current dir or relative to repo root |
| 74 | + if [ -f "./$path" ]; then |
| 75 | + # Path is relative to docs/ - already covered by the docs/ check above |
| 76 | + continue |
| 77 | + fi |
| 78 | + # Path is relative to repo root |
| 79 | + if ! git diff --quiet "$COMPARE_REF" "$COMMIT_REF" -- "../../$path" 2>/dev/null; then |
| 80 | + echo "Changes detected in included file: $path - proceeding with build" |
| 81 | + exit 1 |
| 82 | + fi |
| 83 | + fi |
| 84 | +done |
| 85 | + |
| 86 | +echo "No docs-related changes detected - skipping build" |
| 87 | +exit 0 |
0 commit comments