Spaces:
Running on CPU Upgrade
sidebar_position: 8
Build Verification & CI/CD
This guide explains how we prevent failed HuggingFace deployments through automated build verification.
π¨ The Problem We Solved
April 2026: A duplicate gtag configuration caused a HuggingFace deployment to fail after a 15-minute build process. The error only appeared during the Docker build on HuggingFace's servers, making it slow and expensive to discover.
Root Cause: Configuration errors in docusaurus.config.ts that weren't caught before deployment.
β The Solution
We implemented two layers of protection:
1. Pre-Deployment Build Verification
The deploy-huggingface.sh script now tests builds BEFORE pushing to HuggingFace:
./deploy-huggingface.sh
What it does:
β Docusaurus build test (fast, ~30 seconds)
- Catches config errors like duplicate gtag
- Validates all markdown files and links
- Tests before the slow Docker build
β Docker build test (slow, ~5-10 minutes)
- Full deployment simulation
- Tests all three apps: docs, frontend, API
- Validates the complete build process
β Clear error messages
- Explains common issues
- Suggests fixes
- Prevents deployment if tests fail
2. GitHub Actions CI/CD
The .github/workflows/ci-build-test.yml workflow automatically tests:
- β Frontend TypeScript build
- β Docusaurus documentation build β catches config errors
- β Backend Python tests
Runs automatically on:
- Every push to
main - Every push to
huggingface-deploy - Every pull request to
main
π‘οΈ What This Prevents
Before (Manual Deployment)
git push hf-www huggingface-deploy:main
# Wait 15 minutes...
# β Build fails on HuggingFace
# Must fix, commit, push again
# Wait another 15 minutes...
After (Automated Verification)
./deploy-huggingface.sh
# Docusaurus build test (30s)
# β FAIL: Duplicate gtag config detected
# Fix locally, test again
# β
Docusaurus build succeeds
# β
Docker build succeeds
# β
Deploy to HuggingFace (confident it will work)
π§ Common Build Errors Caught
Duplicate gtag Configuration
Error: "gtag" field in themeConfig should now be specified as option for plugin-google-gtag
Fix: Remove gtag from themeConfig, keep only in preset options:
// β
CORRECT
presets: [
['classic', {
gtag: {
trackingID: 'G-5EQV815915',
anonymizeIP: true,
}
}]
],
themeConfig: {
// β Do NOT put gtag here
}
Missing export statement
Error: ParseError: Unexpected token
Fix: Ensure config file ends properly:
export default config;
Broken markdown links
Warning: Markdown link with URL "..." couldn't be resolved
Fix: Use paths relative to docs directory or full URLs
π Workflow Diagram
Developer makes changes
β
git push origin main
β
GitHub Actions runs tests β Catches errors automatically
ββ Frontend build
ββ Docs build β Your gtag error caught here!
ββ Backend tests
β
If tests pass:
β
./deploy-huggingface.sh
ββ Docusaurus test (30s)
ββ Docker test (5-10min)
ββ Push to HuggingFace
β
β
Deployment succeeds!
π Usage
Deploy with all verification (recommended)
./deploy-huggingface.sh
Skip tests (NOT recommended)
./deploy-huggingface.sh --skip-test
Test builds locally without deploying
# Test Docusaurus only
cd website && npm run build
# Test full Docker build
./test-huggingface-build.sh
# Test and keep container running
./test-huggingface-build.sh --keep
π‘ Best Practices
Always test locally before deploying:
cd website && npm run buildWatch CI/CD results on GitHub:
- Check Actions tab after pushing
- Don't deploy if tests fail
Use the deploy script, don't push manually:
# β Good ./deploy-huggingface.sh # β Bad (skips verification) git push hf-www huggingface-deploy:mainReview warnings even if build succeeds:
- Broken links
- Missing dependencies
- Version mismatches
π Troubleshooting
Build fails with "npm WARN EBADENGINE"
Issue: HuggingFace uses Node 20, but package wants Node 22
Fix: Usually safe to ignore warnings, but check if it causes runtime errors
Docker build test fails locally
Issue: Not enough disk space or memory
Fix:
# Clean up Docker
docker system prune -a -f
# Check disk space
df -h
# Check Docker settings in Docker Desktop (increase resources)
CI tests pass but local build fails
Issue: Different Node/npm versions
Fix:
# Check versions match CI
node -v # Should be 20.x
npm -v # Should be 10.x
# Use nvm to switch versions
nvm use 20
π Related Documentation
π― Summary
This two-layer verification system prevents expensive deployment failures:
- GitHub Actions - Automatic testing on every push
- deploy-huggingface.sh - Pre-deployment verification
Result: Catch errors in 30 seconds locally instead of waiting 15 minutes for HuggingFace build to fail.