Skip to content

Commit 918c5ca

Browse files
committed
Build validation
1 parent 7380adb commit 918c5ca

4 files changed

Lines changed: 137 additions & 1 deletion

File tree

.github/workflows/deploy.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ jobs:
2626
- name: 🏗 npm build
2727
run: npm run build
2828

29+
- name: ✅ Validate build output
30+
run: bash scripts/validate-build.sh --skip-build
31+
2932
- name: 🚀 Deploy to gh-pages
3033
uses: JamesIves/github-pages-deploy-action@v4.6.8
3134
with:

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Available npm scripts:
1818
- `npm run serve` - Start development server with live reload
1919
- `npm run clean` - Remove the `_site` directory
2020
- `npm run debug` - Build with debug output for troubleshooting
21+
- `npm run validate` - Build and validate output
22+
- `npm run validate:only` - Validate existing build (skip build step)
2123

2224
The development server includes:
2325

@@ -31,6 +33,24 @@ Having produced a build in `_site`, the entire directory is pushed up on a `gh-p
3133

3234
## Quality Assurance
3335

36+
### Build Validation
37+
38+
Automated checks ensure the build produces valid output:
39+
40+
- **Critical files**: Validates that index.html, sitemap.xml, feed.xml, and robots.txt exist
41+
- **Content verification**: Ensures expected number of blog posts are generated
42+
- **Structure checks**: Validates HTML structure and feed/sitemap content
43+
- **CI integration**: Runs automatically on every push before deployment
44+
45+
Run validation locally:
46+
47+
```bash
48+
npm run validate # Build and validate
49+
npm run validate:only # Validate existing build only
50+
```
51+
52+
The validation logic is defined in [scripts/validate-build.sh](scripts/validate-build.sh) and used by both local development and CI.
53+
3454
### Link Checking
3555

3656
The repository includes automated link checking via GitHub Actions:

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
"clean": "shx rm -rf _site",
77
"build": "npx @11ty/eleventy",
88
"serve": "npx @11ty/eleventy --serve",
9-
"debug": "DEBUG=Eleventy* npx @11ty/eleventy"
9+
"debug": "DEBUG=Eleventy* npx @11ty/eleventy",
10+
"validate": "bash scripts/validate-build.sh",
11+
"validate:only": "bash scripts/validate-build.sh --skip-build"
1012
},
1113
"devDependencies": {
1214
"@11ty/eleventy": "^3.1.2",

scripts/validate-build.sh

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#!/bin/bash
2+
# Build validation script
3+
# Run this locally to validate your build before pushing
4+
# Usage:
5+
# ./scripts/validate-build.sh # Build and validate
6+
# ./scripts/validate-build.sh --skip-build # Only validate existing build
7+
8+
set -e
9+
10+
# Check if we should skip the build step
11+
SKIP_BUILD=false
12+
if [ "$1" = "--skip-build" ]; then
13+
SKIP_BUILD=true
14+
fi
15+
16+
if [ "$SKIP_BUILD" = false ]; then
17+
echo "🏗 Building site..."
18+
npm run build
19+
fi
20+
21+
echo ""
22+
echo "✅ Validating build output..."
23+
echo ""
24+
25+
# Check that _site directory exists and has content
26+
if [ ! -d "_site" ]; then
27+
echo "❌ Build directory _site does not exist"
28+
exit 1
29+
fi
30+
31+
# Check critical files exist
32+
critical_files=(
33+
"_site/index.html"
34+
"_site/sitemap.xml"
35+
"_site/feed.xml"
36+
"_site/static/robots.txt"
37+
"_site/blog/index.html"
38+
)
39+
40+
echo "Checking critical files..."
41+
for file in "${critical_files[@]}"; do
42+
if [ ! -f "$file" ]; then
43+
echo "❌ Critical file missing: $file"
44+
exit 1
45+
fi
46+
if [ ! -s "$file" ]; then
47+
echo "❌ File is empty: $file"
48+
exit 1
49+
fi
50+
echo "$file"
51+
done
52+
53+
# Count blog posts
54+
blog_count=$(find _site/blog -name "index.html" -type f | wc -l | tr -d ' ')
55+
echo ""
56+
echo "Blog posts: $blog_count"
57+
if [ "$blog_count" -lt 20 ]; then
58+
echo "❌ Expected at least 20 blog posts, found: $blog_count"
59+
exit 1
60+
fi
61+
62+
# Check sitemap
63+
echo ""
64+
echo "Validating sitemap..."
65+
if ! grep -q "<loc>https://rupertmckay.com/blog/" _site/sitemap.xml; then
66+
echo "❌ Sitemap does not contain blog post URLs"
67+
exit 1
68+
fi
69+
sitemap_urls=$(grep -c "<loc>" _site/sitemap.xml)
70+
echo " ✓ Sitemap contains $sitemap_urls URLs"
71+
72+
# Check feed
73+
echo ""
74+
echo "Validating RSS feed..."
75+
if ! grep -q "<entry>" _site/feed.xml; then
76+
echo "❌ RSS feed does not contain entries"
77+
exit 1
78+
fi
79+
feed_entries=$(grep -c "<entry>" _site/feed.xml)
80+
echo " ✓ Feed contains $feed_entries entries"
81+
82+
# Check HTML structure
83+
echo ""
84+
echo "Validating HTML structure..."
85+
invalid_count=0
86+
for html_file in _site/*.html _site/blog/*/index.html; do
87+
if [ -f "$html_file" ]; then
88+
if ! grep -q "<html" "$html_file"; then
89+
echo "❌ Invalid HTML structure in: $html_file"
90+
invalid_count=$((invalid_count + 1))
91+
fi
92+
fi
93+
done
94+
95+
if [ $invalid_count -gt 0 ]; then
96+
echo "❌ Found $invalid_count invalid HTML files"
97+
exit 1
98+
fi
99+
echo " ✓ All HTML files have valid structure"
100+
101+
# Summary
102+
total_size=$(du -sh _site | cut -f1)
103+
echo ""
104+
echo "✅ Build validation passed!"
105+
echo ""
106+
echo "Summary:"
107+
echo " Total size: $total_size"
108+
echo " Blog posts: $blog_count"
109+
echo " Sitemap URLs: $sitemap_urls"
110+
echo " Feed entries: $feed_entries"
111+
echo ""

0 commit comments

Comments
 (0)