feat(ci): PR size (non-test churn) pre-commit hook + size-labeling workflow - #445
Open
arekay-nv wants to merge 3 commits into
Open
feat(ci): PR size (non-test churn) pre-commit hook + size-labeling workflow#445arekay-nv wants to merge 3 commits into
arekay-nv wants to merge 3 commits into
Conversation
…orkflow Classify a PR by non-test churn per the Endpoints PR Review Policy: additions + deletions and changed-file count outside tests/**, lockfiles, vendored sources, and generated files, mapped to Normal / Large / Very large (class = higher of the two dimensions). Advisory only -- always exits 0. - scripts/pr_size_check.py: pure classify()/parse_numstat() + git measurement. Terse one-line verdict by default; -v/--verbose adds the threshold grid and per-class review requirements; --github-output emits size_class/churn/files. - pre-commit hook `pr-size-check`: quiet on a normal commit; the breakdown surfaces under `pre-commit run pr-size-check --verbose`. - .github/workflows/pr-size-label.yml: labels PRs size/normal|large|very-large from the same logic. Uses pull_request_target so fork PRs can be labeled, running only the trusted base-repo script over the fetched PR diff (never checks out or executes PR code). - tests/unit/scripts/test_pr_size_check.py: boundary, verbose-gating, and temp-git measurement coverage. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
MLCommons CLA bot All contributors have signed the MLCommons CLA ✍️ ✅ |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #445 +/- ##
=======================================
Coverage ? 80.99%
=======================================
Files ? 150
Lines ? 20211
Branches ? 0
=======================================
Hits ? 16369
Misses ? 3842
Partials ? 0 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Follow-up hardening on the pr-size-check feature: - workflow: drop the inline `gh label create` calls (creating label definitions needs `issues: write`; the job only has `pull-requests: write`). Label application is now warn-only and never fails the advisory check, and stale `size/*` labels are stripped only after the new label applies, so a failed add can't leave a PR unlabeled. Labels are provisioned once out-of-band via `gh label create`. - pre-commit: run the advisory hook with `python3` (not `python`) and set `verbose: true` so the one-line verdict shows on every commit. - size script: exclude root-level `*.lock` (was `**/*.lock`, which git's default pathspec matching never matches against a top-level `uv.lock`). - tests: cover the CI two-ref `--head` path, top-level `*.lock` exclusion, and base-ref auto-detection (candidate scan + `GITHUB_BASE_REF`). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
arekay-nv
marked this pull request as ready for review
August 14, 2026 23:30
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Adds a PR-size classifier used two ways, implementing the "CI job for LOC count / label large PRs" item from the Endpoints PR Review Policy:
pr-size-check— prints the one-line size class on every commit (verbose: true). Runpython3 scripts/pr_size_check.py --verbosefor the threshold grid and per-class review requirements..github/workflows/pr-size-label.yml— labels each PRsize/normal | size/large | size/very-largefrom the same logic.Size = non-test churn (additions + deletions and changed-file count) excluding
tests/**, lockfiles, vendored sources, and generated files. Class = the higher of the lines/files dimensions. Advisory only — nothing blocks.Per its own tool, this PR classifies as Normal.
Type of change
Testing
tests/unit/scripts/test_pr_size_check.py(21 cases): classify boundaries, numstat parsing, verbose gating, temp-git measurement,$GITHUB_OUTPUT, the CI two-ref--headpath, top-level*.lockexclusion, and base-ref auto-detection (candidate scan +GITHUB_BASE_REF).Checklist
sched_setaffinityenv issue on unrelated files; green on Linux CI)Notes for reviewers
pull_request_targetsoGITHUB_TOKENcan write labels on fork PRs (a plainpull_requesttoken is read-only for forks). It never checks out or runs PR code — only the trusted base-repo copy ofscripts/pr_size_check.pyover the fetched PR diff.pull_request_targetruns the workflow from the base branch, this very PR won't be auto-labeled; labeling takes effect for PRs opened after this merges.pull-requests: writeto attach labels, whereas creating label definitions needsissues: write; keeping them separate keeps the per-PR token minimally scoped. Create the labels once with:::warning::and never fails the PR, and stalesize/*labels are removed only after the new label is successfully applied (so a failed add never leaves a PR unlabeled).Base-branch resolution & forked PRs
The size class is computed against a base branch. When
--base/PR_BASE_REFare unset,resolve_base_ref()tries, in order:GITHUB_BASE_REF→origin/main→main→upstream/main→ any other<remote>/main.pull_request.base.sha, so the applied label is correct regardless of local remotes.origin= your fork,upstream=mlcommons/endpoints—origin/mainresolves beforeupstream/main. If your fork'sorigin/mainis stale, the local advisory size can count already-merged upstream commits and over-classify. This affects only the local hint, never the CI label. To pin the base locally, either keep your fork'smainsynced with upstream, or set the base explicitly:PR_BASE_REF=upstream/main pre-commit run pr-size-check # or, ad hoc: python3 scripts/pr_size_check.py --base upstream/main --verbose