Skip to content

Commit f69dd52

Browse files
committed
test
1 parent 77dd931 commit f69dd52

2 files changed

Lines changed: 102 additions & 21 deletions

File tree

.github/workflows/cd.yml

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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

.github/workflows/release.yml

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,53 @@ jobs:
1818
node-version: '18'
1919
cache: 'npm'
2020

21-
- run: npm ci
21+
- name: Install dependencies
22+
run: |
23+
echo "📦 Installing dependencies..."
24+
if ! npm ci; then
25+
echo "❌ Failed to install dependencies" >&2
26+
exit 1
27+
fi
28+
echo "✅ Dependencies installed successfully"
2229
23-
- name: Build
24-
run: npm run build:all
30+
- name: Build with error handling
31+
run: |
32+
echo "🔨 Building release artifacts..."
33+
if ! npm run build:all; then
34+
echo "❌ Build failed" >&2
35+
exit 1
36+
fi
37+
echo "✅ Build completed successfully"
2538
2639
- name: Validate build outputs
2740
run: |
41+
echo "🔍 Validating build outputs..."
42+
validation_failed=false
43+
2844
for file in dist/auto-image.{standalone,userscript,bookmarklet}.js dist/auto-image.bookmarklet.txt; do
29-
test -s "$file" || (echo "Missing or empty: $file" && exit 1)
45+
if [[ ! -f "$file" ]]; then
46+
echo "❌ Missing file: $file" >&2
47+
validation_failed=true
48+
elif [[ ! -s "$file" ]]; then
49+
echo "❌ Empty file: $file" >&2
50+
validation_failed=true
51+
else
52+
size=$(stat -c%s "$file" 2>/dev/null || echo 0)
53+
if [[ $size -lt 100 ]]; then
54+
echo "⚠️ Suspiciously small file: $file ($size bytes)" >&2
55+
validation_failed=true
56+
else
57+
echo "✅ Valid: $file ($size bytes)"
58+
fi
59+
fi
3060
done
31-
echo "✅ All outputs validated"
61+
62+
if [[ "$validation_failed" == "true" ]]; then
63+
echo "❌ Build validation failed" >&2
64+
exit 1
65+
fi
66+
67+
echo "✅ All build outputs validated successfully"
3268
3369
- name: Generate version tag
3470
id: version
@@ -41,7 +77,9 @@ jobs:
4177
env:
4278
GH_TOKEN: ${{ github.token }}
4379
run: |
44-
gh release create ${{ steps.version.outputs.tag }} \
80+
echo "🚀 Creating release ${{ steps.version.outputs.tag }}..."
81+
82+
if ! gh release create ${{ steps.version.outputs.tag }} \
4583
--title "Auto Release ${{ steps.version.outputs.tag }}" \
4684
--notes "Automated release from ${{ github.ref_name }} branch
4785
@@ -61,4 +99,9 @@ jobs:
6199
dist/auto-image.standalone.js \
62100
dist/auto-image.userscript.js \
63101
dist/auto-image.bookmarklet.js \
64-
dist/auto-image.bookmarklet.txt
102+
dist/auto-image.bookmarklet.txt; then
103+
echo "❌ Failed to create release" >&2
104+
exit 1
105+
fi
106+
107+
echo "✅ Release ${{ steps.version.outputs.tag }} created successfully"

0 commit comments

Comments
 (0)