Skip to content

ci: automatically label each PR with a code-size bucket - #3941

Merged
michaelmalave merged 8 commits into
mainfrom
mm/ci/pr-size-label
Sep 23, 2026
Merged

michaelmalave merged 8 commits into
mainfrom
mm/ci/pr-size-label

Conversation

@michaelmalave

@michaelmalave michaelmalave commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This adds a small GitHub Actions workflow that automatically tags every pull request with a size label (size/XS through size/XL) so reviewers can see how big a PR is before they open it. The size is based only on lines of code changed — documentation, the lockfile, and generated files don't count — so a big docs update or a lockfile bump won't make a small code change look large. The label is purely informational: it never blocks a PR from merging.

What it does, step by step:

  • Runs automatically whenever a PR is opened, updated, or reopened.
  • Counts the lines added and removed in the PR and picks a size bucket: XS (under 10), S (under 100), M (under 500), L (under 1000), XL (1000+). These thresholds are constants at the top of the file, so they're easy to change.
  • Ignores docs/, *.md, package-lock.json, autocomplete-scripts/, and dist/ when counting, so the size reflects code a person actually has to review.
  • Adds a separate docs label when documentation changed, tracked independently of size.
  • Keeps exactly one size label on the PR at a time, updating it as the PR grows or shrinks.

Comments on the PR

The workflow posts a comment only when a PR is XL (1000+ lines of code churn) — no other size gets a comment. It's posted once, and it's automatically deleted if the PR is later updated and drops below XL. The comment is a suggestion, not a gate; the check still passes either way. The exact text is:

This PR is labeled size/XL (N lines of code churn, excluding docs, package-lock.json, and generated files).

Large PRs are harder to review well. If it can be split into smaller, independently reviewable pieces, consider doing so. This is a suggestion, not a blocker — the check still passes.

The workflow is plain bash using the built-in gh CLI (the same zero-dependency style as pr-title-check.yml); it pulls in no third-party actions.

Type of Change

Breaking Changes (major semver update)

  • Add a ! after your change type to denote a change that breaks current behavior

Feature Additions (minor semver update)

  • feat: Introduces a new feature to the codebase

Patch Updates (patch semver update)

  • fix: Bug fix
  • deps: Dependency upgrade
  • revert: Revert a previous commit
  • chore: Change that does not affect production code
  • refactor: Refactoring existing code without changing behavior
  • test: Add/update/remove tests

The real type is ci (a CI-only change, accepted by the PR-title linter). The template has no ci box, so the closest one (chore) is checked. No production code is touched.

Testing

Steps:

  1. On this PR, expect a size/* label to be applied automatically. Since this change touches no docs/ or *.md files, no docs label should appear. (This PR is size/M, so no comment is posted.)
  2. To see the docs behavior, push a follow-up commit editing a docs/*.md file — expect the docs label to show up while the size label stays driven by code changes only.

Screenshots (if applicable)

Related Issues

GitHub issue: none
GUS work item: none

@michaelmalave
michaelmalave requested a review from a team as a code owner September 22, 2026 18:03
@michaelmalave
michaelmalave deployed to AcceptanceTests September 22, 2026 18:03 — with GitHub Actions Active
@michaelmalave
michaelmalave deployed to AcceptanceTests September 22, 2026 18:03 — with GitHub Actions Active
@michaelmalave
michaelmalave deployed to AcceptanceTests September 22, 2026 18:03 — with GitHub Actions Active
@michaelmalave
michaelmalave deployed to AcceptanceTests September 22, 2026 18:03 — with GitHub Actions Active
@michaelmalave
michaelmalave deployed to AcceptanceTests September 22, 2026 18:24 — with GitHub Actions Active
@michaelmalave
michaelmalave deployed to AcceptanceTests September 22, 2026 18:24 — with GitHub Actions Active
@michaelmalave
michaelmalave deployed to AcceptanceTests September 22, 2026 18:24 — with GitHub Actions Active
@michaelmalave
michaelmalave deployed to AcceptanceTests September 22, 2026 18:24 — with GitHub Actions Active
@github-actions github-actions Bot added the size/M Medium PR (code churn < 500) label Sep 22, 2026
@michaelmalave michaelmalave changed the title ci: add advisory PR size label with docs excluded ci: automatically label each PR with a code-size bucket Sep 22, 2026

@eablack eablack left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review findings for the new pr-size-label.yml workflow, posted inline below (most severe first). The line 39 runner-pool exposure is the one worth gating the merge on.

Comment thread .github/workflows/pr-size-label.yml
Comment thread .github/workflows/pr-size-label.yml Outdated
Comment thread .github/workflows/pr-size-label.yml Outdated
Comment thread .github/workflows/pr-size-label.yml Outdated
Comment thread .github/workflows/pr-size-label.yml Outdated
- Serialize with cancel-in-progress: false so an in-flight label/comment
  reconcile always completes rather than being cancelled mid-update.
- Capture the changed-files read up front and degrade to a clean skip on
  API failure, so a failed read can never be misread as churn=0 (size/XS).
- Create only the size label actually applied (via ensure_label) instead
  of all six on every event, routed through try() for a visible warning.
- Add --paginate + a guard to the labels read (a >30-label PR would drop a
  stale size/* and leave two size labels; a failed read would abort).
- Guard the XL-nudge comments read so a transient failure can't abort the
  step under set -e.
Switch the trigger from pull_request to a hardened pull_request_target job,
per review feedback. The job runs on the org's IP-allow-listed runner pool;
under pull_request_target the workflow definition comes from the base branch,
so a fork contributor can no longer edit this file to inject run: steps onto
that runner network. Safe because the job never checks out PR head code and
references only trusted, non-text context (repository slug, PR number).

Update the try() comment: under pull_request_target the GITHUB_TOKEN is
read-write even for fork PRs, so try() now guards transient failures rather
than a read-only fork token.
@michaelmalave
michaelmalave merged commit 2d13484 into main Sep 23, 2026
19 checks passed
@michaelmalave
michaelmalave deleted the mm/ci/pr-size-label branch September 23, 2026 16:15

This branch was successfully deployed

1 active deployment
AcceptanceTests — 39339115 Deployed Sep 23, 2026 by michaelmalave via acceptance (22.x, ubuntu-latest) #9266
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Medium PR (code churn < 500)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants