bim

CI/CD Workflows

Automate your site builds with popular CI/CD platforms.

GitHub Actions

Create .github/workflows/deploy.yml:

name: Deploy Site

on:
  push:
    branches: [main]
  workflow_dispatch:

permissions:
  contents: read
  pages: write
  id-token: write

concurrency:
  group: "pages"
  cancel-in-progress: true

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0  # Full history for git dates

      - name: Install Rust
        uses: dtolnay/rust-action@stable

      - name: Install bim
        run: cargo install --git https://github.com/example/bim

      - name: Build site
        run: bim build --output _site

      - name: Upload artifact
        uses: actions/upload-pages-artifact@v3
        with:
          path: _site

  deploy:
    needs: build
    runs-on: ubuntu-latest
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    steps:
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v4

GitHub Pages Setup

  1. Go to repository Settings → Pages
  2. Set Source to "GitHub Actions"
  3. Push to main branch to trigger deploy

GitLab CI

Create .gitlab-ci.yml:

stages:
  - build
  - deploy

variables:
  CARGO_HOME: $CI_PROJECT_DIR/.cargo

cache:
  key: rust-cache
  paths:
    - .cargo/
    - target/

build:
  stage: build
  image: rust:latest
  script:
    - cargo install --git https://github.com/example/bim
    - bim build --output public
  artifacts:
    paths:
      - public
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH

pages:
  stage: deploy
  dependencies:
    - build
  script:
    - echo "Deploying to GitLab Pages"
  artifacts:
    paths:
      - public
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH

GitLab Pages Setup

  1. Ensure your repository is public or you have GitLab Pages enabled
  2. Push to default branch
  3. Site deploys to https://username.gitlab.io/repo-name

SourceHut Builds

Create .build.yml:

image: archlinux
packages:
  - rustup
  - git
sources:
  - https://git.sr.ht/~username/my-site
secrets:
  - site-key  # SSH key for deployment
tasks:
  - setup: |
      rustup default stable
      cargo install --git https://github.com/example/bim
  - build: |
      cd my-site
      bim build --output dist
  - deploy: |
      cd my-site
      # Deploy to your server via rsync
      rsync -avz --delete dist/ deploy@yourserver.com:/var/www/site/

SourceHut with Pages.sr.ht

For hosting on pages.sr.ht:

image: archlinux
packages:
  - rustup
  - git
  - hut
sources:
  - https://git.sr.ht/~username/my-site
oauth: pages.sr.ht/PAGES:RW
tasks:
  - setup: |
      rustup default stable
      cargo install --git https://github.com/example/bim
  - build: |
      cd my-site
      bim build --output dist
  - deploy: |
      cd my-site
      tar -czf site.tar.gz -C dist .
      hut pages publish -d username.srht.site site.tar.gz

SourceHut Setup

  1. Create a secret for deployment credentials
  2. Add .build.yml to your repository
  3. Enable builds in repository settings
  4. Push to trigger build

Common Tips

Full Git History

Always fetch full git history for accurate dates:

# GitHub Actions
- uses: actions/checkout@v4
  with:
    fetch-depth: 0

# GitLab CI - default is full clone

# SourceHut - default is full clone

Caching Cargo

Speed up builds by caching Cargo:

# GitHub Actions
- uses: Swatinem/rust-cache@v2

# GitLab CI
cache:
  key: rust-cache
  paths:
    - .cargo/
    - target/

Draft Preview

Build with drafts for preview environments:

# GitHub Actions - preview on PR
- name: Build preview
  if: github.event_name == 'pull_request'
  run: bim build --drafts --output _site

Self-Hosted Deployment

For deploying to your own server:

# Build locally
bim build --output dist

# Deploy via rsync
rsync -avz --delete dist/ user@server:/var/www/site/

# Or use scp
scp -r dist/* user@server:/var/www/site/

Nginx Configuration

server {
    listen 80;
    server_name example.com;
    root /var/www/site;

    location / {
        try_files $uri $uri/ $uri/index.html =404;
    }

    # Clean URLs
    location ~ ^([^.]*[^/])$ {
        return 301 $1/;
    }
}

Related: #ci-cd #automation #deployment #github-actions #gitlab-ci #sourcehut @documentation