Skip already-cached packages in CI build-and-cache job
All checks were successful
CI / check (pull_request) Successful in 5m26s
CI / build-and-cache (pull_request) Has been skipped

This commit is contained in:
mayor
2026-02-14 18:15:36 -08:00
committed by John Ogle
parent 3ece063a6a
commit acd9d8d70f

View File

@@ -56,9 +56,20 @@ jobs:
) )
FAILED=() FAILED=()
SKIPPED=()
for pkg in "${PACKAGES[@]}"; do for pkg in "${PACKAGES[@]}"; do
echo "::group::Building $pkg" echo "::group::Building $pkg"
# Capture build output, extract store path (last line starting with /nix/store/)
# Check if package is already cached by evaluating its store path and checking the remote
OUT_PATH=$(nix build ".#$pkg" --no-link --print-out-paths --dry-run 2>/dev/null | grep '^/nix/store/' | tail -1)
if [ -n "$OUT_PATH" ] && ssh -i ~/.ssh/cache_key ${{ secrets.CACHE_USER }}@${{ secrets.CACHE_HOST }} \
"nix path-info '$OUT_PATH' >/dev/null 2>&1"; then
echo "⏭ $pkg already cached ($OUT_PATH), skipping"
SKIPPED+=("$pkg")
echo "::endgroup::"
continue
fi
# --cores 2 limits parallel jobs to reduce RAM pressure on john-endesktop # --cores 2 limits parallel jobs to reduce RAM pressure on john-endesktop
if BUILD_OUTPUT=$(nix build ".#$pkg" --no-link --print-out-paths --cores 2 2>&1); then if BUILD_OUTPUT=$(nix build ".#$pkg" --no-link --print-out-paths --cores 2 2>&1); then
OUT_PATH=$(echo "$BUILD_OUTPUT" | grep '^/nix/store/' | tail -1) OUT_PATH=$(echo "$BUILD_OUTPUT" | grep '^/nix/store/' | tail -1)
@@ -84,6 +95,10 @@ jobs:
echo "::endgroup::" echo "::endgroup::"
done done
if [ ${#SKIPPED[@]} -gt 0 ]; then
echo "Skipped (already cached): ${SKIPPED[*]}"
fi
if [ ${#FAILED[@]} -gt 0 ]; then if [ ${#FAILED[@]} -gt 0 ]; then
echo "::error::Failed packages: ${FAILED[*]}" echo "::error::Failed packages: ${FAILED[*]}"
exit 1 exit 1