From 622b011d8dc004fd0db32b20e77d22860c377c70 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Mon, 8 Jan 2024 16:14:41 +0000 Subject: [PATCH] Add CI and cache --- .github/workflows/ci.yml | 83 +++++++++++++++++++++++++++++++++++ .github/workflows/quality.yml | 23 ---------- flake.lock | 37 +++++++++++++++- flake.nix | 2 + 4 files changed, 120 insertions(+), 25 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/quality.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..0a1d669 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,83 @@ +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: + matrix: ${{ steps.set-matrix.outputs.matrix }} + steps: + - name: checkout + uses: actions/checkout@v4 + + - name: Install Nix + uses: cachix/install-nix-action@v24 + with: + extra_nix_config: | + trusted-public-keys = public:O6JLD0yXzaJDPiQW1meVu32JIDViuaPtGDfjlOopU7o= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= + substituters = https://hercules.servers.lowrisc.org/nix-cache/public/ https://cache.nixos.org/ + + - 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://hercules.servers.lowrisc.org/nix-cache/ ${{ secrets.NIX_CACHE_TOKEN }} + attic push public $(which attic) + + - name: Generate Build Matrix + id: set-matrix + run: | + matrix="$(nix eval --json .#githubActions.matrix)" + echo "matrix=$matrix" >> $GITHUB_OUTPUT + + build: + needs: build-plan + runs-on: ${{ matrix.os }} + strategy: + matrix: ${{fromJSON(needs.build-plan.outputs.matrix)}} + steps: + - name: checkout + uses: actions/checkout@v4 + + - name: Install Nix + uses: cachix/install-nix-action@v24 + with: + extra_nix_config: | + trusted-public-keys = public:O6JLD0yXzaJDPiQW1meVu32JIDViuaPtGDfjlOopU7o= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= + substituters = https://hercules.servers.lowrisc.org/nix-cache/public/ https://cache.nixos.org/ + + - name: Setup Cache + if: github.event_name != 'pull_request' + run: | + nix profile install github:zhaofengli/attic#attic + attic login --set-default lowrisc https://hercules.servers.lowrisc.org/nix-cache/ ${{ secrets.NIX_CACHE_TOKEN }} + + - name: Build + run: nix build ".#{{ matrix.attr }}" + + - name: Upload Cache + if: github.event_name != 'pull_request' + run: | + attic push public result/ diff --git a/.github/workflows/quality.yml b/.github/workflows/quality.yml deleted file mode 100644 index 5dab2c4..0000000 --- a/.github/workflows/quality.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: Quality - -on: - push: - branches: ["main"] - pull_request: - branches: ["main"] - -jobs: - checks: - runs-on: ubuntu-latest - steps: - - name: checkout - uses: actions/checkout@v3 - - - 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 diff --git a/flake.lock b/flake.lock index ef5d7da..c3782e5 100644 --- a/flake.lock +++ b/flake.lock @@ -19,6 +19,24 @@ } }, "nix-github-actions": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1703863825, + "narHash": "sha256-rXwqjtwiGKJheXB43ybM8NwWB8rO2dSRrEqes0S7F5Y=", + "owner": "nix-community", + "repo": "nix-github-actions", + "rev": "5163432afc817cf8bd1f031418d1869e4c9d5547", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nix-github-actions", + "type": "github" + } + }, + "nix-github-actions_2": { "inputs": { "nixpkgs": [ "poetry2nix", @@ -40,6 +58,20 @@ } }, "nixpkgs": { + "locked": { + "lastModified": 1688646010, + "narHash": "sha256-kCeza5eKI2NEi8k0EoeZfv3lN1r1Vwx+L/VA6I8tmG4=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5daaa32204e9c46b05cd709218b7ba733d07e80c", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs_2": { "locked": { "lastModified": 1703992652, "narHash": "sha256-C0o8AUyu8xYgJ36kOxJfXIroy9if/G6aJbNOpA5W0+M=", @@ -60,7 +92,7 @@ "flake-utils": [ "flake-utils" ], - "nix-github-actions": "nix-github-actions", + "nix-github-actions": "nix-github-actions_2", "nixpkgs": [ "nixpkgs" ], @@ -84,7 +116,8 @@ "root": { "inputs": { "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs", + "nix-github-actions": "nix-github-actions", + "nixpkgs": "nixpkgs_2", "poetry2nix": "poetry2nix" } }, diff --git a/flake.nix b/flake.nix index 078bf9b..7f4cf9d 100644 --- a/flake.nix +++ b/flake.nix @@ -5,6 +5,7 @@ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11"; flake-utils.url = "github:numtide/flake-utils"; + nix-github-actions.url = "github:nix-community/nix-github-actions"; poetry2nix = { url = "github:nix-community/poetry2nix"; @@ -20,6 +21,7 @@ } @ inputs: let no_system_outputs = { lib.poetryOverrides = import ./lib/poetryOverrides.nix; + githubActions = inputs.nix-github-actions.lib.mkGithubMatrix {checks = nixpkgs.lib.getAttrs ["x86_64-linux"] self.packages;}; }; all_system_outputs = flake-utils.lib.eachDefaultSystem (system: let