Skip to content

armgit / lyftr

Public Imported from GitHub
0

Self-hosted fitness tracker. Log workouts, track nutrition, and monitor progress. Docker deployment, mobile-friendly.

Cap PR size, and stop the reviewer reading a diff nobody would (#162)

Carter4c111531db8e
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 4eb5533..5f577df 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -254,6 +254,60 @@ jobs:
echo "version output: $out"
echo "$out" | grep -q 'smoke-9.9.9'
+ # Size is reported, never enforced — the convention kubernetes/kubernetes uses, and the
+ # default of every size-labeller in the wild (CodelyTV ships fail_if_xl: false;
+ # oven-sh/bun has no size labels at all).
+ #
+ # A label is better feedback than a block or a comment: it shows in the PR list without
+ # notifying anyone, it is filterable, and it never has to be argued with. Some large
+ # PRs are legitimate — a vendored dependency, a migration, one mechanical rename across
+ # forty files — and a gate that has to be overridden teaches people to override gates.
+ #
+ # Thresholds are Kubernetes': XS 0-9, S 10-29, M 30-99, L 100-499, XL 500-999, XXL
+ # 1000+, "ignoring generated files". Lockfiles, build output and snapshots do not count;
+ # a lockfile refresh is thousands of lines nobody reads.
+ pr-size:
+ name: PR size
+ if: github.event_name == 'pull_request'
+ runs-on: ubuntu-latest
+ permissions:
+ contents: read
+ pull-requests: write # to apply the size label
+ steps:
+ - uses: actions/checkout@v4
+ with:
+ fetch-depth: 0
+ - name: Label by reviewable churn
+ env:
+ GH_TOKEN: ${{ github.token }}
+ BASE: ${{ github.event.pull_request.base.sha }}
+ HEAD: ${{ github.event.pull_request.head.sha }}
+ PR: ${{ github.event.pull_request.number }}
+ run: |
+ set -euo pipefail
+ CHANGED=$(git diff --numstat "$BASE...$HEAD" -- . ':(exclude)**/package-lock.json' ':(exclude)**/*.lock' ':(exclude)**/*.tsbuildinfo' ':(exclude)**/dist/**' ':(exclude)**/*.snap' | awk '{ a += $1; d += $2 } END { print (a + d) + 0 }')
+
+ if [ "$CHANGED" -lt 10 ]; then SIZE=XS
+ elif [ "$CHANGED" -lt 30 ]; then SIZE=S
+ elif [ "$CHANGED" -lt 100 ]; then SIZE=M
+ elif [ "$CHANGED" -lt 500 ]; then SIZE=L
+ elif [ "$CHANGED" -lt 1000 ]; then SIZE=XL
+ else SIZE=XXL
+ fi
+ echo "reviewable churn: ${CHANGED} lines -> size/${SIZE}"
+
+ # Replace any previous size label so the PR carries exactly one.
+ for old in XS S M L XL XXL; do
+ [ "$old" = "$SIZE" ] || gh pr edit "$PR" --remove-label "size/$old" 2>/dev/null || true
+ done
+ gh pr edit "$PR" --add-label "size/$SIZE"
+
+ # Past the point where a review stops being useful, say so once, in the run
+ # summary. Advisory: this job never fails.
+ if [ "$CHANGED" -gt 5000 ]; then
+ echo "::warning::This PR changes ${CHANGED} reviewable lines. Past 5000 the automated review is skipped entirely, and a diff this size is hard for anyone to hold in their head — consider splitting it."
+ fi
+
build-backend:
name: Build & push backend image
needs: [test, unit, e2e, version-smoke]
diff --git a/.github/workflows/claude-code-review.yml b/.github/workflows/claude-code-review.yml
index 20dc965..78aa3af 100644
--- a/.github/workflows/claude-code-review.yml
+++ b/.github/workflows/claude-code-review.yml
@@ -57,17 +57,52 @@ jobs:
# step runs with a token in the environment.
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
- fetch-depth: 1
+ # Full history: the size check below diffs base...head, which a shallow clone
+ # cannot resolve.
+ fetch-depth: 0
# Don't leave the token in .git/config for later steps to pick up.
persist-credentials: false
+ # Cost ceiling, separate from the merge gate in ci.yml. A review's spend scales with
+ # the diff, and this draws on the subscription's usage, so an accidental
+ # ten-thousand-line diff should cost nothing rather than a lot. Same exclusions as
+ # the size gate: a lockfile refresh is not thinking work.
+ #
+ # Note the fork guard above already means an outside contributor cannot trigger a
+ # review at all — GitHub withholds secrets from fork PRs. This bounds OUR OWN
+ # mistakes, which is the realistic case.
+ - name: Skip the review if the diff is too large to be worth reading
+ env:
+ BASE: ${{ github.event.pull_request.base.sha }}
+ HEAD: ${{ github.event.pull_request.head.sha }}
+ run: |
+ set -euo pipefail
+ CHANGED=$(git diff --numstat "$BASE...$HEAD" -- . ':(exclude)**/package-lock.json' ':(exclude)**/*.lock' ':(exclude)**/*.tsbuildinfo' ':(exclude)**/dist/**' ':(exclude)**/*.snap' | awk '{ a += $1; d += $2 } END { print (a + d) + 0 }')
+ echo "REVIEWABLE=$CHANGED" >> "$GITHUB_ENV"
+ if [ "$CHANGED" -gt 5000 ]; then
+ echo "TOO_BIG=true" >> "$GITHUB_ENV"
+ echo "::notice::Review skipped — ${CHANGED} reviewable lines is past the 5000 line ceiling. Split the PR, and CI's 'PR size' check will say the same."
+ else
+ echo "TOO_BIG=false" >> "$GITHUB_ENV"
+ fi
+
- name: Say what is missing, rather than failing on auth
if: env.CONFIGURED != 'true'
run: |
echo "::notice::Review skipped — CLAUDE_CODE_OAUTH_TOKEN is not set."
echo "To enable: claude setup-token then gh secret set CLAUDE_CODE_OAUTH_TOKEN"
- - if: env.CONFIGURED == 'true'
+ # Best-effort, deliberately. Anthropic's own guidance for this is that "a failed run
+ # never blocks your PR", and the failures worth planning for are not code problems:
+ # an API outage, an exhausted subscription, a rate limit. None of those say anything
+ # about the change under review, so none should show as a red X against it — that
+ # trains people to ignore red, which is the one thing CI cannot afford.
+ #
+ # continue-on-error keeps the job green and the next step says what happened. This
+ # check is not a required one either, so a merge is never waiting on it.
+ - id: review
+ continue-on-error: true
+ if: env.CONFIGURED == 'true' && env.TOO_BIG != 'true'
uses: anthropics/claude-code-action@a874e9ecd7bb36efdad65429c6b35815f5a08f10 # v1.0.210
with:
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
@@ -99,3 +134,11 @@ jobs:
calibration. It deliberately does not restate the project's standards: those
are in CLAUDE.md, which you already read, and REVIEW.md tells you how to weigh
a violation of them."
+
+ # Say it out loud rather than leaving a silently unreviewed PR looking reviewed.
+ # An outage means nobody looked at this — worth knowing before merging, even though
+ # nothing stops you.
+ - name: Note a review that could not run
+ if: steps.review.outcome == 'failure'
+ run: |
+ echo "::warning::The automated review did not complete — Claude may be unavailable, rate limited, or the subscription's usage exhausted. Nothing is blocked, but this PR has not been reviewed. Re-run this job to try again."