Path: blob/trunk/scripts/github-actions/disk-status.sh
11810 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" || true7# Also show the Windows system drive (C:) for reference. The build runs on the8# workspace drive (D: on Windows, / on Linux), so that is what we measure below.9if [[ "$RUNNER_OS" == "Windows" ]]; then df -h /c || true; fi1011# Available space on the drive the build actually uses (the workspace).12AVAIL_GB=$(df -k "$GITHUB_WORKSPACE" | awk 'NR==2 {printf "%.0f", $4/1024/1024}')13if ! [[ "$AVAIL_GB" =~ ^[0-9]+$ ]]; then14echo "::error::Could not determine available disk space (got: '${AVAIL_GB}')"15AVAIL_GB=016fi17export AVAIL_GB18echo "Available: ${AVAIL_GB}GB"1920if [[ "$RUNNER_OS" == "Windows" ]]; then21external="/d/b/external"22repos="/d/b-repo"23bazelisk="/c/Users/runneradmin/AppData/Local/bazelisk"24else25external="$HOME/.bazel/external"26repos="$HOME/.cache/bazel-repo"27bazelisk="$HOME/.cache/bazelisk"28fi2930echo "=== Bazel cache sizes ==="31cache_size() {32local label="$1" path="$2"33if [ -d "$path" ]; then34local size35size=$(du -sh "$path" 2>/dev/null | awk '{print $1}')36printf " %-25s %s\n" "${label}:" "$size"37else38printf " %-25s (not present)\n" "${label}:"39fi40}41cache_size "External" "$external"42if [ -d "$repos" ]; then43for sub in "$repos"/*/; do44[ -d "$sub" ] || continue45case "$(basename "$sub")" in46content_addressable) label="Repository Cache" ;;47contents) label="Repo Contents Cache" ;;48*) label="Repository/$(basename "$sub")" ;;49esac50cache_size "$label" "$sub"51done52else53cache_size "Repository Cache" "$repos"54fi55cache_size "Bazelisk" "$bazelisk"565758