#!/usr/bin/env bash
# Install on a runner, and survive a half-written cache entry.
#
# Runners have failed twice with "Fail extracting tarball" on a different
# package each time, on different machines, and passed on a re-run. The cache
# is shared between jobs on a host, so a job that dies mid-write leaves an
# entry the next job cannot read. Clearing it and installing again costs a
# couple of minutes; a human re-running the job costs however long it takes
# someone to notice.
set -euo pipefail
if bun install --frozen-lockfile; then exit 0; fi
echo "Install failed. Clearing the bun cache and trying once more." >&2
rm -rf "${BUN_INSTALL_CACHE_DIR:-$HOME/.bun/install/cache}"
bun install --frozen-lockfile
