Add CI and cache #7
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI | |
on: | |
push: | |
branches: ["main"] | |
pull_request: | |
branches: ["main"] | |
jobs: | |
checks: | |
runs-on: ubuntu-latest | |
steps: | |
- name: checkout | |
uses: actions/checkout@v4 | |
- name: Install Nix | |
uses: cachix/install-nix-action@v24 | |
- name: Nix Format Check | |
run: nix fmt -- . --check | |
- name: Nix Syntax Check | |
run: nix flake check | |
build-plan: | |
# Save some computation. If the checks fail, don't build. | |
needs: checks | |
runs-on: ubuntu-latest | |
outputs: | |
attrs: ${{ steps.plan.outputs.ATTRS }} | |
steps: | |
- name: checkout | |
uses: actions/checkout@v4 | |
- name: Install Nix | |
uses: cachix/install-nix-action@v24 | |
with: | |
nix_path: nixpkgs=channel:nixos-23.11 | |
- name: Build and Cache Attic | |
if: github.event_name != 'pull_request' | |
run: | | |
nix profile install github:zhaofengli/attic#attic | |
attic login --set-default lowrisc https://nix-cache.lowrisc.org/ ${{ secrets.NIX_CACHE_TOKEN }} | |
attic push public $(which attic) | |
- name: Generate Nix Build Plan | |
id: plan | |
run: | | |
echo 'ATTRS<<EOF' >> $GITHUB_OUTPUT | |
nix-shell -p nix-eval-jobs --run 'nix-eval-jobs --accept-flake-config --check-cache-status --flake .#packages.x86_64-linux' | \ | |
tee /dev/stderr | \ | |
jq -s 'map(select(.isCached | not) | .attr)' | \ | |
tee -a $GITHUB_OUTPUT | |
echo 'EOF' >> $GITHUB_OUTPUT | |
build: | |
needs: build-plan | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
attr: ${{fromJSON(needs.build-plan.outputs.attrs)}} | |
steps: | |
- name: checkout | |
uses: actions/checkout@v4 | |
- name: Install Nix | |
uses: cachix/install-nix-action@v24 | |
- name: Setup Cache | |
if: github.event_name != 'pull_request' | |
run: | | |
nix profile install github:zhaofengli/attic#attic | |
attic login --set-default lowrisc https://nix-cache.lowrisc.org/ ${{ secrets.NIX_CACHE_TOKEN }} | |
- name: Build | |
run: nix build ".#${{ matrix.attr }}" --accept-flake-config | |
- name: Upload Cache | |
if: github.event_name != 'pull_request' | |
run: | | |
attic push public result/ |