Path: blob/trunk/scripts/github-actions/disk-status.sh
10192 views
#!/usr/bin/env bash1#2# Print a disk-status snapshot for use as a CI checkpoint:3# Also exports AVAIL_GB (available space in GB45echo "=== Disk space ==="6df -h "$GITHUB_WORKSPACE" || true7if [[ "$RUNNER_OS" == "Windows" ]]; then df -h /c || true; fi89# On Windows the workspace is on D: but C: is the constrained drive10if [[ "$RUNNER_OS" == "Windows" ]]; then11AVAIL_GB=$(df -k /c | awk 'NR==2 {printf "%.0f", $4/1024/1024}')12else13AVAIL_GB=$(df -k "$GITHUB_WORKSPACE" | awk 'NR==2 {printf "%.0f", $4/1024/1024}')14fi15if ! [[ "$AVAIL_GB" =~ ^[0-9]+$ ]]; then16echo "::error::Could not determine available disk space (got: '${AVAIL_GB}')"17AVAIL_GB=018fi19export AVAIL_GB20echo "Available: ${AVAIL_GB}GB"2122if [[ "$RUNNER_OS" == "Windows" ]]; then23external="/d/b/external"24repos="/d/b-repo"25bazelisk="/c/Users/runneradmin/AppData/Local/bazelisk"26else27external="$HOME/.bazel/external"28repos="$HOME/.cache/bazel-repo"29bazelisk="$HOME/.cache/bazelisk"30fi3132echo "=== Bazel cache sizes ==="33cache_size() {34local label="$1" path="$2"35if [ -d "$path" ]; then36local size37size=$(du -sh "$path" 2>/dev/null | awk '{print $1}')38printf " %-25s %s\n" "${label}:" "$size"39else40printf " %-25s (not present)\n" "${label}:"41fi42}43cache_size "External" "$external"44if [ -d "$repos" ]; then45for sub in "$repos"/*/; do46[ -d "$sub" ] || continue47case "$(basename "$sub")" in48content_addressable) label="Repository Cache" ;;49contents) label="Repo Contents Cache" ;;50*) label="Repository/$(basename "$sub")" ;;51esac52cache_size "$label" "$sub"53done54else55cache_size "Repository Cache" "$repos"56fi57cache_size "Bazelisk" "$bazelisk"585960