github-actions[bot] commented on code in PR #40717: URL: https://github.com/apache/beam/pull/40717#discussion_r4343819875
########## .github/workflows/pr-size-labeler.yml: ########## @@ -0,0 +1,117 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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 +# +# http://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. + +name: 'pr-size-labeler' + +on: # zizmor: ignore[dangerous-triggers] + pull_request_target: + types: ['opened', 'synchronize', 'reopened'] + workflow_dispatch: + inputs: + pr_number: + description: 'PR number to label manually (for workflow_dispatch)' + required: false + type: 'string' + +permissions: + pull-requests: 'write' + issues: 'write' + Review Comment: **🟢 Low**: Without a concurrency group, rapid pushes to the same PR can trigger parallel runs that race when inspecting and updating labels. Adding a `concurrency` block keyed on the PR number (or run ID for manual dispatch) prevents race conditions and saves runner minutes. ########## .github/workflows/pr-size-labeler.yml: ########## @@ -0,0 +1,117 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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 +# +# http://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. + +name: 'pr-size-labeler' + +on: # zizmor: ignore[dangerous-triggers] + pull_request_target: + types: ['opened', 'synchronize', 'reopened'] + workflow_dispatch: + inputs: + pr_number: + description: 'PR number to label manually (for workflow_dispatch)' + required: false + type: 'string' + +permissions: + pull-requests: 'write' + issues: 'write' + +jobs: + size-label: + runs-on: 'ubuntu-latest' + steps: + - name: 'Run size labeler' + env: + GH_TOKEN: '${{ secrets.GITHUB_TOKEN }}' + GH_REPO: '${{ github.repository }}' + EVENT_PR_NUMBER: '${{ github.event.pull_request.number }}' + INPUT_PR_NUMBER: '${{ github.event.inputs.pr_number }}' + run: | + # Determine the target PR number + if [ -n "$EVENT_PR_NUMBER" ]; then + PR_NUMBER="$EVENT_PR_NUMBER" + elif [ -n "$INPUT_PR_NUMBER" ]; then + PR_NUMBER="$INPUT_PR_NUMBER" + else + echo "❌ Error: No PR number provided." + exit 1 + fi + + echo "Checking PR #$PR_NUMBER..." + + # 1. Ensure standard premium size labels exist in the repository (self-healing) + # size/XS: Light green (#7ee081) + # size/S: Yellow-green (#a6d49f) + # size/M: Amber/Yellow (#f7d070) + # size/L: Orange (#f48c06) + # size/XL: Red (#dc2f02) + gh label create "size/XS" --color "7ee081" --description "XS: <10 lines changed" 2>/dev/null || true Review Comment: **🟡 Medium**: Running 5 `gh label create` API calls unconditionally on every `opened`, `synchronize`, and `reopened` event across all PRs generates 5 redundant HTTP requests per run (returning 422 Already Exists once the labels exist). In a busy repo like `apache/beam`, this adds unnecessary latency and consumes `GITHUB_TOKEN` API rate limits. Since the labels (`size/XS` through `size/XL`) only need to be created once, consider removing this block from the hot path (or only running it if `gh pr edit` fails due to a missing label). ########## .github/workflows/pr-size-labeler.yml: ########## @@ -0,0 +1,117 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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 +# +# http://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. + +name: 'pr-size-labeler' + +on: # zizmor: ignore[dangerous-triggers] + pull_request_target: + types: ['opened', 'synchronize', 'reopened'] + workflow_dispatch: + inputs: + pr_number: + description: 'PR number to label manually (for workflow_dispatch)' + required: false + type: 'string' + +permissions: + pull-requests: 'write' + issues: 'write' + +jobs: + size-label: + runs-on: 'ubuntu-latest' + steps: + - name: 'Run size labeler' + env: + GH_TOKEN: '${{ secrets.GITHUB_TOKEN }}' + GH_REPO: '${{ github.repository }}' + EVENT_PR_NUMBER: '${{ github.event.pull_request.number }}' + INPUT_PR_NUMBER: '${{ github.event.inputs.pr_number }}' + run: | + # Determine the target PR number + if [ -n "$EVENT_PR_NUMBER" ]; then + PR_NUMBER="$EVENT_PR_NUMBER" + elif [ -n "$INPUT_PR_NUMBER" ]; then + PR_NUMBER="$INPUT_PR_NUMBER" + else + echo "❌ Error: No PR number provided." + exit 1 + fi + + echo "Checking PR #$PR_NUMBER..." + + # 1. Ensure standard premium size labels exist in the repository (self-healing) + # size/XS: Light green (#7ee081) + # size/S: Yellow-green (#a6d49f) + # size/M: Amber/Yellow (#f7d070) + # size/L: Orange (#f48c06) + # size/XL: Red (#dc2f02) + gh label create "size/XS" --color "7ee081" --description "XS: <10 lines changed" 2>/dev/null || true + gh label create "size/S" --color "a6d49f" --description "S: 10-49 lines changed" 2>/dev/null || true + gh label create "size/M" --color "f7d070" --description "M: 50-249 lines changed" 2>/dev/null || true + gh label create "size/L" --color "f48c06" --description "L: 250-999 lines changed" 2>/dev/null || true + gh label create "size/XL" --color "dc2f02" --description "XL: >=1000 lines changed" 2>/dev/null || true + + # 2. Fetch PR details in a single efficient API call + PR_DATA=$(gh pr view "$PR_NUMBER" --json additions,deletions,changedFiles,labels) + if [ -z "$PR_DATA" ]; then + echo "❌ Error: Could not fetch PR details." + exit 1 + fi + + ADDITIONS=$(echo "$PR_DATA" | jq '.additions') + DELETIONS=$(echo "$PR_DATA" | jq '.deletions') + CHANGED_FILES=$(echo "$PR_DATA" | jq '.changedFiles') + TOTAL=$((ADDITIONS + DELETIONS)) + + echo "PR additions: $ADDITIONS, deletions: $DELETIONS, total changes: $TOTAL, files: $CHANGED_FILES" + + # 3. Calculate new size label + if [ $TOTAL -lt 10 ]; then + SIZE="size/XS" + elif [ $TOTAL -lt 50 ]; then + SIZE="size/S" + elif [ $TOTAL -lt 250 ]; then + SIZE="size/M" + elif [ $TOTAL -lt 1000 ]; then + SIZE="size/L" + else + SIZE="size/XL" + fi + + # 4. Check existing labels and update only if necessary + EXISTING_LABELS=$(echo "$PR_DATA" | jq -r '.labels[].name' 2>/dev/null || echo "") + + LABELS_TO_REMOVE=() + for L in size/XS size/S size/M size/L size/XL; do + if echo "$EXISTING_LABELS" | grep -Fq "$L" && [ "$L" != "$SIZE" ]; then + LABELS_TO_REMOVE+=("--remove-label" "$L") + fi + done + + LABEL_TO_ADD=() + if ! echo "$EXISTING_LABELS" | grep -Fq "$SIZE"; then Review Comment: **🟡 Medium**: Use `grep -Fxq` here as well to ensure exact full-line label matching. ```suggestion if ! echo "$EXISTING_LABELS" | grep -Fxq "$SIZE"; then ``` ########## .github/workflows/pr-size-labeler.yml: ########## @@ -0,0 +1,117 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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 +# +# http://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. + +name: 'pr-size-labeler' + +on: # zizmor: ignore[dangerous-triggers] + pull_request_target: + types: ['opened', 'synchronize', 'reopened'] + workflow_dispatch: + inputs: + pr_number: + description: 'PR number to label manually (for workflow_dispatch)' + required: false + type: 'string' + +permissions: + pull-requests: 'write' + issues: 'write' + +jobs: + size-label: + runs-on: 'ubuntu-latest' + steps: + - name: 'Run size labeler' + env: + GH_TOKEN: '${{ secrets.GITHUB_TOKEN }}' + GH_REPO: '${{ github.repository }}' + EVENT_PR_NUMBER: '${{ github.event.pull_request.number }}' + INPUT_PR_NUMBER: '${{ github.event.inputs.pr_number }}' + run: | + # Determine the target PR number + if [ -n "$EVENT_PR_NUMBER" ]; then + PR_NUMBER="$EVENT_PR_NUMBER" + elif [ -n "$INPUT_PR_NUMBER" ]; then + PR_NUMBER="$INPUT_PR_NUMBER" + else + echo "❌ Error: No PR number provided." + exit 1 + fi + + echo "Checking PR #$PR_NUMBER..." + + # 1. Ensure standard premium size labels exist in the repository (self-healing) + # size/XS: Light green (#7ee081) + # size/S: Yellow-green (#a6d49f) + # size/M: Amber/Yellow (#f7d070) + # size/L: Orange (#f48c06) + # size/XL: Red (#dc2f02) + gh label create "size/XS" --color "7ee081" --description "XS: <10 lines changed" 2>/dev/null || true + gh label create "size/S" --color "a6d49f" --description "S: 10-49 lines changed" 2>/dev/null || true + gh label create "size/M" --color "f7d070" --description "M: 50-249 lines changed" 2>/dev/null || true + gh label create "size/L" --color "f48c06" --description "L: 250-999 lines changed" 2>/dev/null || true + gh label create "size/XL" --color "dc2f02" --description "XL: >=1000 lines changed" 2>/dev/null || true + + # 2. Fetch PR details in a single efficient API call + PR_DATA=$(gh pr view "$PR_NUMBER" --json additions,deletions,changedFiles,labels) + if [ -z "$PR_DATA" ]; then + echo "❌ Error: Could not fetch PR details." + exit 1 + fi + + ADDITIONS=$(echo "$PR_DATA" | jq '.additions') + DELETIONS=$(echo "$PR_DATA" | jq '.deletions') + CHANGED_FILES=$(echo "$PR_DATA" | jq '.changedFiles') + TOTAL=$((ADDITIONS + DELETIONS)) + + echo "PR additions: $ADDITIONS, deletions: $DELETIONS, total changes: $TOTAL, files: $CHANGED_FILES" + + # 3. Calculate new size label + if [ $TOTAL -lt 10 ]; then + SIZE="size/XS" + elif [ $TOTAL -lt 50 ]; then + SIZE="size/S" + elif [ $TOTAL -lt 250 ]; then + SIZE="size/M" + elif [ $TOTAL -lt 1000 ]; then + SIZE="size/L" + else + SIZE="size/XL" + fi + + # 4. Check existing labels and update only if necessary + EXISTING_LABELS=$(echo "$PR_DATA" | jq -r '.labels[].name' 2>/dev/null || echo "") + + LABELS_TO_REMOVE=() + for L in size/XS size/S size/M size/L size/XL; do + if echo "$EXISTING_LABELS" | grep -Fq "$L" && [ "$L" != "$SIZE" ]; then Review Comment: **🟡 Medium**: Use `grep -Fxq` instead of `grep -Fq` to match the full line. Without `-x`, `grep -Fq "size/S"` will match substrings (for example, if a label like `size/S-override` or `size/XL` vs `size/X` ever existed). ```suggestion if echo "$EXISTING_LABELS" | grep -Fxq "$L" && [ "$L" != "$SIZE" ]; then ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
