diff --git a/.github/install-attic-ci.sh b/.github/install-attic-ci.sh new file mode 100755 index 0000000..102b56c --- /dev/null +++ b/.github/install-attic-ci.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash +set -euo pipefail +expr=$(mktemp) + +cleanup() { + rm -f "$expr" +} + +cat >"$expr" <<'EOF' + { system ? builtins.currentSystem }: +let + maybeStorePath = if builtins ? langVersion && builtins.lessThan 1 builtins.langVersion + then builtins.storePath + else x: x; + mkFakeDerivation = attrs: outputs: + let + outputNames = builtins.attrNames outputs; + common = attrs // outputsSet // + { type = "derivation"; + outputs = outputNames; + all = outputsList; + }; + outputToAttrListElement = outputName: + { name = outputName; + value = common // { + inherit outputName; + outPath = maybeStorePath (builtins.getAttr outputName outputs); + drvPath = maybeStorePath (builtins.getAttr outputName outputs); + }; + }; + outputsList = map outputToAttrListElement outputNames; + outputsSet = builtins.listToAttrs outputsList; + in outputsSet; +in + +{ + "x86_64-linux" = (mkFakeDerivation { + name = "attic-0.1.0"; + system = "x86_64-linux"; +} { + out = "/nix/store/jxw24xfq64f0bhlfyfi7wh2mvc9dvvip-attic-0.1.0"; +}).out; + + "aarch64-linux" = (mkFakeDerivation { + name = "attic-0.1.0"; + system = "aarch64-linux"; +} { + out = "/nix/store/f2i2xz39dzq9d4c1vhhykqmpf05ijwi6-attic-0.1.0"; +}).out; + + "x86_64-darwin" = (mkFakeDerivation { + name = "attic-0.1.0"; + system = "x86_64-darwin"; +} { + out = "/nix/store/3pa4w4ajqvq5dj8pzq8hkhs0ryp0zj55-attic-0.1.0"; +}).out; + + "aarch64-darwin" = (mkFakeDerivation { + name = "attic-0.1.0"; + system = "aarch64-darwin"; +} { + out = "/nix/store/ja9khkssgsdx8293j3ayjl6kbhi5xzix-attic-0.1.0"; +}).out; + +}.${system} + +EOF + +nix-env --substituters "https://staging.attic.rs/attic-ci https://cache.nixos.org" --trusted-public-keys "attic-ci:U5Sey4mUxwBXM3iFapmP0/ogODXywKLRNgRPQpEXxbo= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=" -if "$expr" diff --git a/.github/workflows/book.yml b/.github/workflows/book.yml index 789cfcb..c8a3137 100644 --- a/.github/workflows/book.yml +++ b/.github/workflows/book.yml @@ -26,10 +26,17 @@ jobs: with: extra-conf: | trusted-users = root ${{ env.ACTION_USER }} - substituters = https://staging.attic.rs/attic-ci https://cache.nixos.org - trusted-public-keys = attic-ci:U5Sey4mUxwBXM3iFapmP0/ogODXywKLRNgRPQpEXxbo= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= - # == Manual + - name: Install Attic + run: ./.github/install-attic-ci.sh + + - name: Configure Attic + run: | + attic login staging https://staging.attic.rs/ "$ATTIC_TOKEN" + attic use attic-ci + env: + ATTIC_TOKEN: ${{ secrets.ATTIC_TOKEN }} + - name: Build book run: nix build .#book -L @@ -44,3 +51,13 @@ jobs: - name: Deploy book uses: actions/deploy-pages@v1.2.3 + + # TODO: Just take a diff of the list of store paths, also abstract all of this out + - name: Push build artifacts + run: | + if [ -n "$ATTIC_TOKEN" ]; then + nix build .#book --no-link --print-out-paths -L | \ + xargs attic push attic-ci + fi + env: + ATTIC_TOKEN: ${{ secrets.ATTIC_TOKEN }} diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3546c48..c242fa4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,10 +21,32 @@ jobs: with: extra-conf: | trusted-users = root ${{ env.ACTION_USER }} - substituters = https://staging.attic.rs/attic-ci https://cache.nixos.org - trusted-public-keys = attic-ci:U5Sey4mUxwBXM3iFapmP0/ogODXywKLRNgRPQpEXxbo= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= + + - name: Install Attic + run: ./.github/install-attic-ci.sh + + - name: Configure Attic + run: | + export PATH=$HOME/.nix-profile/bin:$PATH # FIXME + attic login staging https://staging.attic.rs/ "$ATTIC_TOKEN" + attic use attic-ci + env: + ATTIC_TOKEN: ${{ secrets.ATTIC_TOKEN }} - name: Build and run tests run: | - tests=$(nix build .#attic-tests --no-link --print-out-paths -L) + system=$(nix-instantiate --eval -E 'builtins.currentSystem') + echo system=$system >>$GITHUB_ENV + tests=$(nix build .#internal."$system".attic-tests --no-link --print-out-paths -L) find "$tests/bin" -exec {} \; + + # TODO: Just take a diff of the list of store paths, also abstract all of this out + - name: Push build artifacts + run: | + export PATH=$HOME/.nix-profile/bin:$PATH # FIXME + if [ -n "$ATTIC_TOKEN" ]; then + nix build .#internal."$system".attic-tests .#internal."$system".cargoArtifacts --no-link --print-out-paths -L | \ + xargs attic push attic-ci + fi + env: + ATTIC_TOKEN: ${{ secrets.ATTIC_TOKEN }} diff --git a/flake.nix b/flake.nix index 88f94da..2d352a6 100644 --- a/flake.nix +++ b/flake.nix @@ -31,7 +31,7 @@ packages = { default = packages.attic; - inherit (cranePkgs) attic attic-client attic-server attic-tests; + inherit (cranePkgs) attic attic-client attic-server; attic-nixpkgs = pkgs.callPackage ./package.nix { }; @@ -61,6 +61,10 @@ }; }; + internal = { + inherit (cranePkgs) attic-tests cargoArtifacts; + }; + devShells = { default = pkgs.mkShell { inputsFrom = with packages; [ attic book ];