matrei commented on code in PR #16779:
URL: https://github.com/apache/grails-core/pull/16779#discussion_r4401754903


##########
.github/workflows/cancel-unneeded-pr-runs.yml:
##########
@@ -0,0 +1,80 @@
+# 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
+#
+#     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.
+
+# Merging a pull request, or labelling it "no ci", does not stop the runs 
still queued or in progress for its head
+# commit, and their result can no longer change anything. This workflow 
cancels the pull_request runs of every
+# open pull request labelled "no ci", and on a push to a release branch also 
those of every pull request merged by
+# the pushed commit that were created before the merge. A run is kept when an 
open pull request not labelled
+# "no ci" has the same head commit, since it reports for that pull request 
too. A pull_request run from a fork gets
+# a read-only token, so the label only cancels at once on a pull request from 
this repository; the runs of a fork's
+# pull request are cancelled by the next push to a release branch. That is 
also why merges are found from the push
+# and not from the pull request being closed.
+name: "Cancel Unneeded PR Runs"
+on:
+  push:
+    branches:
+      - '[0-9]+.[0-9]+.x'
+  pull_request:
+    types: [ labeled ]
+permissions:
+  actions: write
+  contents: read
+  pull-requests: read
+jobs:
+  cancel:
+    name: "Cancel Unneeded PR Runs"
+    # Unlike every other workflow that reacts to a pull request, the "no ci" 
label runs this one rather than skipping it.
+    if: >-
+      github.event_name == 'push'
+      || (github.event.label.name == 'no ci' && 
github.event.pull_request.head.repo.full_name == github.repository)
+    runs-on: ubuntu-slim
+    timeout-minutes: 5
+    steps:
+      - name: "🛑 Cancel the runs of merged and \"no ci\" pull requests"
+        env:
+          EVENT: ${{ github.event_name }}
+          GH_TOKEN: ${{ github.token }}
+          REPO: ${{ github.repository }}
+          SHA: ${{ github.sha }}
+        run: |
+          # Every open pull request as its head repository, its head commit 
and whether it is labelled "no ci".
+          gh api --paginate "repos/$REPO/pulls?state=open&per_page=100" \
+            --jq '.[] | [.head.repo.full_name, .head.sha, (any(.labels[]; 
.name == "no ci") | tostring)] | @tsv' > open.tsv
+          # The head repository and head commit of each pull request whose 
runs are unneeded, with the time its runs
+          # must have been created before: the merge, or now for a pull 
request labelled "no ci".
+          {
+            if [[ "$EVENT" == push ]]; then
+              gh api "repos/$REPO/commits/$SHA/pulls" \
+                --jq '.[] | select(.merged_at != null) | 
[.head.repo.full_name, .head.sha, .merged_at] | @tsv'

Review Comment:
   On 7.0.x, 7.1.x and 7.2.x the push after a merge builds without tests, and 
AGENTS.md says a backport's tests belong on the pull request, labelled `run 
ci`. There, the pull request's run is the only test result the change gets on 
7.x, so its result can still change something after the merge: a late failure 
means a follow-up fix. Cancelling it leaves the change untested on that branch.
   
   It hasn't happened yet: every `run ci` pull request into 7.0.x among the 
last 40 merges had finished its tests before it was merged. So this is about 
what the rule does, not about anything it would have cancelled. Keeping the 
runs of merged pull requests labelled `run ci` would cover it:
   
   ```yaml
                   --jq '.[] | select(.merged_at != null and (any(.labels[]; 
.name == "run ci") | not)) | [.head.repo.full_name, .head.sha, .merged_at] | 
@tsv'
   ```
   
   The header comment's "their result can no longer change anything" and the 
AGENTS.md bullet would then need a sentence on it.



##########
CONTRIBUTING.md:
##########
@@ -278,10 +278,12 @@ Every push and pull request runs the GitHub Actions 
workflows, and runner time i
 project, so two controls limit what runs:
 
 * A draft pull request runs no workflow unless it carries the `run ci` label; 
marking it ready for review starts CI.
-  A pull request labelled `no ci` runs no workflow at all, draft or not. (The 
Release Drafter still labels every
-  pull request into a release branch; it runs no build.) Labels are read when 
a push arrives, so add `run ci` (or
-  remove `no ci`) and then push, or mark the draft ready, to get a run. 
Pushing to a draft still cancels the run in
-  flight for it, as every push to a pull request or a branch does.
+  A pull request labelled `no ci` runs no workflow at all, draft or not. 
Labels are read when a push arrives, so add
+  `run ci` (or remove `no ci`) and then push, or mark the draft ready, to get 
a run. Pushing to a draft still cancels
+  the run in flight for it, as every push to a pull request or a branch does.
+* Adding `no ci` to a pull request cancels the runs it has in flight, and 
merging a pull request cancels the runs

Review Comment:
   Nit: the push trigger only covers release branches, so merging a pull 
request into a side branch (#16750, #16735 and #16696 recently) cancels 
nothing. AGENTS.md says "on a push to a release branch"; this could say 
"merging a pull request into a release branch".



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

Reply via email to