From e305e7ef79cedc63740dd84edad1383d05447490 Mon Sep 17 00:00:00 2001 From: Zhaofeng Li Date: Sat, 26 Oct 2024 12:49:18 -0600 Subject: [PATCH 1/4] .github: Fix CI cache push condition $ATTIC_TOKEN is not available after setup. --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f9a62a7..dae2ee5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -67,7 +67,7 @@ jobs: - name: Push build artifacts run: | export PATH=$HOME/.nix-profile/bin:$PATH # FIXME - if [ -n "$ATTIC_TOKEN" ]; then + if [ -n "$ATTIC_CACHE" ]; then nix build --no-link --print-out-paths -L \ .#internalMatrix."$system".\"${{ matrix.nix }}\".attic-tests \ .#internalMatrix."$system".\"${{ matrix.nix }}\".cargoArtifacts \ @@ -152,7 +152,7 @@ jobs: - name: Push build artifacts run: | export PATH=$HOME/.nix-profile/bin:$PATH # FIXME - if [ -n "$ATTIC_TOKEN" ]; then + if [ -n "$ATTIC_CACHE" ]; then nix build --no-link --print-out-paths -L \ .#attic-server-image \ .#attic-server-image-aarch64 \ From d20160548ed1b6cc298f9e092a6faf3f58f4095d Mon Sep 17 00:00:00 2001 From: Zhaofeng Li Date: Sat, 26 Oct 2024 12:49:18 -0600 Subject: [PATCH 2/4] flake/integration-tests: Expose GitHub Actions matrix Currently only integration tests. --- flake.lock | 21 +++++++++++++++++++++ flake.nix | 5 +++++ flake/integration-tests.nix | 6 ++++++ 3 files changed, 32 insertions(+) diff --git a/flake.lock b/flake.lock index 8020ab6..c3a5d92 100644 --- a/flake.lock +++ b/flake.lock @@ -56,6 +56,26 @@ "type": "github" } }, + "nix-github-actions": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1729742964, + "narHash": "sha256-B4mzTcQ0FZHdpeWcpDYPERtyjJd/NIuaQ9+BV1h+MpA=", + "owner": "nix-community", + "repo": "nix-github-actions", + "rev": "e04df33f62cdcf93d73e9a04142464753a16db67", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nix-github-actions", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1726042813, @@ -93,6 +113,7 @@ "crane": "crane", "flake-compat": "flake-compat", "flake-parts": "flake-parts", + "nix-github-actions": "nix-github-actions", "nixpkgs": "nixpkgs", "nixpkgs-stable": "nixpkgs-stable" } diff --git a/flake.nix b/flake.nix index 868ea70..edc472e 100644 --- a/flake.nix +++ b/flake.nix @@ -15,6 +15,11 @@ inputs.nixpkgs.follows = "nixpkgs"; }; + nix-github-actions = { + url = "github:nix-community/nix-github-actions"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + flake-compat = { url = "github:edolstra/flake-compat"; flake = false; diff --git a/flake/integration-tests.nix b/flake/integration-tests.nix index a05d742..4333649 100644 --- a/flake/integration-tests.nix +++ b/flake/integration-tests.nix @@ -29,6 +29,12 @@ in }; config = { + flake.githubActions = inputs.nix-github-actions.lib.mkGithubMatrix { + checks = { + inherit (self.checks) x86_64-linux; + }; + }; + perSystem = { self', pkgs, config, system, ... }: let cfg = config.attic.integration-tests; From 0acbde64ef66df3be724f42e9b98c3cf7ad362e7 Mon Sep 17 00:00:00 2001 From: Zhaofeng Li Date: Sat, 26 Oct 2024 12:49:18 -0600 Subject: [PATCH 3/4] .github/build: Add job to build main packages --- .github/workflows/build.yml | 59 +++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index dae2ee5..59e7c3c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,6 +6,64 @@ env: REGISTRY: ghcr.io IMAGE_NAME: ghcr.io/${{ github.repository }} jobs: + build: + strategy: + matrix: + os: + - ubuntu-latest + - macos-latest + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4.1.7 + + - name: Install current Bash on macOS + if: runner.os == 'macOS' + run: | + command -v brew && brew install bash || true + + - uses: DeterminateSystems/nix-installer-action@v14 + continue-on-error: true # Self-hosted runners already have Nix installed + + - name: Install Attic + run: | + if ! command -v attic &> /dev/null; then + ./.github/install-attic-ci.sh + fi + + - name: Configure Attic + continue-on-error: true + run: | + : "${ATTIC_SERVER:=https://staging.attic.rs/}" + : "${ATTIC_CACHE:=attic-ci}" + echo ATTIC_CACHE=$ATTIC_CACHE >>$GITHUB_ENV + export PATH=$HOME/.nix-profile/bin:$PATH # FIXME + attic login --set-default ci "$ATTIC_SERVER" "$ATTIC_TOKEN" + attic use "$ATTIC_CACHE" + env: + ATTIC_SERVER: ${{ secrets.ATTIC_SERVER }} + ATTIC_CACHE: ${{ secrets.ATTIC_CACHE }} + ATTIC_TOKEN: ${{ secrets.ATTIC_TOKEN }} + + - name: Cache dev shell + run: | + .ci/cache-shell.sh + system=$(nix-instantiate --eval -E 'builtins.currentSystem') + echo system=$system >>$GITHUB_ENV + + # TODO: Abstract all of this out, and use `attic push --stdin` (requires #232) + - name: Build packages + run: | + export PATH=$HOME/.nix-profile/bin:$PATH # FIXME + nix build --no-link --print-out-paths -L \ + .#attic \ + .#attic-client \ + .#attic-server \ + | if [ -n "$ATTIC_CACHE" ]; then + xargs attic push "ci:$ATTIC_CACHE" + else + cat + fi + tests: strategy: matrix: @@ -78,6 +136,7 @@ jobs: runs-on: ubuntu-latest if: github.event_name == 'push' needs: + - build - tests permissions: contents: read From b109cc369d5f8bbc6163fb5701d4f9f59811d045 Mon Sep 17 00:00:00 2001 From: Zhaofeng Li Date: Sat, 26 Oct 2024 12:49:18 -0600 Subject: [PATCH 4/4] .github/build: Build packages in Nix matrix Currently only integration tests. --- .github/workflows/build.yml | 83 +++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 59e7c3c..ec4d4d4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -132,6 +132,89 @@ jobs: | xargs attic push "ci:$ATTIC_CACHE" fi + nix-matrix: + runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.set-matrix.outputs.matrix }} + steps: + - uses: actions/checkout@v4.1.7 + - uses: DeterminateSystems/nix-installer-action@v14 + continue-on-error: true # Self-hosted runners already have Nix installed + + - name: Install Attic + run: | + if ! command -v attic &> /dev/null; then + ./.github/install-attic-ci.sh + fi + + - name: Configure Attic + continue-on-error: true + run: | + : "${ATTIC_SERVER:=https://staging.attic.rs/}" + : "${ATTIC_CACHE:=attic-ci}" + echo ATTIC_CACHE=$ATTIC_CACHE >>$GITHUB_ENV + export PATH=$HOME/.nix-profile/bin:$PATH # FIXME + attic login --set-default ci "$ATTIC_SERVER" "$ATTIC_TOKEN" + attic use "$ATTIC_CACHE" + env: + ATTIC_SERVER: ${{ secrets.ATTIC_SERVER }} + ATTIC_CACHE: ${{ secrets.ATTIC_CACHE }} + ATTIC_TOKEN: ${{ secrets.ATTIC_TOKEN }} + - id: set-matrix + name: Generate Nix Matrix + run: | + set -Eeu + matrix="$(nix eval --json '.#githubActions.matrix')" + echo "matrix=$matrix" >> "$GITHUB_OUTPUT" + + nix-matrix-job: + name: ${{ matrix.name }} + runs-on: ${{ matrix.os }} + needs: + - build + - nix-matrix + strategy: + matrix: ${{fromJSON(needs.nix-matrix.outputs.matrix)}} + steps: + - uses: actions/checkout@v4.1.7 + + - name: Install current Bash on macOS + if: runner.os == 'macOS' + run: | + command -v brew && brew install bash || true + + - uses: DeterminateSystems/nix-installer-action@v14 + continue-on-error: true # Self-hosted runners already have Nix installed + + - name: Install Attic + run: | + if ! command -v attic &> /dev/null; then + ./.github/install-attic-ci.sh + fi + + - name: Configure Attic + continue-on-error: true + run: | + : "${ATTIC_SERVER:=https://staging.attic.rs/}" + : "${ATTIC_CACHE:=attic-ci}" + echo ATTIC_CACHE=$ATTIC_CACHE >>$GITHUB_ENV + export PATH=$HOME/.nix-profile/bin:$PATH # FIXME + attic login --set-default ci "$ATTIC_SERVER" "$ATTIC_TOKEN" + attic use "$ATTIC_CACHE" + env: + ATTIC_SERVER: ${{ secrets.ATTIC_SERVER }} + ATTIC_CACHE: ${{ secrets.ATTIC_CACHE }} + ATTIC_TOKEN: ${{ secrets.ATTIC_TOKEN }} + + - name: Build ${{ matrix.attr }} + run: | + nix build --no-link --print-out-paths -L '.#${{ matrix.attr }}' \ + | if [ -n "$ATTIC_CACHE" ]; then + xargs attic push "ci:$ATTIC_CACHE" + else + cat + fi + image: runs-on: ubuntu-latest if: github.event_name == 'push'