magic-nix-cache-action/.github/workflows/cache-test.sh

57 lines
1.3 KiB
Bash
Raw Normal View History

2024-01-11 18:14:06 +01:00
#! /usr/bin/env bash
set -e
set -ux
seed=$(date)
2024-01-11 18:14:06 +01:00
log=$MAGIC_NIX_CACHE_DAEMONDIR/daemon.log
2024-02-15 22:03:08 +01:00
binary_cache=https://cache.flakehub.com
2024-01-11 18:14:06 +01:00
# Check that the action initialized correctly.
grep 'FlakeHub cache is enabled' $log
grep 'Using cache' $log
grep 'GitHub Action cache is enabled' $log
# Build something.
outpath=$(nix-build .github/workflows/cache-tester.nix --argstr seed "$seed")
2024-01-11 18:14:06 +01:00
# Check that the path was enqueued to be pushed to the cache.
grep "Enqueueing.*$outpath" $log
# Wait until it has been pushed succesfully.
found=
for ((i = 0; i < 60; i++)); do
sleep 1
if grep "$(basename $outpath)" $log; then
found=1
break
fi
done
if [[ -z $found ]]; then
echo "FlakeHub push did not happen." >&2
exit 1
fi
# Check the FlakeHub binary cache to see if the path is really there.
nix path-info --store "$binary_cache" $outpath
# FIXME: remove this once the daemon also uploads to GHA automatically.
nix copy --to 'http://127.0.0.1:37515' "$outpath"
2024-01-11 18:14:06 +01:00
rm ./result
nix store delete "$outpath"
if [ -f "$outpath" ]; then
echo "$outpath still exists? can't test"
exit 1
fi
rm -rf ~/.cache/nix
echo "-------"
echo "Trying to substitute the build again..."
echo "if it fails, the cache is broken."
nix-store --realize -vvvvvvvv "$outpath"