Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions .github/pr-size-labels.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Copyright 2025 The Cirq Developers
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Configure PR size labeler action in workflows/pr-labeler.yaml
# For more information, see https://github.com/cbrgm/pr-size-labeler-action
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# List of files to exclude from size calculations.
exclude_files:
- "package-lock.json"
- "*_pb2.py"
- "*_pb2.pyi"
- "*.bundle.js"

# cbrgm/pr-size-labeler-action labels based on both "size" (= lines added +
# lines deleted) and number of files changed in a PR. The action looks for the
# largest matching configuration, using number of files changed first. Trying
# to think about the implications of values on two dimensions is difficult, so
# for simplicity, the settings below use the same value for both. This lets us
# think in terms of "changes" more broadly, regardless of what kind.
label_configs:
- size: xs
diff: 10 # Threshold for total LoC changed (additions + deletions)
files: 10 # Threshold for total number of files changed
labels: ["size: XS"] # Label(s) to be applied for this size

- size: s
diff: 50
files: 50
labels: ["size: S"]

- size: m
diff: 250
files: 250
labels: ["size: M"]

- size: l
diff: 1000
files: 1000
labels: ["size: L"]

# Although it's not obvious from the docs of the action, it uses the final
# config for all cases that exceed the given values too. I.e., anything that
# hits 1001 or more will be lumped together as xl.
- size: xl
diff: 1001
files: 1001
labels: ["size: XL"]
58 changes: 38 additions & 20 deletions .github/workflows/pr-labeler.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Label PRs with labels such as size.
#
# This workflow is designed not to fail if labeling actions encounter errors;
# instead, the actions write annotations on the workflow run summary page. If
# labels don't seem to be getting applied as expected, check there for errors.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

name: Pull request labeler
Expand All @@ -22,7 +26,9 @@ run-name: >-

on:
pull_request:
types: [opened]
types:
- opened
- synchronize

# Allow manual invocation.
workflow_dispatch:
Expand All @@ -32,30 +38,42 @@ permissions: read-all

jobs:
label-pr-size:
name: Add size label to new pull request
name: Update PR size labels
runs-on: ubuntu-24.04
permissions:
id-token: write
contents: read
pull-requests: write
issues: write
steps:
- name: Label the PR with a size label
uses: codelytv/pr-size-labeler@c7a55a022747628b50f3eb5bf863b9e796b8f274 # v1
with:
# Don't count file deletions, per suggestion in Small CLs.
ignore_file_deletions: 'true'

xs_label: 'Size: XS'
xs_max_size: '10'
# We need a copy of the repo so the action can read the config file.
- name: Check out a copy of the git repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

s_label: 'size: S'
s_max_size: '50'

m_label: 'size: M'
m_max_size: '250'

l_label: 'size: L'
l_max_size: '1000'
- name: Label the PR with a size label
id: label
continue-on-error: true
run: |
set -x +e
podman --out action.out run -v .github:/tmp/.github --rm -it \
ghcr.io/cbrgm/pr-size-labeler-action:v1 \
--githubtoken ${{secrets.GITHUB_TOKEN}} \
--eventname pull_request \
--reponame ${{github.repository}} \
--prnumber ${{github.event.number}} \
--configfilepath /tmp/.github/pr-size-labels.yaml
status=$?
echo '::group::Labeler action output'
cat action.out
echo '::endgroup::'
exit $status

xl_label: 'size: XL'
fail_if_xl: 'false'
- name: Detect and report errors in labeler action
if: steps.label.outcome == 'failure' || steps.label.outcome == 'error'
run: |
{
echo "<h4>‼️ Failed to label PR ${{github.event.number}}</h4>"
echo "<pre>"
cat action.out
echo "</pre>"
} >> "$GITHUB_STEP_SUMMARY"
Loading