mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-07 05:53:59 -07:00
markdown option
This commit is contained in:
parent
a70892c110
commit
4d1a7698aa
2 changed files with 54 additions and 21 deletions
|
|
@ -1,13 +1,16 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Reports GitHub Actions cache usage, grouped by key prefix (first segment before "-" or "/") or for one prefix.
|
# Reports GitHub Actions cache usage, grouped by key prefix (first segment before "-" or "/") or for one prefix.
|
||||||
#
|
#
|
||||||
# Usage: .ci/gh_buildkit_cache_usage.sh [key-prefix]
|
# Usage: .ci/gh_buildkit_cache_usage.sh [-m|--markdown] [key-prefix]
|
||||||
# No args: all caches grouped by prefix. One arg: caches with that key prefix (default buildkit-blob).
|
# -m, --markdown output as a markdown table
|
||||||
|
# No key-prefix: all caches grouped by prefix.
|
||||||
|
# One arg: caches with that key prefix (default buildkit-blob).
|
||||||
# Requires: gh, jq
|
# Requires: gh, jq
|
||||||
|
|
||||||
set -eo pipefail
|
set -eo pipefail
|
||||||
|
|
||||||
LIMIT=1000
|
LIMIT=1000
|
||||||
|
MARKDOWN=false
|
||||||
|
|
||||||
if ! command -v gh &>/dev/null; then
|
if ! command -v gh &>/dev/null; then
|
||||||
echo "Error: gh (GitHub CLI) is required. Install from https://cli.github.com/" >&2
|
echo "Error: gh (GitHub CLI) is required. Install from https://cli.github.com/" >&2
|
||||||
|
|
@ -18,6 +21,13 @@ if ! command -v jq &>/dev/null; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
while [[ $# -gt 0 ]]; do
|
||||||
|
case "$1" in
|
||||||
|
-m|--markdown) MARKDOWN=true; shift ;;
|
||||||
|
*) break ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
if [[ $# -eq 0 ]]; then
|
if [[ $# -eq 0 ]]; then
|
||||||
# Grouped mode: all caches, group by first segment (before - or /)
|
# Grouped mode: all caches, group by first segment (before - or /)
|
||||||
json=$(gh cache list --limit "$LIMIT" --json key,sizeInBytes 2>/dev/null) || {
|
json=$(gh cache list --limit "$LIMIT" --json key,sizeInBytes 2>/dev/null) || {
|
||||||
|
|
@ -28,20 +38,35 @@ if [[ $# -eq 0 ]]; then
|
||||||
total_entries=$(echo "$json" | jq 'length')
|
total_entries=$(echo "$json" | jq 'length')
|
||||||
total_bytes=$(echo "$json" | jq 'map(.sizeInBytes) | add // 0')
|
total_bytes=$(echo "$json" | jq 'map(.sizeInBytes) | add // 0')
|
||||||
total_gib=$(echo "$total_bytes" | jq -r '. / 1024 / 1024 / 1024 | . * 100 | floor / 100')
|
total_gib=$(echo "$total_bytes" | jq -r '. / 1024 / 1024 / 1024 | . * 100 | floor / 100')
|
||||||
printf "%-12s %6s %10s\n" "PREFIX" "COUNT" "SIZE (GiB)"
|
if [[ "$MARKDOWN" == true ]]; then
|
||||||
printf "%-12s %6s %10s\n" "------------" "------" "----------"
|
echo "| PREFIX | COUNT | SIZE (GiB) |"
|
||||||
while IFS=$'\t' read -r prefix count gib; do
|
echo "|--------|------:|----------:|"
|
||||||
printf "%-12s %6s %10.2f\n" "$prefix" "$count" "$gib"
|
while IFS=$'\t' read -r prefix count gib; do
|
||||||
done < <(echo "$json" | jq -r '
|
echo "| $prefix | $count | $gib |"
|
||||||
def prefix: (if (.key | test("/")) then (.key | split("/")[0]) else (.key | split("-")[0]) end);
|
done < <(echo "$json" | jq -r '
|
||||||
def to_gib: . / 1024 / 1024 / 1024 | . * 100 | floor / 100;
|
def prefix: (if (.key | test("/")) then (.key | split("/")[0]) else (.key | split("-")[0]) end);
|
||||||
map(. + {prefix: prefix}) | group_by(.prefix) |
|
def to_gib: . / 1024 / 1024 / 1024 | . * 100 | floor / 100;
|
||||||
map({prefix: .[0].prefix, count: length, totalBytes: (map(.sizeInBytes) | add // 0)}) |
|
map(. + {prefix: prefix}) | group_by(.prefix) |
|
||||||
sort_by(-.totalBytes) |
|
map({prefix: .[0].prefix, count: length, totalBytes: (map(.sizeInBytes) | add // 0)}) |
|
||||||
.[] | "\(.prefix)\t\(.count)\t\(.totalBytes | to_gib)"
|
sort_by(-.totalBytes) |
|
||||||
')
|
.[] | "\(.prefix)\t\(.count)\t\(.totalBytes | to_gib)"
|
||||||
echo ""
|
')
|
||||||
printf "Total: %s entries, %s GiB\n" "$total_entries" "$total_gib"
|
echo "| **Total** | $total_entries | $total_gib |"
|
||||||
|
else
|
||||||
|
printf "%-12s %6s %10s\n" "PREFIX" "COUNT" "SIZE (GiB)"
|
||||||
|
printf "%-12s %6s %10s\n" "------------" "------" "----------"
|
||||||
|
while IFS=$'\t' read -r prefix count gib; do
|
||||||
|
printf "%-12s %6s %10.2f\n" "$prefix" "$count" "$gib"
|
||||||
|
done < <(echo "$json" | jq -r '
|
||||||
|
def prefix: (if (.key | test("/")) then (.key | split("/")[0]) else (.key | split("-")[0]) end);
|
||||||
|
def to_gib: . / 1024 / 1024 / 1024 | . * 100 | floor / 100;
|
||||||
|
map(. + {prefix: prefix}) | group_by(.prefix) |
|
||||||
|
map({prefix: .[0].prefix, count: length, totalBytes: (map(.sizeInBytes) | add // 0)}) |
|
||||||
|
sort_by(-.totalBytes) |
|
||||||
|
.[] | "\(.prefix)\t\(.count)\t\(.totalBytes | to_gib)"
|
||||||
|
')
|
||||||
|
printf "%-12s %6s %10.2f\n" "Total" "$total_entries" "$total_gib"
|
||||||
|
fi
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
@ -56,6 +81,14 @@ count=$(echo "$json" | jq 'length')
|
||||||
total_bytes=$(echo "$json" | jq 'map(.sizeInBytes) | add // 0')
|
total_bytes=$(echo "$json" | jq 'map(.sizeInBytes) | add // 0')
|
||||||
total_gib=$(echo "$total_bytes" | jq -r '. / 1024 / 1024 / 1024 | . * 100 | floor / 100')
|
total_gib=$(echo "$total_bytes" | jq -r '. / 1024 / 1024 / 1024 | . * 100 | floor / 100')
|
||||||
|
|
||||||
echo "Cache key prefix: $KEY_PREFIX"
|
if [[ "$MARKDOWN" == true ]]; then
|
||||||
echo "Entries: $count"
|
echo "| PREFIX | COUNT | SIZE (GiB) |"
|
||||||
echo "Total size: $total_bytes bytes ($total_gib GiB)"
|
echo "|--------|------:|----------:|"
|
||||||
|
echo "| $KEY_PREFIX | $count | $total_gib |"
|
||||||
|
echo "| **Total** | $count | $total_gib |"
|
||||||
|
else
|
||||||
|
printf "%-12s %6s %10s\n" "PREFIX" "COUNT" "SIZE (GiB)"
|
||||||
|
printf "%-12s %6s %10s\n" "------------" "------" "----------"
|
||||||
|
printf "%-12s %6s %10.2f\n" "$KEY_PREFIX" "$count" "$total_gib"
|
||||||
|
printf "%-12s %6s %10.2f\n" "Total" "$count" "$total_gib"
|
||||||
|
fi
|
||||||
|
|
|
||||||
4
.github/workflows/cache-report.yml
vendored
4
.github/workflows/cache-report.yml
vendored
|
|
@ -27,5 +27,5 @@ jobs:
|
||||||
env:
|
env:
|
||||||
GH_TOKEN: ${{ github.token }}
|
GH_TOKEN: ${{ github.token }}
|
||||||
run: |
|
run: |
|
||||||
./.ci/gh_buildkit_cache_usage.sh | tee report.txt
|
./.ci/gh_buildkit_cache_usage.sh --markdown | tee report.txt
|
||||||
{ echo '```'; cat report.txt; echo '```'; } >> "$GITHUB_STEP_SUMMARY"
|
cat report.txt >> "$GITHUB_STEP_SUMMARY"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue