Skip to content

Commit 0e9f3d5

Browse files
committed
Add back some testing
1 parent 91ece0e commit 0e9f3d5

File tree

3 files changed

+157
-1
lines changed

3 files changed

+157
-1
lines changed

.github/workflows/cache-test.sh

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#! /usr/bin/env bash
2+
3+
set -e
4+
set -ux
5+
6+
seed="$(date)-$RANDOM"
7+
8+
log="${MAGIC_NIX_CACHE_DAEMONDIR}/daemon.log"
9+
10+
flakehub_binary_cache=https://cache.flakehub.com
11+
gha_binary_cache=http://127.0.0.1:37515
12+
13+
is_gh_throttled() {
14+
grep 'GitHub Actions Cache throttled Magic Nix Cache' "${log}"
15+
}
16+
17+
# Check that the action initialized correctly.
18+
grep 'FlakeHub cache is enabled' "${log}"
19+
grep 'Using cache' "${log}"
20+
21+
if [ "$EXPECT_GITHUB_CACHE" == "true" ]; then
22+
grep 'GitHub Action cache is enabled' "${log}"
23+
else
24+
grep 'Native GitHub Action cache is disabled' "${log}"
25+
fi
26+
27+
# Build something.
28+
outpath=$(nix-build .github/workflows/cache-tester.nix --argstr seed "$seed")
29+
30+
# Wait until it has been pushed succesfully.
31+
found=
32+
for ((i = 0; i < 60; i++)); do
33+
sleep 1
34+
if grep "$(basename "${outpath}")" "${log}"; then
35+
found=1
36+
break
37+
fi
38+
done
39+
if [[ -z $found ]]; then
40+
echo "FlakeHub push did not happen." >&2
41+
exit 1
42+
fi
43+
44+
if [ "$EXPECT_GITHUB_CACHE" == "true" ]; then
45+
found=
46+
for ((i = 0; i < 60; i++)); do
47+
sleep 1
48+
if grep "Uploaded '${outpath}' to the GitHub Action Cache" "${log}"; then
49+
found=1
50+
break
51+
fi
52+
done
53+
if [[ -z $found ]]; then
54+
echo "GitHub Actions Cache push did not happen." >&2
55+
56+
if ! is_gh_throttled; then
57+
exit 1
58+
fi
59+
fi
60+
fi
61+
62+
63+
64+
# Check the FlakeHub binary cache to see if the path is really there.
65+
nix path-info --store "${flakehub_binary_cache}" "${outpath}"
66+
67+
if [ "$EXPECT_GITHUB_CACHE" == "true" ] && ! is_gh_throttled; then
68+
# Check the GitHub binary cache to see if the path is really there.
69+
nix path-info --store "${gha_binary_cache}" "${outpath}"
70+
fi
71+
72+
rm ./result
73+
nix store delete "${outpath}"
74+
if [ -f "$outpath" ]; then
75+
echo "$outpath still exists? can't test"
76+
exit 1
77+
fi
78+
79+
rm -rf ~/.cache/nix
80+
81+
echo "-------"
82+
echo "Trying to substitute the build again..."
83+
echo "if it fails, the cache is broken."
84+
85+
# Check the FlakeHub binary cache to see if the path is really there.
86+
nix path-info --store "${flakehub_binary_cache}" "${outpath}"
87+
88+
if [ "$EXPECT_GITHUB_CACHE" == "true" ] && ! is_gh_throttled; then
89+
# Check the FlakeHub binary cache to see if the path is really there.
90+
nix path-info --store "${gha_binary_cache}" "${outpath}"
91+
fi
92+
93+
nix-store --realize -vvvvvvvv "$outpath"

.github/workflows/cache-tester.nix

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{ seed }:
2+
derivation {
3+
name = "cache-test";
4+
system = builtins.currentSystem;
5+
6+
builder = "/bin/sh";
7+
args = [ "-euxc" "echo \"$seed\" > $out" ];
8+
9+
inherit seed;
10+
}

.github/workflows/ci.yml

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,45 @@ on:
44
branches: [main]
55

66
jobs:
7-
success:
7+
run-systems:
8+
if: github.event_name == 'merge_group'
9+
name: "Test: ${{ matrix.systems.nix-system }}"
10+
runs-on: "${{ matrix.systems.runner }}"
11+
permissions:
12+
id-token: "write"
13+
contents: "read"
14+
env:
15+
ACTIONS_STEP_DEBUG: true
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
systems:
20+
- nix-system: "aarch64-darwin"
21+
runner: "macos-latest"
22+
- nix-system: "x86_64-darwin"
23+
runner: "macos-13"
24+
- nix-system: "aarch64-linux"
25+
runner: "namespace-profile-default-arm64"
26+
- nix-system: "x86_64-linux"
27+
runner: "ubuntu-22.04"
28+
steps:
29+
- uses: actions/checkout@v4
30+
- name: Install Nix on ${{ matrix.systems.nix-system }} system
31+
uses: DeterminateSystems/determinate-nix-action@main
32+
with:
33+
extra-conf: |
34+
narinfo-cache-negative-ttl = 0
35+
- name: Cache the store
36+
uses: ./
37+
with:
38+
_internal-strict-mode: true
39+
- name: Check the cache for liveness
40+
env:
41+
EXPECT_GITHUB_CACHE: ${{ toJson(false) }}
42+
run: |
43+
.github/workflows/cache-test.sh
44+
45+
lint:
846
name: Build
947
runs-on: ubuntu-latest
1048
permissions:
@@ -27,3 +65,18 @@ jobs:
2765
- name: Assert no changes were made
2866
run: git diff --exit-code
2967
if: success() || failure()
68+
69+
success:
70+
runs-on: ubuntu-latest
71+
needs:
72+
- run-systems
73+
- lint
74+
if: always()
75+
steps:
76+
- run: "true"
77+
- run: |
78+
echo "A dependent in the build matrix failed."
79+
exit 1
80+
if: |
81+
contains(needs.*.result, 'failure') ||
82+
contains(needs.*.result, 'cancelled')

0 commit comments

Comments
 (0)