Skip to content

Commit e60a125

Browse files
Merge pull request #148 from Staninna/better-cd
Better cd
2 parents 0b21b00 + a994dd4 commit e60a125

7 files changed

Lines changed: 184 additions & 27319 deletions

File tree

.github/workflows/cd.yml

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,30 @@ jobs:
2727
with:
2828
fetch-depth: 1
2929

30+
- name: Set up Node.js
31+
uses: actions/setup-node@v4
32+
with:
33+
node-version: '18'
34+
cache: 'npm'
35+
36+
- name: Install dependencies
37+
run: npm ci
38+
39+
- name: Build production files (main branch only)
40+
if: github.ref == 'refs/heads/main'
41+
run: |
42+
echo "🔨 Building production files..."
43+
if ! npm run build:all; then
44+
echo "❌ Production build failed" >&2
45+
exit 1
46+
fi
47+
mkdir -p public/production
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"
53+
3054
- name: Configure Pages
3155
uses: actions/configure-pages@v5
3256

@@ -127,13 +151,64 @@ jobs:
127151
git fetch --depth=1 origin "$BR"
128152
git archive --format=tar FETCH_HEAD | tar -x -C "public/$SAFE"
129153
154+
# Build files for this branch with proper error handling
155+
if [[ -f "public/$SAFE/package.json" ]]; then
156+
cd "public/$SAFE"
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
172+
if [[ -d "dist" ]]; then
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
195+
fi
196+
else
197+
echo "❌ Build failed for branch $BR, serving source files only" >&2
198+
fi
199+
cd ../..
200+
else
201+
echo "ℹ️ No package.json found for branch $BR, serving source files only"
202+
fi
203+
130204
# Keep only static assets; prune empty dirs
131205
rm -rf "public/$SAFE/.git" "public/$SAFE/.github" \
132206
"public/$SAFE/node_modules"
133207
find "public/$SAFE" -type f ! \
134208
\( -name '*.html' -o -name '*.js' -o -name '*.css' -o \
135209
-name '*.json' -o -name '*.png' -o -name '*.jpg' -o \
136-
-name '*.jpeg' -o -name '*.gif' -o -name '*.svg' \) \
210+
-name '*.jpeg' -o -name '*.gif' -o -name '*.svg' -o \
211+
-name '*.txt' \) \
137212
-delete
138213
find "public/$SAFE" -type d -empty -delete
139214

.github/workflows/release.yml

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
name: Auto Release
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
permissions:
8+
contents: write
9+
10+
jobs:
11+
release:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- uses: actions/setup-node@v4
17+
with:
18+
node-version: '18'
19+
cache: 'npm'
20+
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"
29+
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"
38+
39+
- name: Validate build outputs
40+
run: |
41+
echo "🔍 Validating build outputs..."
42+
validation_failed=false
43+
44+
for file in dist/auto-image.{standalone,userscript,bookmarklet}.js dist/auto-image.bookmarklet.txt; do
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
60+
done
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"
68+
69+
- name: Generate version tag
70+
id: version
71+
run: |
72+
VERSION="v$(date -u +%Y.%m.%d-%H%M%S)"
73+
echo "tag=$VERSION" >> $GITHUB_OUTPUT
74+
echo "Generated version: $VERSION"
75+
76+
- name: Create Release
77+
env:
78+
GH_TOKEN: ${{ github.token }}
79+
run: |
80+
echo "🚀 Creating release ${{ steps.version.outputs.tag }}..."
81+
82+
if ! gh release create ${{ steps.version.outputs.tag }} \
83+
--title "Auto Release ${{ steps.version.outputs.tag }}" \
84+
--notes "Automated release from ${{ github.ref_name }} branch
85+
86+
Commit: ${{ github.sha }}
87+
88+
**Stable Direct URLs (raw files):**
89+
- https://github.com/Staninna/WPlace-AutoBOT/releases/latest/download/auto-image.standalone.js
90+
- https://github.com/Staninna/WPlace-AutoBOT/releases/latest/download/auto-image.userscript.js
91+
- https://github.com/Staninna/WPlace-AutoBOT/releases/latest/download/auto-image.bookmarklet.js
92+
- https://github.com/Staninna/WPlace-AutoBOT/releases/latest/download/auto-image.bookmarklet.txt
93+
94+
**Files included:**
95+
- \`auto-image.standalone.js\` - Standalone version
96+
- \`auto-image.userscript.js\` - Userscript version
97+
- \`auto-image.bookmarklet.js\` - Bookmarklet JavaScript
98+
- \`auto-image.bookmarklet.txt\` - Bookmarklet text" \
99+
dist/auto-image.standalone.js \
100+
dist/auto-image.userscript.js \
101+
dist/auto-image.bookmarklet.js \
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"

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ coverage/
1919
.nyc_output/
2020

2121
# Build and analysis artifacts
22-
dist/build-stats.json
23-
dist/meta.json
22+
dist/
2423

2524
# IDE and editor files
2625
.vscode/

0 commit comments

Comments
 (0)