@@ -36,16 +36,20 @@ jobs:
3636 - name : Install dependencies
3737 run : npm ci
3838
39- - name : Build and deploy production files (main branch only)
39+ - name : Build production files (main branch only)
4040 if : github.ref == 'refs/heads/main'
4141 run : |
42- npm run build:all
42+ echo "🔨 Building production files..."
43+ if ! npm run build:all; then
44+ echo "❌ Production build failed" >&2
45+ exit 1
46+ fi
4347 mkdir -p public/production
44- cp -r dist/* public/production/
45-
46- - name : Build files for all branches
47- run : |
48- npm run build:all
48+ if ! cp -r dist/* public/production/; then
49+ echo "❌ Failed to copy production files" >&2
50+ exit 1
51+ fi
52+ echo "✅ Production build completed successfully"
4953
5054 - name : Configure Pages
5155 uses : actions/configure-pages@v5
@@ -147,20 +151,54 @@ jobs:
147151 git fetch --depth=1 origin "$BR"
148152 git archive --format=tar FETCH_HEAD | tar -x -C "public/$SAFE"
149153
150- # Build files for this branch
154+ # Build files for this branch with proper error handling
151155 if [[ -f "public/$SAFE/package.json" ]]; then
152156 cd "public/$SAFE"
153- if npm ci --silent 2>/dev/null && npm run build:all --silent 2>/dev/null; then
154- echo "✅ Built files for branch $BR"
155- # Copy built files to root of branch directory for direct access
157+ echo "🔨 Building files for branch $BR..."
158+
159+ # Install dependencies with error handling
160+ if ! npm ci; then
161+ echo "❌ Failed to install dependencies for branch $BR" >&2
162+ cd ../..
163+ continue
164+ fi
165+
166+ # Build with error handling
167+ if npm run build:all; then
168+ echo "✅ Successfully built files for branch $BR"
169+
170+ # Validate build outputs exist and have reasonable size
171+ build_success=true
156172 if [[ -d "dist" ]]; then
157- cp dist/auto-image.*.js . 2>/dev/null || true
158- cp dist/auto-image.*.txt . 2>/dev/null || true
173+ for file in dist/auto-image.*.js dist/auto-image.*.txt; do
174+ if [[ -f "$file" ]]; then
175+ size=$(stat -c%s "$file" 2>/dev/null || echo 0)
176+ if [[ $size -lt 100 ]]; then
177+ echo "⚠️ Build output $file is suspiciously small ($size bytes)" >&2
178+ build_success=false
179+ fi
180+ fi
181+ done
182+
183+ if [[ "$build_success" == "true" ]]; then
184+ # Copy built files to root of branch directory for direct access
185+ if cp dist/auto-image.*.js . && cp dist/auto-image.*.txt .; then
186+ echo "✅ Build artifacts copied successfully for branch $BR"
187+ else
188+ echo "⚠️ Failed to copy some build artifacts for branch $BR" >&2
189+ fi
190+ else
191+ echo "⚠️ Build validation failed for branch $BR, serving source files only" >&2
192+ fi
193+ else
194+ echo "⚠️ No dist directory found for branch $BR, serving source files only" >&2
159195 fi
160196 else
161- echo "⚠️ Build failed for branch $BR, serving source files only"
197+ echo "❌ Build failed for branch $BR, serving source files only" >&2
162198 fi
163199 cd ../..
200+ else
201+ echo "ℹ️ No package.json found for branch $BR, serving source files only"
164202 fi
165203
166204 # Keep only static assets; prune empty dirs
0 commit comments