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.7.0
- 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:
- 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
- Create a CI access token for your project:
- Copy the authentication token and add it as a secret to your GitHub repository in
Settings > Secrets > Actions
:
Create a new secret named,
BOB_AUTH_TOKEN
: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.7.0
- name: Set up authentication token
run: bob auth init --token=${{ secrets.BOB_AUTH_TOKEN }}
- name: Bob build
run: bob build --push
- After the workflow is successfully run, you should see the artifact uploaded in the Remote Cache:
- 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 andbuild
will flag the task as cached:
First build: Second build: