Skip to content

Commit e58427c

Browse files
committed
propagate process failure on selfhosted bundle builds
1 parent 6045a05 commit e58427c

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

scripts/build-selfhosted-bundle.sh

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
#!/bin/bash
22

3+
set -e # Exit immediately if any command fails
34

45
export NEXT_PUBLIC_MEILISEARCH_ORIGIN="http://localhost:7700"
56
export NEXT_PUBLIC_MEILISEARCH_API_KEY="fern123!"
67

78
ENV_LOCAL_PATH="packages/fern-docs/bundle/.env.local"
89
ENV_LOCAL_BACKUP="packages/fern-docs/bundle/.env.local.bak"
910

11+
# Function to restore .env.local if it was backed up
12+
cleanup() {
13+
if [ -f "$ENV_LOCAL_BACKUP" ]; then
14+
echo "restoring .env.local from backup..."
15+
mv "$ENV_LOCAL_BACKUP" "$ENV_LOCAL_PATH"
16+
fi
17+
}
18+
19+
# Set trap to run cleanup on exit (success or failure)
20+
# This ensures .env.local is always restored, even if the build fails
21+
trap cleanup EXIT
22+
1023
# move .env.local to a backup if it exists
1124
if [ -f "$ENV_LOCAL_PATH" ]; then
1225
echo "temporarily moving .env.local to backup..."
@@ -19,9 +32,3 @@ cp -r packages/fern-docs/bundle/.next/static packages/fern-docs/bundle/.next/sta
1932
find packages/fern-docs/bundle/.next -depth -mindepth 1 -not -path "packages/fern-docs/bundle/.next/standalone*" -exec rm -rf {} \;
2033
rm -rf packages/fern-docs/bundle/.next/standalone/node_modules/.pnpm/[email protected] && rm -rf packages/fern-docs/bundle/.next/standalone/node_modules/.pnpm/@[email protected]
2134
tar -czf docs_bundle.tar.gz -C packages/fern-docs/bundle/.next/standalone .
22-
23-
# move .env.local back if it was backed up
24-
if [ -f "$ENV_LOCAL_BACKUP" ]; then
25-
echo "restoring .env.local from backup..."
26-
mv "$ENV_LOCAL_BACKUP" "$ENV_LOCAL_PATH"
27-
fi

0 commit comments

Comments
 (0)