How to Add Size Labels (XS/S/M/L) to Pull Requests
A size-label action counts additions plus deletions and applies a bucketed label like size/S or size/XL.
Run pascalgn/size-label-action on pull_request events. It computes the diff size and applies a size/* label, and you can override the thresholds with an env var.
Steps
- Add a workflow triggered on
pull_request. - Run
pascalgn/size-label-actionwithGITHUB_TOKEN. - Optionally set
IGNOREDand custom size thresholds viasizes.
Workflow
.github/workflows/ci.yml
on: [pull_request]
permissions:
pull-requests: write
jobs:
size:
runs-on: ubuntu-latest
steps:
- uses: pascalgn/size-label-action@v0.5.4
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
sizes: >
{
"0": "XS",
"20": "S",
"100": "M",
"500": "L",
"1000": "XL"
}Gotchas
- Exclude generated files with an
IGNOREDenv var so lockfiles do not inflate the size. - The label updates on each push, so a shrinking PR moves back down a bucket.
Related guides
How to Auto-Label Pull Requests by Changed PathsApply labels to a pull request based on which files it touches using actions/labeler and a .github/labeler.ym…
How to Fail a PR That Exceeds a Diff SizeFail a pull request whose diff exceeds a line threshold by reading additions and deletions from the PR payloa…