From 3fb0f9613dc9bfa2edba9684f53559e94b1b37dc Mon Sep 17 00:00:00 2001 From: Shahed Nasser Date: Mon, 18 Aug 2025 10:29:32 +0300 Subject: [PATCH] docs: optimize script to ignore builds (#13232) --- www/apps/api-reference/vercel.json | 2 +- www/apps/book/vercel.json | 2 +- www/apps/cloud/vercel.json | 2 +- www/apps/resources/vercel.json | 2 +- www/apps/ui/vercel.json | 2 +- www/apps/user-guide/vercel.json | 2 +- www/ignore-build-script.sh | 46 ++++++++++++++++++++++++++++-- 7 files changed, 49 insertions(+), 9 deletions(-) diff --git a/www/apps/api-reference/vercel.json b/www/apps/api-reference/vercel.json index f1a53d3670..18309e64e7 100644 --- a/www/apps/api-reference/vercel.json +++ b/www/apps/api-reference/vercel.json @@ -7,5 +7,5 @@ "installCommand": "yarn install", "buildCommand": "turbo run build", "outputDirectory": ".next", - "ignoreCommand": "bash ../../ignore-build-script.sh" + "ignoreCommand": "bash ../../ignore-build-script.sh api-reference" } diff --git a/www/apps/book/vercel.json b/www/apps/book/vercel.json index 323833758c..4f0cfed39e 100644 --- a/www/apps/book/vercel.json +++ b/www/apps/book/vercel.json @@ -3,5 +3,5 @@ "installCommand": "yarn install", "buildCommand": "turbo run build", "outputDirectory": ".next", - "ignoreCommand": "bash ../../ignore-build-script.sh" + "ignoreCommand": "bash ../../ignore-build-script.sh book" } \ No newline at end of file diff --git a/www/apps/cloud/vercel.json b/www/apps/cloud/vercel.json index 323833758c..2e7064bbe6 100644 --- a/www/apps/cloud/vercel.json +++ b/www/apps/cloud/vercel.json @@ -3,5 +3,5 @@ "installCommand": "yarn install", "buildCommand": "turbo run build", "outputDirectory": ".next", - "ignoreCommand": "bash ../../ignore-build-script.sh" + "ignoreCommand": "bash ../../ignore-build-script.sh cloud" } \ No newline at end of file diff --git a/www/apps/resources/vercel.json b/www/apps/resources/vercel.json index 323833758c..63d5392e2e 100644 --- a/www/apps/resources/vercel.json +++ b/www/apps/resources/vercel.json @@ -3,5 +3,5 @@ "installCommand": "yarn install", "buildCommand": "turbo run build", "outputDirectory": ".next", - "ignoreCommand": "bash ../../ignore-build-script.sh" + "ignoreCommand": "bash ../../ignore-build-script.sh resources" } \ No newline at end of file diff --git a/www/apps/ui/vercel.json b/www/apps/ui/vercel.json index e88ccbe8b7..40641b2f25 100644 --- a/www/apps/ui/vercel.json +++ b/www/apps/ui/vercel.json @@ -3,7 +3,7 @@ "installCommand": "yarn install", "buildCommand": "turbo run build", "outputDirectory": ".next", - "ignoreCommand": "bash ../../ignore-build-script.sh", + "ignoreCommand": "bash ../../ignore-build-script.sh ui", "redirects": [ { "source": "/ui/hooks/use-toast", diff --git a/www/apps/user-guide/vercel.json b/www/apps/user-guide/vercel.json index 323833758c..52ce477a25 100644 --- a/www/apps/user-guide/vercel.json +++ b/www/apps/user-guide/vercel.json @@ -3,5 +3,5 @@ "installCommand": "yarn install", "buildCommand": "turbo run build", "outputDirectory": ".next", - "ignoreCommand": "bash ../../ignore-build-script.sh" + "ignoreCommand": "bash ../../ignore-build-script.sh user-guide" } \ No newline at end of file diff --git a/www/ignore-build-script.sh b/www/ignore-build-script.sh index b07cc4a91e..af5dfbd0c4 100644 --- a/www/ignore-build-script.sh +++ b/www/ignore-build-script.sh @@ -5,20 +5,60 @@ if [[ "$1" == "docs-old" ]]; then exit 0; fi +PROJECT_NAME="$1" + +echo "PROJECT_NAME: $PROJECT_NAME" echo "VERCEL_ENV: $VERCEL_ENV" echo "VERCEL_GIT_COMMIT_REF: $VERCEL_GIT_COMMIT_REF" SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) echo "SCRIPT_DIR: $SCRIPT_DIR" +# Check for changes in the www directory (original logic) $(git diff HEAD^ HEAD --quiet ${SCRIPT_DIR}) diffResult=$? -echo "DIFF RESULT: $diffResult" +echo "DIFF RESULT (www): $diffResult" + +# For preview environments, also check project-specific directories +if [[ "$VERCEL_ENV" == "preview" && -n "$PROJECT_NAME" ]]; then + # Check for changes in the specific project directory + PROJECT_DIR="${SCRIPT_DIR}/apps/${PROJECT_NAME}" + if [[ -d "$PROJECT_DIR" ]]; then + $(git diff HEAD^ HEAD --quiet ${PROJECT_DIR}) + projectDiffResult=$? + echo "DIFF RESULT (project ${PROJECT_NAME}): $projectDiffResult" + else + projectDiffResult=0 + echo "Project directory ${PROJECT_DIR} does not exist" + fi + + # Check for changes in www/packages directory + PACKAGES_DIR="${SCRIPT_DIR}/packages" + if [[ -d "$PACKAGES_DIR" ]]; then + $(git diff HEAD^ HEAD --quiet ${PACKAGES_DIR}) + packagesDiffResult=$? + echo "DIFF RESULT (packages): $packagesDiffResult" + else + packagesDiffResult=0 + echo "Packages directory ${PACKAGES_DIR} does not exist" + fi + + # For preview, build if there are changes in project dir OR packages dir + previewShouldBuild=$((projectDiffResult + packagesDiffResult)) + if [[ $previewShouldBuild -gt 0 ]]; then + previewShouldBuild=1 + fi + echo "PREVIEW SHOULD BUILD: $previewShouldBuild" +fi if [[ ("$VERCEL_ENV" == "production" && $diffResult -eq 1) || "$VERCEL_GIT_COMMIT_REF" = "docs/"* ]] ; then - # Proceed with the build - echo "✅ - Build can proceed" + # Proceed with the build for production with changes or docs branches + echo "✅ - Build can proceed (production with changes or docs branch)" + exit 1; +elif [[ "$VERCEL_ENV" == "preview" && -n "$PROJECT_NAME" && $previewShouldBuild -eq 1 ]]; then + # Proceed with the build for preview if there are changes in project or packages directory + echo "✅ - Build can proceed (preview with project/packages changes)" exit 1; else # Don't build