From 7d70c37ab02b67eb6b0bafeedc4bb8eafc27a190 Mon Sep 17 00:00:00 2001 From: Nicolas Mattia Date: Sun, 23 Feb 2020 10:18:59 +0100 Subject: [PATCH] Cleanup nix action --- .github/actions/nix/install-nix | 40 +++++++++++++++++++++++++++++---- .github/workflows/test.yml | 15 ++----------- 2 files changed, 38 insertions(+), 17 deletions(-) diff --git a/.github/actions/nix/install-nix b/.github/actions/nix/install-nix index c245568..6f50ed5 100755 --- a/.github/actions/nix/install-nix +++ b/.github/actions/nix/install-nix @@ -4,12 +4,15 @@ set -euo pipefail +set -x + +echo "Installing Nix" + sudo mkdir -p /etc/nix # Workaround segfault: https://github.com/NixOS/nix/issues/2733 sudo sh -c 'echo "http2 = false" >> /etc/nix/nix.conf' - if [[ $OSTYPE =~ darwin ]]; then echo "Installing on Darwin" sudo sh -c "echo \"nix\t/opt/nix\" >> /etc/synthetic.conf" @@ -28,8 +31,37 @@ fi curl https://nixos.org/nix/install | sh -sudo sh -c 'echo "substituters = https://cache.nixos.org https://niv.cachix.org" > /etc/nix/nix.conf' -sudo sh -c 'echo "trusted-public-keys = niv.cachix.org-1:X32PCg2e/zAm3/uD1ScqW2z/K0LtDyNV7RdaxIuLgQM= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=" >> /etc/nix/nix.conf' - echo "::add-path::/nix/var/nix/profiles/per-user/runner/profile/bin" echo "::add-path::/nix/var/nix/profiles/default/bin" + +PATH="/nix/var/nix/profiles/per-user/runner/profile/bin:$PATH" +PATH="/nix/var/nix/profiles/default/bin:$PATH" + +echo "Installing cachix" + +nix-env -iA cachix -f https://cachix.org/api/v1/install + +echo "Setting up cachix" + +cachix_cache="${GITHUB_REPOSITORY##*/}" + +echo "Using cache '$cachix_cache' for '$GITHUB_REPOSITORY'" + +cachix use "$cachix_cache" + +script_path="$HOME/.local/bin/save-cache" +mkdir -p "$(dirname $script_path)" + +cat <> "$script_path" +#!/usr/bin/env bash +if [ -n "\$CACHIX_SIGNING_KEY" ]; +then + nix path-info --all | cachix push $cachix_cache +else + echo "CACHIX_SIGNING_KEY not set, not uploading cache" +fi +EOF + +chmod +x "$script_path" + +echo "::add-path::$(dirname $script_path)" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1e25435..cefb886 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,19 +14,8 @@ jobs: - uses: actions/checkout@v1 - uses: './.github/actions/nix' - name: "Run tests" - run: | - - ls ~/.nix-profile/etc/ - echo "$NIX_SSL_CERT_FILE" - ./script/test + run: ./script/test - name: "Save cache" - run: | - if [ -n "$CACHIX_SIGNING_KEY" ] - then - nix-env -iA cachix -f https://cachix.org/api/v1/install - nix path-info --all | cachix push niv - else - echo "CACHIX_SIGNING_KEY not set, not uploading cache" - fi + run: save-cache env: CACHIX_SIGNING_KEY: ${{ secrets.CACHIX_SIGNING_KEY }}