Skip to content

Commit 3fb0f96

Browse files
authored
docs: optimize script to ignore builds (medusajs#13232)
1 parent c42155f commit 3fb0f96

File tree

7 files changed

+49
-9
lines changed

7 files changed

+49
-9
lines changed

www/apps/api-reference/vercel.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
"installCommand": "yarn install",
88
"buildCommand": "turbo run build",
99
"outputDirectory": ".next",
10-
"ignoreCommand": "bash ../../ignore-build-script.sh"
10+
"ignoreCommand": "bash ../../ignore-build-script.sh api-reference"
1111
}

www/apps/book/vercel.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
"installCommand": "yarn install",
44
"buildCommand": "turbo run build",
55
"outputDirectory": ".next",
6-
"ignoreCommand": "bash ../../ignore-build-script.sh"
6+
"ignoreCommand": "bash ../../ignore-build-script.sh book"
77
}

www/apps/cloud/vercel.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
"installCommand": "yarn install",
44
"buildCommand": "turbo run build",
55
"outputDirectory": ".next",
6-
"ignoreCommand": "bash ../../ignore-build-script.sh"
6+
"ignoreCommand": "bash ../../ignore-build-script.sh cloud"
77
}

www/apps/resources/vercel.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
"installCommand": "yarn install",
44
"buildCommand": "turbo run build",
55
"outputDirectory": ".next",
6-
"ignoreCommand": "bash ../../ignore-build-script.sh"
6+
"ignoreCommand": "bash ../../ignore-build-script.sh resources"
77
}

www/apps/ui/vercel.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"installCommand": "yarn install",
44
"buildCommand": "turbo run build",
55
"outputDirectory": ".next",
6-
"ignoreCommand": "bash ../../ignore-build-script.sh",
6+
"ignoreCommand": "bash ../../ignore-build-script.sh ui",
77
"redirects": [
88
{
99
"source": "/ui/hooks/use-toast",

www/apps/user-guide/vercel.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
"installCommand": "yarn install",
44
"buildCommand": "turbo run build",
55
"outputDirectory": ".next",
6-
"ignoreCommand": "bash ../../ignore-build-script.sh"
6+
"ignoreCommand": "bash ../../ignore-build-script.sh user-guide"
77
}

www/ignore-build-script.sh

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,60 @@ if [[ "$1" == "docs-old" ]]; then
55
exit 0;
66
fi
77

8+
PROJECT_NAME="$1"
9+
10+
echo "PROJECT_NAME: $PROJECT_NAME"
811
echo "VERCEL_ENV: $VERCEL_ENV"
912
echo "VERCEL_GIT_COMMIT_REF: $VERCEL_GIT_COMMIT_REF"
1013

1114
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
1215
echo "SCRIPT_DIR: $SCRIPT_DIR"
1316

17+
# Check for changes in the www directory (original logic)
1418
$(git diff HEAD^ HEAD --quiet ${SCRIPT_DIR})
1519
diffResult=$?
1620

17-
echo "DIFF RESULT: $diffResult"
21+
echo "DIFF RESULT (www): $diffResult"
22+
23+
# For preview environments, also check project-specific directories
24+
if [[ "$VERCEL_ENV" == "preview" && -n "$PROJECT_NAME" ]]; then
25+
# Check for changes in the specific project directory
26+
PROJECT_DIR="${SCRIPT_DIR}/apps/${PROJECT_NAME}"
27+
if [[ -d "$PROJECT_DIR" ]]; then
28+
$(git diff HEAD^ HEAD --quiet ${PROJECT_DIR})
29+
projectDiffResult=$?
30+
echo "DIFF RESULT (project ${PROJECT_NAME}): $projectDiffResult"
31+
else
32+
projectDiffResult=0
33+
echo "Project directory ${PROJECT_DIR} does not exist"
34+
fi
35+
36+
# Check for changes in www/packages directory
37+
PACKAGES_DIR="${SCRIPT_DIR}/packages"
38+
if [[ -d "$PACKAGES_DIR" ]]; then
39+
$(git diff HEAD^ HEAD --quiet ${PACKAGES_DIR})
40+
packagesDiffResult=$?
41+
echo "DIFF RESULT (packages): $packagesDiffResult"
42+
else
43+
packagesDiffResult=0
44+
echo "Packages directory ${PACKAGES_DIR} does not exist"
45+
fi
46+
47+
# For preview, build if there are changes in project dir OR packages dir
48+
previewShouldBuild=$((projectDiffResult + packagesDiffResult))
49+
if [[ $previewShouldBuild -gt 0 ]]; then
50+
previewShouldBuild=1
51+
fi
52+
echo "PREVIEW SHOULD BUILD: $previewShouldBuild"
53+
fi
1854

1955
if [[ ("$VERCEL_ENV" == "production" && $diffResult -eq 1) || "$VERCEL_GIT_COMMIT_REF" = "docs/"* ]] ; then
20-
# Proceed with the build
21-
echo "✅ - Build can proceed"
56+
# Proceed with the build for production with changes or docs branches
57+
echo "✅ - Build can proceed (production with changes or docs branch)"
58+
exit 1;
59+
elif [[ "$VERCEL_ENV" == "preview" && -n "$PROJECT_NAME" && $previewShouldBuild -eq 1 ]]; then
60+
# Proceed with the build for preview if there are changes in project or packages directory
61+
echo "✅ - Build can proceed (preview with project/packages changes)"
2262
exit 1;
2363
else
2464
# Don't build

0 commit comments

Comments
 (0)