spark-test commented on code in PR #60352:
URL: https://github.com/apache/spark/pull/60352#discussion_r4543651228


##########
.github/workflows/labeler.yml:
##########
@@ -22,73 +22,81 @@
 # Manually added configured labels are removed on the next scan if they do not
 # match the PR's changed files.
 #
-# To label all open PRs once, regardless of their last update:
-#   gh workflow run labeler.yml --repo apache/spark --ref master -f 
backfill=true
-
+# Each run labels PRs updated since the last successful run started, so failed
+# or skipped runs only widen the next run's window. The PRs are split into
+# groups that are labeled by parallel jobs, keeping each job well within
+# ubuntu-slim's 15-minute job limit.
+#
 name: Label pull requests
 
 on:
   schedule:
   - cron: "7-59/10 * * * *"
   workflow_dispatch:
-    inputs:
-      backfill:
-        description: Label all open PRs regardless of their last update
-        type: boolean
-        default: false
 
 concurrency:
   group: ${{ github.workflow }}
   cancel-in-progress: false
-  queue: max
 
 jobs:
-  label:
-    name: Label pull requests
+  list:
+    name: List pull requests
     if: github.repository == 'apache/spark' && github.ref == 
'refs/heads/master'
-    runs-on: ubuntu-latest
+    runs-on: ubuntu-slim
     permissions:
       actions: read
-      contents: read
-      pull-requests: write
+      pull-requests: read
+    outputs:
+      groups: ${{ steps.prs.outputs.groups }}
     steps:
-      - name: Checkout labeler configuration
-        uses: actions/checkout@v7
-        with:
-          persist-credentials: false
-          sparse-checkout: .github
       - name: List PRs
         id: prs
         env:
           GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
-          BACKFILL: ${{ inputs.backfill }}
         run: |
-          if [[ "$BACKFILL" == "true" ]]; then
-            filters=(-f state=open)
-            echo "Listing all open PRs"
+          last_success=$(gh run list --workflow labeler.yml --branch master \
+            --status success --limit 1 --json startedAt \
+            --jq '.[0].startedAt // empty')
+          if [ -n "$last_success" ]; then
+            # Keep a short overlap to catch PR updates missed near the 
previous run's start.
+            since=$(date -u -d "$last_success - 10 minutes" 
+%Y-%m-%dT%H:%M:%SZ)
           else
-            last_success=$(gh run list --workflow labeler.yml --branch master \
-              --event schedule --status success --limit 1 --json startedAt \
-              --jq '.[0].startedAt // empty')
-            if [ -n "$last_success" ]; then
-              # Keep a short overlap to catch PR updates missed near the 
previous run's start.
-              since=$(date -u -d "$last_success - 10 minutes" 
+%Y-%m-%dT%H:%M:%SZ)
-            else
-              since=$(date -u -d "12 hours ago" +%Y-%m-%dT%H:%M:%SZ)
-            fi
-            filters=(-f state=all -f since="$since")
-            echo "Listing PRs updated since $since"
+            since=$(date -u -d "12 hours ago" +%Y-%m-%dT%H:%M:%SZ)
           fi
