11
11
description : ' Commit SHA to build'
12
12
required : true
13
13
type : string
14
+ wipe_cache :
15
+ description : ' Wipe /tmp/rust-cache before build'
16
+ required : false
17
+ type : boolean
18
+ default : false
14
19
15
20
env :
16
21
AWS_REGION : " eu-central-1"
@@ -45,17 +50,81 @@ jobs:
45
50
run : |
46
51
set -e
47
52
echo "--- Restoring Rust cache from host ---"
48
- if [ -d /tmp/rust-cache ]; then
49
- echo "Rust cache found. Restoring..."
53
+ if [ -d /tmp/rust-cache ] && [ -f /tmp/rust-cache/.ready ] ; then
54
+ echo "Ready cache found. Restoring..."
50
55
mkdir -p ~/.cargo/git ~/.cargo/registry ./target
51
56
nix shell nixpkgs#rsync -c bash -c "
52
57
rsync -a /tmp/rust-cache/cargo-git/ ~/.cargo/git/
53
58
rsync -a /tmp/rust-cache/cargo-registry/ ~/.cargo/registry/
54
59
rsync -a /tmp/rust-cache/target/ ./target/
55
60
"
56
61
else
57
- echo "No Rust cache found. Will be created after build ."
62
+ echo "No ready cache; skipping restore ."
58
63
fi
64
+ - name : Validate Rust cache
65
+ run : |
66
+ set -euo pipefail
67
+ CACHE=/tmp/rust-cache
68
+ CARGO_HOME="${CARGO_HOME:-$HOME/.cargo}"
69
+ TARGET_DIR="${CARGO_TARGET_DIR:-$GITHUB_WORKSPACE/target}"
70
+ [[ -d "$CACHE" ]] || { echo "No shared cache present."; exit 0; }
71
+
72
+ echo "--- Cache preflight ---"
73
+ RUSTC="$(nix develop -c rustc -vV 2>/dev/null || rustc -vV)"
74
+ LOCK_SHA="$(sha256sum Cargo.lock | cut -d' ' -f1)"
75
+ MAN="$CACHE/.manifest"; READY="$CACHE/.ready"
76
+ WANT="$(printf '%s\n%s\n' "$RUSTC" "$LOCK_SHA")"
77
+
78
+ BAD=0; REASONS=()
79
+
80
+ echo "[1/4] Checking manifest and ready marker..."
81
+ if [[ ! -f "$READY" || ! -f "$MAN" ]]; then
82
+ echo "manifest/ready missing"
83
+ BAD=1; REASONS+=("manifest/ready missing")
84
+ else
85
+ HAVE="$(head -n 2 "$MAN" || true)"
86
+ if [[ "$WANT" != "$HAVE" ]]; then
87
+ echo "manifest/ready mismatch"
88
+ BAD=1; REASONS+=("manifest mismatch")
89
+ fi
90
+ fi
91
+
92
+ echo "[2/4] Scanning for broken symlinks..."
93
+ if find "$CARGO_HOME" "$TARGET_DIR" -xtype l -print -quit >/dev/null 2>&1; then
94
+ echo "Broken symlink detected:"
95
+ find "$CARGO_HOME" "$TARGET_DIR" -xtype l -print 2>/dev/null | head -5 || true
96
+ BAD=1; REASONS+=("broken symlink(s)")
97
+ fi
98
+
99
+ echo "[3/4] Scanning for zero-byte files..."
100
+ if find "$CARGO_HOME" "$TARGET_DIR" -type f -size 0 -print -quit >/dev/null 2>&1; then
101
+ echo "Zero-byte file detected:"
102
+ find "$CARGO_HOME" "$TARGET_DIR" -type f -size 0 -print 2>/dev/null | head -5 || true
103
+ BAD=1; REASONS+=("zero-byte file(s)")
104
+ fi
105
+
106
+ echo "[4/4] Running cargo fetch integrity check..."
107
+ if ! nix develop -c cargo fetch --locked -q; then
108
+ echo "cargo fetch failed"
109
+ BAD=1; REASONS+=("cargo fetch failed")
110
+ fi
111
+
112
+ if [[ $BAD -eq 1 ]]; then
113
+ echo "--- Purging suspect parts of cache ---"
114
+ if [[ ${#REASONS[@]} -gt 1 ]]; then
115
+ echo "Multiple issues (${REASONS[*]}) : removing entire target/"
116
+ rm -rf "$TARGET_DIR" || true
117
+ else
118
+ echo "Single issue (${REASONS[*]}) : purging build dirs"
119
+ find "$TARGET_DIR" -type d -name build -prune -exec rm -rf {} + || true
120
+ fi
121
+ echo "Clearing registry/src and git/checkouts..."
122
+ rm -rf "$CARGO_HOME"/registry/src/* "$CARGO_HOME"/git/checkouts/* || true
123
+ else
124
+ echo "Cache looks healthy."
125
+ fi
126
+
127
+ echo "--- Preflight summary : ${REASONS[*]:-OK} ---"
59
128
- name : Release cache lock
60
129
if : always()
61
130
run : rmdir /tmp/rust-cache.lock
@@ -82,18 +151,21 @@ jobs:
82
151
sleep 5
83
152
done
84
153
- name : Save Rust cache to host
85
- if : always()
86
154
run : |
87
155
set -e
88
156
echo "--- Saving Rust cache to host cache ---"
89
157
mkdir -p /tmp/rust-cache
90
158
nix shell nixpkgs#rsync -c bash -c "
91
- rsync -a ~/.cargo/git/ /tmp/rust-cache/cargo-git/
92
- rsync -a ~/.cargo/registry/ /tmp/rust-cache/cargo-registry/
93
- rsync -a ./target/ /tmp/rust-cache/target/
159
+ rsync -a --delete ~/.cargo/git/ /tmp/rust-cache/cargo-git/
160
+ rsync -a --delete ~/.cargo/registry/ /tmp/rust-cache/cargo-registry/
161
+ rsync -a --delete ./target/ /tmp/rust-cache/target/
94
162
"
95
163
echo "--- Verifying cache contents ---"
96
164
ls -laR /tmp/rust-cache
165
+ RUSTC="$(nix develop -c rustc -vV 2>/dev/null || rustc -vV)"
166
+ LOCK_SHA="$(sha256sum Cargo.lock | cut -d' ' -f1)"
167
+ printf '%s\n%s\n' "$RUSTC" "$LOCK_SHA" > /tmp/rust-cache/.manifest
168
+ touch /tmp/rust-cache/.ready
97
169
- name : Release cache lock
98
170
if : always()
99
171
run : rmdir /tmp/rust-cache.lock
@@ -225,7 +297,7 @@ jobs:
225
297
- name : Upload chain spec artifacts to Kubernetes
226
298
uses : ./.github/actions/deploy/upload-chain-specs
227
299
with :
228
- sha : ${{ needs.build-linux-x86_64-pre-merge.outputs .sha }}
300
+ sha : ${{ github .sha }}
229
301
env :
230
302
kubeconfig_base64 : ${{ secrets.kubeconfig_base64 }}
231
303
K8S_SERVER : ${{ secrets.K8S_SERVER }}
@@ -278,17 +350,81 @@ jobs:
278
350
run : |
279
351
set -e
280
352
echo "--- Restoring Rust cache from host ---"
281
- if [ -d /tmp/rust-cache ]; then
282
- echo "Rust cache found. Restoring..."
353
+ if [ -d /tmp/rust-cache ] && [ -f /tmp/rust-cache/.ready ] ; then
354
+ echo "Ready cache found. Restoring..."
283
355
mkdir -p ~/.cargo/git ~/.cargo/registry ./target
284
356
nix shell nixpkgs#rsync -c bash -c "
285
357
rsync -a /tmp/rust-cache/cargo-git/ ~/.cargo/git/
286
358
rsync -a /tmp/rust-cache/cargo-registry/ ~/.cargo/registry/
287
359
rsync -a /tmp/rust-cache/target/ ./target/
288
360
"
289
361
else
290
- echo "No Rust cache found. Will be created after build."
362
+ echo "No ready cache; skipping restore."
363
+ fi
364
+ - name : Validate Rust cache
365
+ run : |
366
+ set -euo pipefail
367
+ CACHE=/tmp/rust-cache
368
+ CARGO_HOME="${CARGO_HOME:-$HOME/.cargo}"
369
+ TARGET_DIR="${CARGO_TARGET_DIR:-$GITHUB_WORKSPACE/target}"
370
+ [[ -d "$CACHE" ]] || { echo "No shared cache present."; exit 0; }
371
+
372
+ echo "--- Cache preflight ---"
373
+ RUSTC="$(nix develop -c rustc -vV 2>/dev/null || rustc -vV)"
374
+ LOCK_SHA="$(sha256sum Cargo.lock | cut -d' ' -f1)"
375
+ MAN="$CACHE/.manifest"; READY="$CACHE/.ready"
376
+ WANT="$(printf '%s\n%s\n' "$RUSTC" "$LOCK_SHA")"
377
+
378
+ BAD=0; REASONS=()
379
+
380
+ echo "[1/4] Checking manifest and ready marker..."
381
+ if [[ ! -f "$READY" || ! -f "$MAN" ]]; then
382
+ echo "manifest/ready missing"
383
+ BAD=1; REASONS+=("manifest/ready missing")
384
+ else
385
+ HAVE="$(head -n 2 "$MAN" || true)"
386
+ if [[ "$WANT" != "$HAVE" ]]; then
387
+ echo "manifest/ready mismatch"
388
+ BAD=1; REASONS+=("manifest mismatch")
389
+ fi
390
+ fi
391
+
392
+ echo "[2/4] Scanning for broken symlinks..."
393
+ if find "$CARGO_HOME" "$TARGET_DIR" -xtype l -print -quit >/dev/null 2>&1; then
394
+ echo "Broken symlink detected:"
395
+ find "$CARGO_HOME" "$TARGET_DIR" -xtype l -print 2>/dev/null | head -5 || true
396
+ BAD=1; REASONS+=("broken symlink(s)")
397
+ fi
398
+
399
+ echo "[3/4] Scanning for zero-byte files..."
400
+ if find "$CARGO_HOME" "$TARGET_DIR" -type f -size 0 -print -quit >/dev/null 2>&1; then
401
+ echo "Zero-byte file detected:"
402
+ find "$CARGO_HOME" "$TARGET_DIR" -type f -size 0 -print 2>/dev/null | head -5 || true
403
+ BAD=1; REASONS+=("zero-byte file(s)")
404
+ fi
405
+
406
+ echo "[4/4] Running cargo fetch integrity check..."
407
+ if ! nix develop -c cargo fetch --locked -q; then
408
+ echo "cargo fetch failed"
409
+ BAD=1; REASONS+=("cargo fetch failed")
410
+ fi
411
+
412
+ if [[ $BAD -eq 1 ]]; then
413
+ echo "--- Purging suspect parts of cache ---"
414
+ if [[ ${#REASONS[@]} -gt 1 ]]; then
415
+ echo "Multiple issues (${REASONS[*]}) : removing entire target/"
416
+ rm -rf "$TARGET_DIR" || true
417
+ else
418
+ echo "Single issue (${REASONS[*]}) : purging build dirs"
419
+ find "$TARGET_DIR" -type d -name build -prune -exec rm -rf {} + || true
420
+ fi
421
+ echo "Clearing registry/src and git/checkouts..."
422
+ rm -rf "$CARGO_HOME"/registry/src/* "$CARGO_HOME"/git/checkouts/* || true
423
+ else
424
+ echo "Cache looks healthy."
291
425
fi
426
+
427
+ echo "--- Preflight summary : ${REASONS[*]:-OK} ---"
292
428
- name : Release cache lock
293
429
if : always()
294
430
run : rmdir /tmp/rust-cache.lock
@@ -339,18 +475,21 @@ jobs:
339
475
sleep 5
340
476
done
341
477
- name : Save Rust cache to host
342
- if : always()
343
478
run : |
344
479
set -e
345
480
echo "--- Saving Rust cache to host cache ---"
346
481
mkdir -p /tmp/rust-cache
347
482
nix shell nixpkgs#rsync -c bash -c "
348
- rsync -a ~/.cargo/git/ /tmp/rust-cache/cargo-git/
349
- rsync -a ~/.cargo/registry/ /tmp/rust-cache/cargo-registry/
350
- rsync -a ./target/ /tmp/rust-cache/target/
483
+ rsync -a --delete ~/.cargo/git/ /tmp/rust-cache/cargo-git/
484
+ rsync -a --delete ~/.cargo/registry/ /tmp/rust-cache/cargo-registry/
485
+ rsync -a --delete ./target/ /tmp/rust-cache/target/
351
486
"
352
487
echo "--- Verifying cache contents ---"
353
488
ls -laR /tmp/rust-cache
489
+ RUSTC="$(nix develop -c rustc -vV 2>/dev/null || rustc -vV)"
490
+ LOCK_SHA="$(sha256sum Cargo.lock | awk '{print $1}')"
491
+ printf '%s\n%s\n' "$RUSTC" "$LOCK_SHA" > /tmp/rust-cache/.manifest
492
+ touch /tmp/rust-cache/.ready
354
493
- name : Release cache lock
355
494
if : always()
356
495
run : rmdir /tmp/rust-cache.lock
@@ -538,6 +677,12 @@ jobs:
538
677
fetch-depth : 0
539
678
ref : ${{ inputs.sha }}
540
679
clean : true
680
+ - name : (Optional) Wipe shared Rust cache
681
+ if : github.event_name == 'workflow_dispatch' && inputs.wipe_cache == true
682
+ run : |
683
+ until mkdir /tmp/rust-cache.lock 2>/dev/null; do sleep 2; done
684
+ rm -rf /tmp/rust-cache/
685
+ rmdir /tmp/rust-cache.lock || true
541
686
- name : Acquire cache lock
542
687
run : |
543
688
until mkdir /tmp/rust-cache.lock 2>/dev/null; do
@@ -547,17 +692,81 @@ jobs:
547
692
run : |
548
693
set -e
549
694
echo "--- Restoring Rust cache from host ---"
550
- if [ -d /tmp/rust-cache ]; then
551
- echo "Rust cache found. Restoring..."
695
+ if [ -d /tmp/rust-cache ] && [ -f /tmp/rust-cache/.ready ] ; then
696
+ echo "Ready cache found. Restoring..."
552
697
mkdir -p ~/.cargo/git ~/.cargo/registry ./target
553
698
nix shell nixpkgs#rsync -c bash -c "
554
699
rsync -a /tmp/rust-cache/cargo-git/ ~/.cargo/git/
555
700
rsync -a /tmp/rust-cache/cargo-registry/ ~/.cargo/registry/
556
701
rsync -a /tmp/rust-cache/target/ ./target/
557
702
"
558
703
else
559
- echo "No Rust cache found. Will be created after build."
704
+ echo "No ready cache; skipping restore."
705
+ fi
706
+ - name : Validate Rust cache
707
+ run : |
708
+ set -euo pipefail
709
+ CACHE=/tmp/rust-cache
710
+ CARGO_HOME="${CARGO_HOME:-$HOME/.cargo}"
711
+ TARGET_DIR="${CARGO_TARGET_DIR:-$GITHUB_WORKSPACE/target}"
712
+ [[ -d "$CACHE" ]] || { echo "No shared cache present."; exit 0; }
713
+
714
+ echo "--- Cache preflight ---"
715
+ RUSTC="$(nix develop -c rustc -vV 2>/dev/null || rustc -vV)"
716
+ LOCK_SHA="$(sha256sum Cargo.lock | cut -d' ' -f1)"
717
+ MAN="$CACHE/.manifest"; READY="$CACHE/.ready"
718
+ WANT="$(printf '%s\n%s\n' "$RUSTC" "$LOCK_SHA")"
719
+
720
+ BAD=0; REASONS=()
721
+
722
+ echo "[1/4] Checking manifest and ready marker..."
723
+ if [[ ! -f "$READY" || ! -f "$MAN" ]]; then
724
+ echo "manifest/ready missing"
725
+ BAD=1; REASONS+=("manifest/ready missing")
726
+ else
727
+ HAVE="$(head -n 2 "$MAN" || true)"
728
+ if [[ "$WANT" != "$HAVE" ]]; then
729
+ echo "manifest/ready mismatch"
730
+ BAD=1; REASONS+=("manifest mismatch")
731
+ fi
560
732
fi
733
+
734
+ echo "[2/4] Scanning for broken symlinks..."
735
+ if find "$CARGO_HOME" "$TARGET_DIR" -xtype l -print -quit >/dev/null 2>&1; then
736
+ echo "Broken symlink detected:"
737
+ find "$CARGO_HOME" "$TARGET_DIR" -xtype l -print 2>/dev/null | head -5 || true
738
+ BAD=1; REASONS+=("broken symlink(s)")
739
+ fi
740
+
741
+ echo "[3/4] Scanning for zero-byte files..."
742
+ if find "$CARGO_HOME" "$TARGET_DIR" -type f -size 0 -print -quit >/dev/null 2>&1; then
743
+ echo "Zero-byte file detected:"
744
+ find "$CARGO_HOME" "$TARGET_DIR" -type f -size 0 -print 2>/dev/null | head -5 || true
745
+ BAD=1; REASONS+=("zero-byte file(s)")
746
+ fi
747
+
748
+ echo "[4/4] Running cargo fetch integrity check..."
749
+ if ! nix develop -c cargo fetch --locked -q; then
750
+ echo "cargo fetch failed"
751
+ BAD=1; REASONS+=("cargo fetch failed")
752
+ fi
753
+
754
+ if [[ $BAD -eq 1 ]]; then
755
+ echo "--- Purging suspect parts of cache ---"
756
+ if [[ ${#REASONS[@]} -gt 1 ]]; then
757
+ echo "Multiple issues (${REASONS[*]}) : removing entire target/"
758
+ rm -rf "$TARGET_DIR" || true
759
+ else
760
+ echo "Single issue (${REASONS[*]}) : purging build dirs"
761
+ find "$TARGET_DIR" -type d -name build -prune -exec rm -rf {} + || true
762
+ fi
763
+ echo "Clearing registry/src and git/checkouts..."
764
+ rm -rf "$CARGO_HOME"/registry/src/* "$CARGO_HOME"/git/checkouts/* || true
765
+ else
766
+ echo "Cache looks healthy."
767
+ fi
768
+
769
+ echo "--- Preflight summary : ${REASONS[*]:-OK} ---"
561
770
- name : Release cache lock
562
771
if : always()
563
772
run : rmdir /tmp/rust-cache.lock
@@ -584,18 +793,21 @@ jobs:
584
793
sleep 5
585
794
done
586
795
- name : Save Rust cache to host
587
- if : always()
588
796
run : |
589
797
set -e
590
798
echo "--- Saving Rust cache to host cache ---"
591
799
mkdir -p /tmp/rust-cache
592
800
nix shell nixpkgs#rsync -c bash -c "
593
- rsync -a ~/.cargo/git/ /tmp/rust-cache/cargo-git/
594
- rsync -a ~/.cargo/registry/ /tmp/rust-cache/cargo-registry/
595
- rsync -a ./target/ /tmp/rust-cache/target/
801
+ rsync -a --delete ~/.cargo/git/ /tmp/rust-cache/cargo-git/
802
+ rsync -a --delete ~/.cargo/registry/ /tmp/rust-cache/cargo-registry/
803
+ rsync -a --delete ./target/ /tmp/rust-cache/target/
596
804
"
597
805
echo "--- Verifying cache contents ---"
598
806
ls -laR /tmp/rust-cache
807
+ RUSTC="$(nix develop -c rustc -vV 2>/dev/null || rustc -vV)"
808
+ LOCK_SHA="$(sha256sum Cargo.lock | awk '{print $1}')"
809
+ printf '%s\n%s\n' "$RUSTC" "$LOCK_SHA" > /tmp/rust-cache/.manifest
810
+ touch /tmp/rust-cache/.ready
599
811
- name : Release cache lock
600
812
if : always()
601
813
run : rmdir /tmp/rust-cache.lock
@@ -696,4 +908,4 @@ jobs:
696
908
exit 1
697
909
else
698
910
echo "All needed jobs passed."
699
- fi
911
+ fi
0 commit comments