From 158d9c043ed55091f99fcb20c8a18dde407a01d7 Mon Sep 17 00:00:00 2001 From: Bruno Alexandre Rosa <1791393+brunoalr@users.noreply.github.com> Date: Sat, 14 Mar 2026 18:29:28 -0300 Subject: [PATCH] chore: add ccache report workflow --- .ci/gh_buildkit_cache_usage.sh | 41 ++++++++++++++++++++++++++++++ .github/workflows/cache-report.yml | 33 ++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100755 .ci/gh_buildkit_cache_usage.sh create mode 100644 .github/workflows/cache-report.yml diff --git a/.ci/gh_buildkit_cache_usage.sh b/.ci/gh_buildkit_cache_usage.sh new file mode 100755 index 000000000..728fa87af --- /dev/null +++ b/.ci/gh_buildkit_cache_usage.sh @@ -0,0 +1,41 @@ +#!/bin/bash +# Reports total count and size of GitHub Actions caches whose key starts with a given prefix. +# Used for BuildKit GHA cache (keys like buildkit-blob-1-sha256:...). +# +# Requires: gh (GitHub CLI), jq +# Run from repo root with gh auth login already done (or GITHUB_TOKEN set in CI). +# +# Usage: .ci/gh_buildkit_cache_usage.sh [key-prefix] +# Default key-prefix: buildkit-blob +# +# Example: .ci/gh_buildkit_cache_usage.sh +# Example: .ci/gh_buildkit_cache_usage.sh buildkit-blob + +set -eo pipefail + +KEY_PREFIX="${1:-buildkit-blob}" +LIMIT=1000 + +if ! command -v gh &>/dev/null; then + echo "Error: gh (GitHub CLI) is required. Install from https://cli.github.com/" >&2 + exit 1 +fi +if ! command -v jq &>/dev/null; then + echo "Error: jq is required. Install with: brew install jq" >&2 + exit 1 +fi + +json=$(gh cache list --key "$KEY_PREFIX" --limit "$LIMIT" --json key,sizeInBytes 2>/dev/null) || { + echo "Error: gh cache list failed (check gh auth or repo access)" >&2 + exit 1 +} + +count=$(echo "$json" | jq 'length') +total_bytes=$(echo "$json" | jq 'map(.sizeInBytes) | add // 0') + +# Human-readable size (GiB, 2 decimals) +total_gib=$(echo "$total_bytes" | jq -r '. / 1024 / 1024 / 1024 | . * 100 | floor / 100') + +echo "Cache key prefix: $KEY_PREFIX" +echo "Entries: $count" +echo "Total size: $total_bytes bytes ($total_gib GiB)" diff --git a/.github/workflows/cache-report.yml b/.github/workflows/cache-report.yml new file mode 100644 index 000000000..eb3d4c976 --- /dev/null +++ b/.github/workflows/cache-report.yml @@ -0,0 +1,33 @@ +# Reports total GitHub Actions cache usage for BuildKit blob caches (used by docker-release). +# Run locally: .ci/gh_buildkit_cache_usage.sh + +name: Cache usage report + +on: + schedule: + # Mondays 09:00 UTC + - cron: '0 9 * * 1' + workflow_dispatch: + +jobs: + report: + name: buildkit-blob cache usage + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + + steps: + - name: Checkout + uses: actions/checkout@v6 + + - name: Install jq + run: sudo apt-get update && sudo apt-get install -y jq + + - name: Report cache usage + id: cache_report + run: | + ./.ci/gh_buildkit_cache_usage.sh buildkit-blob | tee report.txt + echo "summary<> "$GITHUB_STEP_SUMMARY" + cat report.txt >> "$GITHUB_STEP_SUMMARY" + echo "EOF" >> "$GITHUB_STEP_SUMMARY"