Set up continuous integration and deployment (CI/CD) for your Bengal site. Automate builds, run tests, and deploy to production with GitHub Actions.
When to Use This Guide
- You want automated builds on every commit
- You need to run tests before deployment
- You want to deploy to production automatically
- You're setting up preview deployments for pull requests
- You need to validate content and links before publishing
Prerequisites
- Bengal installed
- A Git repository on GitHub
- A hosting provider account (GitHub Pages, Netlify, Vercel, etc.)
- Basic knowledge of YAML
Steps
- 1
Basic Build Workflow
Create
.github/workflows/build.yml:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
name: Build Site on: push: branches: [main] pull_request: branches: [main] jobs: build: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v5 with: python-version: '3.14' - name: Install Bengal run: pip install bengal - name: Build site run: bengal build --environment production --strict - name: Upload artifacts uses: actions/upload-artifact@v4 with: name: site path: public/ retention-days: 1 - 2
Deploy to GitHub Pages
Create
.github/workflows/deploy.yml:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
name: Deploy to Production on: push: branches: [main] permissions: contents: read pages: write id-token: write jobs: build: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v5 with: python-version: '3.14' - name: Install Bengal run: pip install bengal - name: Build site run: bengal build --environment production --strict --clean-output - name: Upload artifact uses: actions/upload-pages-artifact@v4 with: path: './public' deploy: environment: name: github-pages url: ${{ steps.deployment.outputs.page_url }} runs-on: ubuntu-latest needs: build steps: - name: Deploy to GitHub Pages id: deployment uses: actions/deploy-pages@v4 - 3
Preview Deployments
Create
.github/workflows/preview.yml:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
name: Preview Deployment on: pull_request: branches: [main] jobs: preview: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v5 with: python-version: '3.14' - name: Install Bengal run: pip install bengal - name: Build site run: bengal build --environment preview --build-drafts - name: Comment PR with preview uses: actions/github-script@v7 with: script: | github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, body: '✅ Preview build successful! Artifacts available in workflow run.' }) - 4
Add Validation and Testing
Add health checks to your CI pipeline:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
# .github/workflows/test.yml name: Test and Validate on: [push, pull_request] jobs: validate: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v5 with: python-version: '3.14' - name: Install Bengal run: pip install bengal - name: Validate configuration run: bengal config doctor - name: Check for broken links run: bengal health linkcheck - name: Build with strict mode run: bengal build --strict --verbose - 5
Caching for Faster Builds
Add caching to speed up workflows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
- name: Cache pip packages uses: actions/cache@v4 with: path: ~/.cache/pip key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }} restore-keys: | ${{ runner.os }}-pip- - name: Cache Bengal build cache uses: actions/cache@v4 with: path: .bengal-cache key: ${{ runner.os }}-bengal-${{ github.sha }} restore-keys: | ${{ runner.os }}-bengal- - 6
Environment-Specific Builds
Create Environment Configs
config/environments/production.yaml:1 2 3 4 5
site: baseurl: "https://example.com" params: analytics_id: "{{ env.GA_ID }}"config/environments/preview.yaml:1 2 3 4 5
site: baseurl: "https://preview.example.com" params: analytics_id: "" # Disable analytics in previewUse Environment Variables
1 2 3
env: GA_ID: ${{ secrets.GA_ID }} API_KEY: ${{ secrets.API_KEY }}
Alternative Platforms
GitLab CI
Create.gitlab-ci.yml:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | |
Netlify
Createnetlify.toml:
1 2 3 4 5 6 | |
Vercel
Createvercel.json:
1 2 3 4 5 | |
Troubleshooting
Build Failures
Issue: Build fails with "Command not found: bengal"
Solutions:
- Ensure Python 3.14+ is installed
- Check
pip install bengalruns before build - Verify Python path in CI environment
Issue: Build fails with strict mode errors
Solutions:
- Fix broken links:
bengal health check - Fix template errors
- Remove
--strictflag temporarily to identify issues
Deployment Issues
Issue: Files not deploying
Solutions:
- Verify output directory:
public/ - Check build artifacts are uploaded
- Verify deployment permissions
Next Steps
- Deployment Options - Explore other hosting platforms
- Configuration - Environment-specific settings
- Validation - Set up health checks