+          echo "Listing PRs updated since $since"
           numbers=$(gh api --method GET --paginate 
"repos/$GITHUB_REPOSITORY/issues" \
-            "${filters[@]}" -f sort=updated -f direction=desc \
+            -f state=all -f since="$since" -f sort=updated -f direction=desc \
             -f per_page=100 --jq '.[] | select(.pull_request != null) | 
.number')
+          # Dedupe, since PRs updated during pagination can appear on two 
pages.

Review Comment:
   **Nit (P3):** The dedupe is needed, but the PRs it removes are not the 
updated ones. This listing pages by number through issues sorted by update 
time, newest first, so a PR updated mid-listing moves to the front, which this 
run has already fetched: it appears once if it was fetched before the update, 
and this run skips it otherwise. What repeats is a neighbor that the move 
pushes from the end of one page onto the next. The skipped PR was updated after 
this run started, so the next run's window still covers it and no behavior 
needs to change, but the current wording suggests updated PRs are listed twice 
when a run can in fact miss them.
   
   ```suggestion
             # Dedupe, since updates during pagination can shift PRs across 
page boundaries.
   ```
   
   **Verification:**
   - **Inspection:** The comment above the dedupe attributes repeated PR 
numbers to PRs that updates during pagination shift across page boundaries, and 
the listing and `sort -nu` lines are unchanged.



##########
.github/workflows/labeler.yml:
##########
@@ -22,73 +22,81 @@
 # Manually added configured labels are removed on the next scan if they do not
 # match the PR's changed files.
 #
-# To label all open PRs once, regardless of their last update:
-#   gh workflow run labeler.yml --repo apache/spark --ref master -f 
backfill=true
-
+# Each run labels PRs updated since the last successful run started, so failed
+# or skipped runs only widen the next run's window. The PRs are split into
+# groups that are labeled by parallel jobs, keeping each job well within
+# ubuntu-slim's 15-minute job limit.
+#
 name: Label pull requests
 
 on:
   schedule:
   - cron: "7-59/10 * * * *"
   workflow_dispatch:
-    inputs:
-      backfill:
-        description: Label all open PRs regardless of their last update
-        type: boolean
-        default: false
 
 concurrency:
   group: ${{ github.workflow }}
   cancel-in-progress: false
-  queue: max
 
 jobs:
-  label:
-    name: Label pull requests
+  list:
+    name: List pull requests
     if: github.repository == 'apache/spark' && github.ref == 
'refs/heads/master'
-    runs-on: ubuntu-latest
+    runs-on: ubuntu-slim
     permissions:
       actions: read
-      contents: read
-      pull-requests: write
+      pull-requests: read
+    outputs:
+      groups: ${{ steps.prs.outputs.groups }}
     steps:
-      - name: Checkout labeler configuration
-        uses: actions/checkout@v7
-        with:
-          persist-credentials: false
-          sparse-checkout: .github
       - name: List PRs
         id: prs
         env:
           GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
-          BACKFILL: ${{ inputs.backfill }}
         run: |
-          if [[ "$BACKFILL" == "true" ]]; then
-            filters=(-f state=open)
-            echo "Listing all open PRs"
+          last_success=$(gh run list --workflow labeler.yml --branch master \
+            --status success --limit 1 --json startedAt \

Review Comment:
   **Non-blocking (P2):** This job no longer checks anything out, since the 
checkout moved to the `label` job, so its working directory has no git remote, 
and nothing else tells `gh run list` which repository to read. gh takes the 
repository from `--repo`, `GH_REPO`, or the local git remotes, and `gh help 
environment` documents no use of `GITHUB_REPOSITORY`, so here gh stops with 
`failed to determine base repo`. Under the default `bash -e` shell that ends 
the step at this assignment, the `list` job fails, and the `label` job is 
skipped, so every scheduled and manual run after merge would fail without 
labeling any PR. No update is lost, since a failed run never sets where the 
next window starts, but labeling stops until this is fixed. The `gh api` call 
below is unaffected because its path names the repository.
   
   ```suggestion
             last_success=$(gh run list --repo "$GITHUB_REPOSITORY" --workflow 
labeler.yml \
               --branch master --status success --limit 1 --json startedAt \
   ```
   
   **Verification:**
   - **Regression:** Running the List PRs step as changed in a directory that 
is not a git checkout, with `GITHUB_REPOSITORY` set to apache/spark, no 
`GH_REPO`, and the step's default `bash -e` shell, the run-history query 
resolves the repository instead of exiting with `failed to determine base 
repo`, so the step goes on to compute its window.
   - **Inspection:** The `list` job still has no checkout step and holds only 
`actions: read` and `pull-requests: read`, and every `gh` command in its List 
PRs step names the repository through `--repo` or an explicit 
`repos/$GITHUB_REPOSITORY/...` path.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to