#!/usr/bin/env sh # Fetch the build.zig.zon dependency tree with backoff. zig gives up on the # first failed download, and the tangled.org archive endpoint rate-limits, so a # cold cache could fail a pipeline before any check ran. A download can also # stall without failing, which once held a deploy for 25 minutes, so each # attempt is cut off and retried. Lazy dependencies (hegel, for the # property campaigns) are fetched too, so the cache keeps them. set -eu zig="${ZIG:-.ci-cache/zig/zig}" attempt_timeout="${FETCH_ATTEMPT_TIMEOUT:-300}" attempt=1 delay=5 while ! timeout "$attempt_timeout" "$zig" build --fetch=all; do if [ "$attempt" -ge 6 ]; then echo "dependency fetch failed after $attempt attempts" >&2 exit 1 fi echo "dependency fetch failed (attempt $attempt); retrying in ${delay}s" >&2 sleep "$delay" attempt=$((attempt + 1)) delay=$((delay * 2)) done # The global cache keeps every package archive it has fetched, and CI saves it # between runs, so it grows with each dependency change until the spindle's # cache quota refuses to save it. Keep only what this checkout uses. global="${ZIG_GLOBAL_CACHE_DIR:-}" if [ -n "$global" ] && [ -d "$global/p" ] && [ -d zig-pkg ]; then kept=0 removed=0 for entry in "$global"/p/*; do [ -e "$entry" ] || continue name=$(basename "$entry" .tar.gz) if [ -e "zig-pkg/$name" ]; then kept=$((kept + 1)); else rm -rf "$entry"; removed=$((removed + 1)); fi done echo "package cache: kept $kept, removed $removed" fi