From 29ba2a7d585d1e7f918adcc0f47513cb702768f1 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 | 93 +++++++++++++++++++++++++++++++++++ .github/workflows/quality.yml | 23 --------- flake.nix | 6 +++ 3 files changed, 99 insertions(+), 23 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..e1164d1 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,93 @@ +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: | + REBUILD=() + echo '| Package | Status |' >> $GITHUB_STEP_SUMMARY + echo '|---------|--------|' >> $GITHUB_STEP_SUMMARY + + for LINE in $(nix-shell -p nix-eval-jobs --run 'nix-eval-jobs --accept-flake-config --check-cache-status --flake .#packages.x86_64-linux'); do + ATTR=$(echo "$LINE" | jq -r .attr) + if echo "$LINE" | jq -e .isCached; then + echo "| $ATTR | ✅Cached |" >> $GITHUB_STEP_SUMMARY + else + REBUILD+=($ATTR) + echo "| $ATTR | ⏳Need Rebuild |" >> $GITHUB_STEP_SUMMARY + fi + done + + echo 'ATTRS<> $GITHUB_OUTPUT + jq --null-input '$ARGS.positional' --args -- "${REBUILD[@]}" >> $GITHUB_OUTPUT + echo 'EOF' >> $GITHUB_OUTPUT + + build: + needs: build-plan + runs-on: ubuntu-latest + 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/ 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.nix b/flake.nix index b0c9e1d..f1e989a 100644 --- a/flake.nix +++ b/flake.nix @@ -14,6 +14,12 @@ inputs.flake-utils.follows = "flake-utils"; }; }; + + nixConfig = { + extra-substituters = ["https://nix-cache.lowrisc.org/public/"]; + extra-trusted-public-keys = ["public:O6JLD0yXzaJDPiQW1meVu32JIDViuaPtGDfjlOopU7o="]; + }; + outputs = { self, nixpkgs,