2024-01-11 18:14:06 +01:00
|
|
|
#! /usr/bin/env bash
|
2023-06-26 05:18:41 +02:00
|
|
|
|
|
|
|
set -e
|
|
|
|
set -ux
|
|
|
|
|
|
|
|
seed=$(date)
|
|
|
|
|
2024-03-06 22:10:54 +01:00
|
|
|
log="${MAGIC_NIX_CACHE_DAEMONDIR}/daemon.log"
|
2024-01-11 18:14:06 +01:00
|
|
|
|
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.
|
2024-03-06 22:10:54 +01:00
|
|
|
grep 'FlakeHub cache is enabled' "${log}"
|
|
|
|
grep 'Using cache' "${log}"
|
|
|
|
grep 'GitHub Action cache is enabled' "${log}"
|
2024-01-11 18:14:06 +01:00
|
|
|
|
|
|
|
# Build something.
|
2023-06-26 05:18:41 +02:00
|
|
|
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.
|
2024-03-06 22:10:54 +01:00
|
|
|
grep "Enqueueing.*${outpath}" "${log}"
|
2024-01-11 18:14:06 +01:00
|
|
|
|
|
|
|
# Wait until it has been pushed succesfully.
|
|
|
|
found=
|
|
|
|
for ((i = 0; i < 60; i++)); do
|
|
|
|
sleep 1
|
2024-03-06 22:10:54 +01:00
|
|
|
if grep "✅ $(basename "${outpath}")" "${log}"; then
|
2024-01-11 18:14:06 +01:00
|
|
|
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.
|
2024-03-06 22:10:54 +01:00
|
|
|
nix path-info --store "${binary_cache}" "${outpath}"
|
2024-01-11 18:14:06 +01:00
|
|
|
|
|
|
|
# FIXME: remove this once the daemon also uploads to GHA automatically.
|
2024-03-06 22:10:54 +01:00
|
|
|
nix copy --to 'http://127.0.0.1:37515' "${outpath}"
|
2024-01-11 18:14:06 +01:00
|
|
|
|
2023-06-26 05:18:41 +02:00
|
|
|
rm ./result
|
2024-03-06 22:10:54 +01:00
|
|
|
nix store delete "${outpath}"
|
2023-06-26 05:18:41 +02:00
|
|
|
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"
|