# Automate with GitHub Actions URL: /docs/tutorials/automate-with-github-actions/ Section: tutorials Tags: tutorial, ci-cd, automation, github-actions -------------------------------------------------------------------------------- Automate with GitHub Actions 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 1Basic Build WorkflowCreate .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 33name: 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 2Deploy to GitHub PagesCreate .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 44name: 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 3Preview DeploymentsCreate .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 34name: 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.' }) 4Add Validation and TestingAdd 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 5Caching for Faster BuildsAdd 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- 6Environment-Specific BuildsCreate Environment Configs config/environments/production.yaml: 1 2 3 4 5site: baseurl: "https://example.com" params: analytics_id: "{{ env.GA_ID }}" config/environments/preview.yaml: 1 2 3 4 5site: baseurl: "https://preview.example.com" params: analytics_id: "" # Disable analytics in preview Use Environment Variables 1 2 3env: 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 25image: python:3.14 stages: - build - deploy build: stage: build script: - pip install bengal - bengal build --environment production --strict artifacts: paths: - public/ pages: stage: deploy script: - pip install bengal - bengal build --environment production --strict artifacts: paths: - public only: - main Netlify Create netlify.toml: 1 2 3 4 5 6[build] publish = "public" command = "pip install bengal && bengal build --environment production --strict" [build.environment] PYTHON_VERSION = "3.14" Vercel Create vercel.json: 1 2 3 4 5{ "buildCommand": "pip install bengal && bengal build --environment production", "outputDirectory": "public", "installCommand": "pip install bengal" } Troubleshooting Warning Build Failures Issue: Build fails with "Command not found: bengal" Solutions: Ensure Python 3.14+ is installed Check pip install bengal runs 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 --strict flag temporarily to identify issues Warning 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 -------------------------------------------------------------------------------- Metadata: - Author: lbliii - Word Count: 869 - Reading Time: 4 minutes