|
| 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