Skip to content

Commit 84af2be

Browse files
committed
Automate size badge publishing
1 parent 5c05ca7 commit 84af2be

5 files changed

Lines changed: 54 additions & 17 deletions

File tree

‎.github/badges/master-payload-size.json‎

Lines changed: 0 additions & 6 deletions
This file was deleted.

‎.github/workflows/docker-publish.yml‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,54 @@ jobs:
167167
labels: ${{ steps.meta.outputs.labels }}
168168
cache-from: type=gha
169169
cache-to: type=gha,mode=max,ignore-error=true
170+
171+
update-size-badge:
172+
needs: build
173+
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
174+
runs-on: ubuntu-latest
175+
continue-on-error: true
176+
permissions:
177+
contents: write
178+
179+
steps:
180+
- name: Configure Git default branch
181+
run: git config --global init.defaultBranch master
182+
183+
- name: Checkout
184+
uses: actions/checkout@v6
185+
with:
186+
fetch-depth: 0
187+
188+
- name: Generate badge data
189+
run: BADGE_PATH=tmp/master-payload-size.json bash scripts/update-size-badge.sh
190+
191+
- name: Publish badge data
192+
run: |
193+
set -euo pipefail
194+
badge_branch="size-badge-data"
195+
badge_file="tmp/master-payload-size.json"
196+
worktree="$(mktemp -d)"
197+
198+
git config user.name "github-actions[bot]"
199+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
200+
201+
if git ls-remote --exit-code --heads origin "$badge_branch" >/dev/null 2>&1; then
202+
git fetch origin "$badge_branch"
203+
git worktree add "$worktree" "origin/$badge_branch"
204+
git -C "$worktree" switch -c "$badge_branch"
205+
else
206+
git worktree add --detach "$worktree"
207+
git -C "$worktree" switch --orphan "$badge_branch"
208+
git -C "$worktree" rm -rf . >/dev/null 2>&1 || true
209+
fi
210+
211+
cp "$badge_file" "$worktree/master-payload-size.json"
212+
git -C "$worktree" add master-payload-size.json
213+
214+
if git -C "$worktree" diff --cached --quiet; then
215+
echo "Badge data unchanged"
216+
exit 0
217+
fi
218+
219+
git -C "$worktree" commit -m "Update master payload badge"
220+
git -C "$worktree" push origin "HEAD:$badge_branch"

‎README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<img src="https://github.com/Devsh-Graphics-Programming/MainWebsite/actions/workflows/docker-publish.yml/badge.svg?branch=master" alt="Build Status" />
44
</a>
55
<a href="https://github.com/Devsh-Graphics-Programming/MainWebsite">
6-
<img src="https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2FDevsh-Graphics-Programming%2FMainWebsite%2Fmaster%2F.github%2Fbadges%2Fmaster-payload-size.json" alt="Master payload size" />
6+
<img src="https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2FDevsh-Graphics-Programming%2FMainWebsite%2Fsize-badge-data%2Fmaster-payload-size.json" alt="Master payload size" />
77
</a>
88
<a href="https://discord.gg/krsBcABm7u">
99
<img src="https://img.shields.io/discord/308323056592486420?label=discord&logo=discord&logoColor=white&color=7289DA" alt="Join our Discord" />
@@ -24,7 +24,7 @@ This repo is a Next.js app used to generate a static site. The final production
2424
2525
## Repository size budget
2626
- CI fails if the tracked tree exceeds `10 MiB`, `public/` exceeds `8 MiB`, any tracked blob exceeds `1 MiB`, or HEAD Git blob payloads exceed `15 MiB`.
27-
- Run `scripts/check-size-budget.sh` locally before adding new media. If the badge changes, commit the updated `.github/badges/master-payload-size.json`.
27+
- Run `scripts/check-size-budget.sh` locally before adding new media. The README badge is informational and is updated outside the size gate.
2828

2929
## Runtime filesystem layout
3030
- The image is read-only, but Caddy still needs tiny writable slots for TLS cache/autosave/lock files.

‎scripts/check-size-budget.sh‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,4 @@ fi
9090
history_blob_bytes="$(sum_head_blob_bytes)"
9191
check_limit "HEAD Git blob payload size" "$history_blob_bytes" "$max_history_blob_bytes"
9292

93-
if [ -x scripts/update-size-badge.sh ]; then
94-
scripts/update-size-badge.sh
95-
if ! git diff --exit-code -- .github/badges/master-payload-size.json >/dev/null; then
96-
echo "::error file=.github/badges/master-payload-size.json::Repository size badge is stale. Run scripts/update-size-badge.sh and commit the result."
97-
fail=1
98-
fi
99-
fi
100-
10193
exit "$fail"

‎scripts/update-size-badge.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set -euo pipefail
33

44
max_history_blob_bytes="${MAX_HISTORY_BLOB_BYTES:-15728640}"
55
warning_history_blob_bytes="${WARNING_HISTORY_BLOB_BYTES:-12582912}"
6-
badge_path="${BADGE_PATH:-.github/badges/master-payload-size.json}"
6+
badge_path="${BADGE_PATH:-tmp/master-payload-size.json}"
77

88
history_blob_bytes="$(
99
git rev-list --objects HEAD |

0 commit comments

Comments
 (0)