Skip to content

Commit

Permalink
Use post action for uploading up cache
Browse files Browse the repository at this point in the history
  • Loading branch information
nmattia committed Feb 24, 2020
1 parent 7d70c37 commit 5fc9a36
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 47 deletions.
1 change: 1 addition & 0 deletions .github/actions/nix/action.yml
Expand Up @@ -3,3 +3,4 @@ description: 'use nix'
runs:
using: 'node12'
main: 'main.js'
post: 'main.js'
108 changes: 65 additions & 43 deletions .github/actions/nix/install-nix
Expand Up @@ -4,64 +4,86 @@

set -euo pipefail

set -x
install_nix() {

echo "Installing Nix"
echo "Installing Nix"

sudo mkdir -p /etc/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'
# 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"
sudo sh -c "mkdir -m 0755 /opt/nix && chown runner /opt/nix"
/System/Library/Filesystems/apfs.fs/Contents/Resources/apfs.util -B
sudo sh -c "echo 'Defaults env_keep += NIX_IGNORE_SYMLINK_STORE' >> /etc/sudoers"
echo "::set-env name=NIX_IGNORE_SYMLINK_STORE::1"
export NIX_IGNORE_SYMLINK_STORE=1
sudo launchctl setenv NIX_IGNORE_SYMLINK_STORE 1
if [[ $OSTYPE =~ darwin ]]; then
echo "Installing on Darwin"
sudo sh -c "echo \"nix\t/opt/nix\" >> /etc/synthetic.conf"
sudo sh -c "mkdir -m 0755 /opt/nix && chown runner /opt/nix"
/System/Library/Filesystems/apfs.fs/Contents/Resources/apfs.util -B
sudo sh -c "echo 'Defaults env_keep += NIX_IGNORE_SYMLINK_STORE' >> /etc/sudoers"
echo "::set-env name=NIX_IGNORE_SYMLINK_STORE::1"
export NIX_IGNORE_SYMLINK_STORE=1
sudo launchctl setenv NIX_IGNORE_SYMLINK_STORE 1

cert_file=~/.nix-profile/etc/ssl/certs/ca-bundle.crt
echo "::set-env name=NIX_SSL_CERT_FILE::$cert_file"
export NIX_SSL_CERT_FILE=$cert_file
sudo launchctl setenv NIX_SSL_CERT_FILE "$cert_file"
fi
cert_file=~/.nix-profile/etc/ssl/certs/ca-bundle.crt
echo "::set-env name=NIX_SSL_CERT_FILE::$cert_file"
export NIX_SSL_CERT_FILE=$cert_file
sudo launchctl setenv NIX_SSL_CERT_FILE "$cert_file"
fi

curl https://nixos.org/nix/install | sh
curl https://nixos.org/nix/install | sh

echo "::add-path::/nix/var/nix/profiles/per-user/runner/profile/bin"
echo "::add-path::/nix/var/nix/profiles/default/bin"
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"
PATH="/nix/var/nix/profiles/per-user/runner/profile/bin:$PATH"
PATH="/nix/var/nix/profiles/default/bin:$PATH"
}

echo "Installing cachix"
install_cachix() {
echo "Installing cachix"

nix-env -iA cachix -f https://cachix.org/api/v1/install
nix-env -iA cachix -f https://cachix.org/api/v1/install

echo "Setting up cachix"
echo "Setting up cachix"

cachix_cache="${GITHUB_REPOSITORY##*/}"
cachix_cache="${GITHUB_REPOSITORY##*/}"

echo "Using cache '$cachix_cache' for '$GITHUB_REPOSITORY'"
echo "Using cache '$cachix_cache' for '$GITHUB_REPOSITORY'"

cachix use "$cachix_cache"
cachix use "$cachix_cache"

script_path="$HOME/.local/bin/save-cache"
mkdir -p "$(dirname $script_path)"
script_path="$HOME/.local/bin/save-cache"
mkdir -p "$(dirname $script_path)"
}

cat <<EOF >> "$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
save_cache() {

cachix_cache="${GITHUB_REPOSITORY##*/}"

chmod +x "$script_path"
echo "Using cache '$cachix_cache' for '$GITHUB_REPOSITORY'"

echo "::add-path::$(dirname $script_path)"
set +x
if [ -z "${CACHIX_SIGNING_KEY:-}" ] && [ -n "${INPUT_CACHIX_SIGNING_KEY:-}" ]; then
echo "CACHIX_SIGNING_KEY not set, but INPUT_CACHIX_SIGNING_KEY is present"
echo "setting CACHIX_SIGNING_KEY"
export CACHIX_SIGNING_KEY="$INPUT_CACHIX_SIGNING_KEY"
fi

if [ -n "$CACHIX_SIGNING_KEY" ];
then
echo "CACHIX_SIGNING_KEY is set, uploading cache"
nix path-info --all | cachix push $cachix_cache
else
echo "CACHIX_SIGNING_KEY not set, not uploading cache"
fi
set -x
}

set -x

if [ "${INSTALL_NIX_WAS_RUN:-}" == "1" ]; then
save_cache
else
install_nix
install_cachix
echo "::set-env name=INSTALL_NIX_WAS_RUN::1"
fi
6 changes: 2 additions & 4 deletions .github/workflows/test.yml
Expand Up @@ -13,9 +13,7 @@ jobs:
steps:
- uses: actions/checkout@v1
- uses: './.github/actions/nix'
with:
CACHIX_SIGNING_KEY: ${{ secrets.CACHIX_SIGNING_KEY }}
- name: "Run tests"
run: ./script/test
- name: "Save cache"
run: save-cache
env:
CACHIX_SIGNING_KEY: ${{ secrets.CACHIX_SIGNING_KEY }}

0 comments on commit 5fc9a36

Please sign in to comment.