Skip to main content
Version: 0.7.2

Using Bob with GitHub Actions

Create a Workflow

The following example shows how to use Bob with GitHub Actions.

Create a file called .github/workflows/ci.yml in your repository with the following contents:

# .github/workflows/ci.yml

name: CI

on:
push:
branches: [ main ]
pull_request:
types: [ opened, synchronize ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install nix
uses: cachix/install-nix-action@v15
with:
nix_path: nixpkgs=channel:nixos-unstable

- name: Install bob
uses: benchkram/bob-install-action@v1
with:
version: 0.6.3

- name: Bob build
run: bob build

Remote Caching

First things first. Make sure you have read our general guide on remote caching. This will teach you how to create a project and create access tokens.

Bellow is a tutorial on how to set up bob.build/zuzuleinen/todoapp project from Remote Cache on GitHub Actions:

  1. Add the bob.yaml file in the root of your repository:
project: bob.build/zuzuleinen/todoapp
nixpkgs: https://github.com/NixOS/nixpkgs/archive/refs/tags/22.05.tar.gz

build:
build:
input: .
cmd: touch hello-world
target: hello-world
  1. Create a CI access token for your project:

img alt

img alt

  1. Copy the authentication token and add it as a secret to your GitHub repository in Settings > Secrets > Actions:

img alt

  1. Create a new secret named, BOB_AUTH_TOKEN: img alt

  2. Create a file called .github/workflows/ci.yml in your repository with the following contents:

# .github/workflows/ci.yml

name: CI

on:
push:
branches: [ main ]
pull_request:
types: [ opened, synchronize ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install nix
uses: cachix/install-nix-action@v15
with:
nix_path: nixpkgs=channel:nixos-unstable

- name: Install bob
uses: benchkram/bob-install-action@v1
with:
version: 0.6.3

- name: Set up authentication token
run: bob auth init --token=${{ secrets.BOB_AUTH_TOKEN }}

- name: Bob build
run: bob build --push
  1. After the workflow is successfully run, you should see the artifact uploaded in the Remote Cache:

img alt

  1. If you check the workflow output you will see that on first run of the build command an artifact was pushed to your project. If you run it again, it will be downloaded and build will flag the task as cached:

First build: img alt Second build: img alt