name: 'Show Cache Stats' description: 'Displays statistics for ccache and Bazel remote cache to help analyze cache performance and hit rates' inputs: clear_stats: description: 'Whether to clear ccache stats after displaying (default: true)' required: true type: boolean default: true runs: using: 'composite' steps: - name: Define cache summary helper shell: bash working-directory: ${{ github.workspace }} run: | set -euo pipefail echo "🔍 DEBUG: cache-stats action started" echo "🔍 DEBUG: inputs.clear_stats=${{ inputs.clear_stats }}" echo "🔍 DEBUG: github.workspace=${{ github.workspace }}" cat > /tmp/cache_summary.sh <<'EOF' summarize_dir() { local path="$1" local top_n=${2:-10} local sub_n=${3:-5} if [ ! -e "$path" ]; then echo "Path $path not found" return fi echo "---------------" echo "Summary: $path" du -sh "$path" || true echo "Top ${top_n} entries at top level:" du -h --max-depth=1 "$path" 2>/dev/null | sort -hr | head -n "$top_n" || true echo "Showing up to ${sub_n} entries one level deeper for the largest top-level items:" while read -r line; do entry_path=$(echo "$line" | awk '{print $2}') [ -z "$entry_path" ] && continue if [ "$entry_path" = "$path" ]; then continue fi echo "-> $entry_path :" du -h --max-depth=1 "$entry_path" 2>/dev/null | sort -hr | head -n "$sub_n" || true done < <(du -h --max-depth=1 "$path" 2>/dev/null | sort -hr | head -n "$top_n") echo "---------------" } EOF - name: Show ccache Stats shell: bash working-directory: ${{ github.workspace }} run: | set -euo pipefail echo "====================" echo "=== ccache stats ===" echo "====================" echo "🔍 DEBUG: Starting ccache stats collection" if ! command -v ccache >/dev/null 2>&1; then echo "🔍 DEBUG: ccache command not found" echo "⚠️ ccache not installed, skipping ccache stats" echo "====================" exit 0 fi echo "🔍 DEBUG: ccache command found at: $(which ccache)" # Get ccache version CCACHE_VERSION=$(ccache --version | head -1) echo "🔍 DEBUG: ccache version: $CCACHE_VERSION" # Check ccache directory echo "🔍 DEBUG: Checking ccache directory: /home/runner/.ccache" if [ -d /home/runner/.ccache ]; then echo "🔍 DEBUG: ccache directory exists" echo "🔍 DEBUG: ccache directory size: $(du -sh /home/runner/.ccache 2>/dev/null | cut -f1)" echo "🔍 DEBUG: ccache directory file count: $(find /home/runner/.ccache -type f 2>/dev/null | wc -l)" else echo "🔍 DEBUG: ccache directory does NOT exist" fi echo "🔍 DEBUG: Running ccache -s (statistics)" ccache -s || true echo "🔍 DEBUG: ccache -s completed" echo "=====================" echo "=== ccache config ===" echo "=====================" echo "🔍 DEBUG: Running ccache -p (config)" ccache -p || true echo "🔍 DEBUG: ccache -p completed" echo "=====================" echo "🔍 DEBUG: Running ccache -s for stats parsing" STATS="$(ccache -s)" echo "🔍 DEBUG: Raw ccache stats captured" echo "🔍 DEBUG: Parsing ccache statistics" echo "🔍 DEBUG: Raw STATS (first 10 lines):" echo "$STATS" | head -n 10 CACHEABLE=$(echo "$STATS" | awk '/Cacheable calls:/ { match($0, /[0-9]+/); print substr($0, RSTART, RLENGTH) }' | head -n1) echo "🔍 DEBUG: CACHEABLE=$CACHEABLE" HITS=$(echo "$STATS" | awk '/^[[:space:]]*Hits:/ { match($0, /[0-9]+/); print substr($0, RSTART, RLENGTH) }' | head -n1) echo "🔍 DEBUG: HITS=$HITS" DIRECT=$(echo "$STATS" | awk '/Direct:/ { match($0, /[0-9]+/); print substr($0, RSTART, RLENGTH) }' | head -n1) echo "🔍 DEBUG: DIRECT=$DIRECT" echo "🔍 DEBUG: Calculating hit rates" echo "🔍 DEBUG: CACHEABLE=${CACHEABLE:-0}, HITS=${HITS:-0}, DIRECT=${DIRECT:-0}" if [ "${CACHEABLE:-0}" -gt 0 ]; then HIT_RATE=$(awk -v h="${HITS:-0}" -v c="$CACHEABLE" 'BEGIN{printf "%.1f", (h/c)*100}') DIRECT_RATE=$(awk -v d="${DIRECT:-0}" -v c="$CACHEABLE" 'BEGIN{printf "%.1f", (d/c)*100}') echo "🔍 DEBUG: Calculated HIT_RATE=$HIT_RATE%, DIRECT_RATE=$DIRECT_RATE%" else HIT_RATE="0.0" DIRECT_RATE="0.0" echo "🔍 DEBUG: CACHEABLE is 0, setting rates to 0.0%" fi echo "hit_rate=${HIT_RATE}%" echo "direct_rate=${DIRECT_RATE}%" echo "🔍 DEBUG: Hit rates output complete" echo "🔍 DEBUG: clear_stats check: ${{ inputs.clear_stats }}" if [ "${{ inputs.clear_stats }}" = "true" ]; then echo "🔍 DEBUG: Clearing ccache stats (ccache -z)" echo "=== ccache reset ===" echo "=====================" ccache -z || true echo "🔍 DEBUG: ccache -z completed" echo "=====================" # Touch all files to prevent LRU eviction of freshly restored cache echo "🔍 DEBUG: Checking if ccache directory needs atime update" if [ -d /home/runner/.ccache ] && find /home/runner/.ccache -type f -print -quit 2>/dev/null | grep -q .; then echo "🔍 DEBUG: ccache directory has files, updating atime" echo "Updating ccache atime to prevent cache eviction..." echo "🔍 DEBUG: Executing find touch command for ccache files" find /home/runner/.ccache -type f -exec touch -t $(date -d "1 day ago" +%Y%m%d%H%M) {} + echo "✅ ccache atime updated" echo "🔍 DEBUG: ccache atime update completed" else echo "🔍 DEBUG: Skipping ccache atime update (directory empty or missing)" fi else echo "🔍 DEBUG: clear_stats is false, keeping ccache stats for next run" echo "Keeping ccache stats for next run" fi echo "🔍 DEBUG: ccache stats section complete" - name: Show ccache folder Stats shell: bash working-directory: ${{ github.workspace }} run: | set -euo pipefail echo "🔍 DEBUG: ccache folder stats section started" # shellcheck disable=SC1091 source /tmp/cache_summary.sh echo "🔍 DEBUG: cache_summary.sh loaded successfully" echo "🔍 DEBUG: Calling summarize_dir for /home/runner/.ccache with top_n=10, sub_n=5" echo "===============" echo "=== .ccache ===" echo "===============" summarize_dir /home/runner/.ccache 10 5 || true echo "🔍 DEBUG: ccache folder stats section complete" - name: Show Bazel Cache folder Stats shell: bash working-directory: ${{ github.workspace }} run: | set -euo pipefail echo "🔍 DEBUG: Bazel cache folder stats section started" # shellcheck disable=SC1091 source /tmp/cache_summary.sh echo "🔍 DEBUG: cache_summary.sh loaded successfully" echo "🔍 DEBUG: Calling summarize_dir for /home/runner/.cache/bazel with top_n=10, sub_n=5" echo "====================" echo "=== .cache/bazel ===" echo "====================" summarize_dir /home/runner/.cache/bazel 10 5 || true echo "🔍 DEBUG: Bazel cache folder stats section complete" echo "🔍 DEBUG: cache-stats action finished successfully"