2024-01-11 18:14:06 +01:00
|
|
|
#! /usr/bin/env bash
|
2023-06-26 05:18:41 +02:00
|
|
|
|
|
|
|
set -e
|
|
|
|
set -ux
|
|
|
|
|
2024-11-06 22:05:00 +01:00
|
|
|
seed="$(date)-$RANDOM"
|
2023-06-26 05:18:41 +02:00
|
|
|
|
2024-03-06 22:10:54 +01:00
|
|
|
log="${MAGIC_NIX_CACHE_DAEMONDIR}/daemon.log"
|
2024-01-11 18:14:06 +01:00
|
|
|
|
2024-11-06 22:05:00 +01:00
|
|
|
flakehub_binary_cache=https://cache.flakehub.com
|
|
|
|
gha_binary_cache=http://127.0.0.1:37515
|
|
|
|
|
|
|
|
is_gh_throttled() {
|
|
|
|
grep 'GitHub Actions Cache throttled Magic Nix Cache' "${log}"
|
|
|
|
}
|
2024-01-11 18:14:06 +01:00
|
|
|
|
|
|
|
# Check that the action initialized correctly.
|
2024-11-06 22:05:00 +01:00
|
|
|
if [ "$EXPECT_FLAKEHUB" == "true" ]; then
|
|
|
|
grep 'FlakeHub cache is enabled' "${log}"
|
|
|
|
grep 'Using cache' "${log}"
|
|
|
|
else
|
|
|
|
grep 'FlakeHub cache is disabled' "${log}" \
|
|
|
|
|| grep 'FlakeHub cache initialization failed:' "${log}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$EXPECT_GITHUB_CACHE" == "true" ]; then
|
|
|
|
grep 'GitHub Action cache is enabled' "${log}"
|
|
|
|
else
|
|
|
|
grep 'Native GitHub Action cache is disabled' "${log}"
|
|
|
|
fi
|
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
|
|
|
|
|
|
|
# Wait until it has been pushed succesfully.
|
2024-11-06 22:05:00 +01:00
|
|
|
if [ "$EXPECT_FLAKEHUB" == "true" ]; then
|
|
|
|
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
|
2024-01-11 18:14:06 +01:00
|
|
|
fi
|
|
|
|
|
2024-11-06 22:05:00 +01:00
|
|
|
if [ "$EXPECT_GITHUB_CACHE" == "true" ]; then
|
|
|
|
found=
|
|
|
|
for ((i = 0; i < 60; i++)); do
|
|
|
|
sleep 1
|
|
|
|
if grep "Uploaded '${outpath}' to the GitHub Action Cache" "${log}"; then
|
|
|
|
found=1
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [[ -z $found ]]; then
|
|
|
|
echo "GitHub Actions Cache push did not happen." >&2
|
|
|
|
|
|
|
|
if ! is_gh_throttled; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
2024-01-11 18:14:06 +01:00
|
|
|
|
2024-11-06 22:05:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
if [ "$EXPECT_FLAKEHUB" == "true" ]; then
|
|
|
|
# Check the FlakeHub binary cache to see if the path is really there.
|
|
|
|
nix path-info --store "${flakehub_binary_cache}" "${outpath}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$EXPECT_GITHUB_CACHE" == "true" ] && ! is_gh_throttled; then
|
|
|
|
# Check the GitHub binary cache to see if the path is really there.
|
|
|
|
nix path-info --store "${gha_binary_cache}" "${outpath}"
|
|
|
|
fi
|
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."
|
|
|
|
|
2024-11-06 22:05:00 +01:00
|
|
|
if [ "$EXPECT_FLAKEHUB" == "true" ]; then
|
|
|
|
# Check the FlakeHub binary cache to see if the path is really there.
|
|
|
|
nix path-info --store "${flakehub_binary_cache}" "${outpath}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$EXPECT_GITHUB_CACHE" == "true" ] && ! is_gh_throttled; then
|
|
|
|
# Check the FlakeHub binary cache to see if the path is really there.
|
|
|
|
nix path-info --store "${gha_binary_cache}" "${outpath}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ([ "$EXPECT_GITHUB_CACHE" == "true" ] && ! is_gh_throttled) || [ "$EXPECT_FLAKEHUB" == "true" ]; then
|
|
|
|
nix-store --realize -vvvvvvvv "$outpath"
|
|
|
|
fi
|