From 194db036c43f76a425f936643b06f11de490d546 Mon Sep 17 00:00:00 2001 From: Scott Murphy Heiberg Date: Wed, 18 Nov 2026 07:48:25 -0800 Subject: [PATCH 01/12] Keep an approval when the pushes after it only merge the base branch GitHub moves an approval to the new head after a merge of the base branch that leaves the diff of the pull request as it was, but not after one that had conflicts, since resolving them changes that diff. The workflow then dismissed the approval, although the pull request got no change to review. The workflow now repeats each merge between the approved commit and the head with git merge-tree, in a bare repository holding only the trees of the merge's parents and of their merge base. The approval is kept when every commit on the way has two parents, the second one a commit of the base branch, and differs from git's own merge only in the conflicted files. A merge that changes another file by hand, or that merges another branch, dismisses the approval as before. --- .github/workflows/dismiss-stale-reviews.yml | 54 ++++++++++++++++++--- AGENTS.md | 2 +- CONTRIBUTING.md | 6 ++- 3 files changed, 52 insertions(+), 10 deletions(-) diff --git a/.github/workflows/dismiss-stale-reviews.yml b/.github/workflows/dismiss-stale-reviews.yml index 30cb18dad77..848ee50e387 100644 --- a/.github/workflows/dismiss-stale-reviews.yml +++ b/.github/workflows/dismiss-stale-reviews.yml @@ -19,11 +19,18 @@ # approval to the new head by itself after a push that leaves the diff of the pull request as it was, such as a rebase # or a merge of the base branch, so those approvals are kept. # +# GitHub does not move an approval over a merge of the base branch that had conflicts, since resolving them changes +# the diff of the pull request. Such an update merge is not a change of the pull request to review again, so the +# approval is kept as well, as long as every commit pushed after it is a merge of the base branch that differs from +# the merge git makes by itself only in the files git could not merge. A merge that also changes another file, or +# that merges anything but the base branch, dismisses the approval like any other push. +# # A pull_request run from a fork gets a read-only token that cannot dismiss a review, so this workflow does not react # to the pull request. It reacts to the Code Style workflow being requested for one, which a push to a pull request # does, even for a draft or a pull request labelled "no ci", whose jobs are then skipped. A workflow_run run uses the # workflow file of the default branch and a token of this repository, and it never checks out or runs anything of the -# pull request: it only reads commit ids through the API. +# pull request: it reads commit ids through the API and, to repeat a merge, fetches the trees of its commits and +# merges them in a bare repository, which runs no hook and no filter. # # Not every push requests the Code Style workflow: GitHub starts no pull_request workflow for a commit whose message # asks to skip them ("[skip ci]" and its variants), nor for a pull request that conflicts with its base branch. So @@ -61,13 +68,42 @@ jobs: # Empty on a scheduled and on a manual run, which look at every open pull request. SHA: ${{ github.event.workflow_run.head_sha }} run: | + # Whether every commit from the approved one to the head is a merge of the base branch that changes nothing + # by hand outside the files git could not merge. Each commit on the way has to have two parents, the + # second one a commit of the base branch, and its tree is compared with the one git merges from those + # parents: the files that differ have to be among the conflicted ones. Three commits are fetched for a + # merge, its parents and their merge base, without history and without file contents; git then asks for + # the contents of the files changed on both sides only. Anything unexpected, such as a failed request, + # an unknown commit or more merges than the limit, answers no, and the approval is dismissed. + only_merges_base() { + local base=$1 approved=$2 commit=$3 merges=0 first second other fork merged tree changed + while [[ "$commit" != "$approved" ]]; do + (( ++merges <= 20 )) || return 1 + read -r first second other < <(gh api "repos/$REPO/commits/$commit" --jq '[.parents[].sha] | join(" ")') + [[ -n "$second" && -z "$other" ]] || return 1 + [[ "$(gh api "repos/$REPO/compare/$second...$base?per_page=1" --jq '.behind_by')" == 0 ]] || return 1 + fork=$(gh api "repos/$REPO/compare/$first...$second?per_page=1" --jq '.merge_base_commit.sha') || return 1 + [[ -n "$fork" ]] || return 1 + git -C merges.git fetch --quiet --depth=1 --filter=blob:none origin "$commit" "$first" "$second" "$fork" || return 1 + # The first line is the merged tree, the lines after it name the conflicted files, which fail the command. + merged=$(git -C merges.git merge-tree --write-tree --name-only --no-messages --merge-base="$fork" "$first" "$second") || [[ $? == 1 ]] || return 1 + tree=${merged%%$'\n'*} + changed=$(git -C merges.git diff --name-only --no-renames "$tree" "$commit^{tree}") || return 1 + [[ -z "$(comm -23 <(sort <<< "$changed") <(tail -n +2 <<< "$merged" | sort))" ]] || return 1 + commit=$first + done + } + git init --quiet --bare merges.git + git -C merges.git remote add origin "$GITHUB_SERVER_URL/$REPO" + git -C merges.git config "http.$GITHUB_SERVER_URL/.extraheader" "AUTHORIZATION: basic $(printf 'x-access-token:%s' "$GH_TOKEN" | base64 -w0)" # The approvals given to another commit than the head, of every open pull request or of the ones whose head # is the pushed commit. A review dismissed earlier is no longer an approval. GitHub has already moved an # approval to the head when the push left the diff of the pull request as it was, so an approval still at - # another commit was given to other changes. Nothing is compared here but the trees of the two commits: an - # approval is kept when its commit has the very tree of the head, which holds the content, the name and - # the mode of every file, and dismissed otherwise, also when either tree is unknown. One query serves a - # hundred pull requests, so that the hourly run does not spend a request of the token's rate limit on each. + # another commit was given to other changes. Only two of those are kept: an approval whose commit has the + # very tree of the head, which holds the content, the name and the mode of every file, and an approval + # that only merges of the base branch separate from the head (see only_merges_base). Every other one is + # dismissed, also when a tree is unknown. One query serves a hundred pull requests, so that the hourly run + # does not spend a request of the token's rate limit on each. gh api graphql --paginate -f owner="${REPO%/*}" -f name="${REPO#*/}" -f query=' query($owner: String!, $name: String!, $endCursor: String) { repository(owner: $owner, name: $name) { @@ -75,6 +111,7 @@ jobs: pageInfo { hasNextPage endCursor } nodes { number headRefOid + baseRef { target { oid } } commits(last: 1) { nodes { commit { oid tree { oid } } } } reviews(states: APPROVED, first: 100) { nodes { databaseId author { login } commit { oid tree { oid } } } } } @@ -84,10 +121,13 @@ jobs: | ([.commits.nodes[].commit | select(.oid == $pull.headRefOid) | .tree.oid][0] // "-") as $tree | .reviews.nodes[] | select(.commit.oid != $pull.headRefOid) | [$pull.number, $pull.headRefOid, .databaseId, .author.login // "ghost", .commit.oid // "-", - (if $tree != "-" and .commit.tree.oid == $tree then "same" else "changed" end)] | @tsv' > stale.tsv - while IFS=$'\t' read -r number head review login commit tree; do + (if $tree != "-" and .commit.tree.oid == $tree then "same" else "changed" end), + $pull.baseRef.target.oid // "-"] | @tsv' > stale.tsv + while IFS=$'\t' read -r number head review login commit tree base; do if [[ "$tree" == same ]]; then echo "#$number: approval of $login at ${commit:0:10} kept, ${head:0:10} has the same files" + elif [[ "$commit" != - && "$base" != - ]] && only_merges_base "$base" "$commit" "$head" < /dev/null; then + echo "#$number: approval of $login at ${commit:0:10} kept, ${head:0:10} only merges the base branch" elif [[ "$DRY_RUN" == true ]]; then echo "#$number: approval of $login at ${commit:0:10} would be dismissed, the head is ${head:0:10}" | tee -a "$GITHUB_STEP_SUMMARY" elif gh api -X PUT "repos/$REPO/pulls/$number/reviews/$review/dismissals" -f event=DISMISS \ diff --git a/AGENTS.md b/AGENTS.md index aa00ff5d674..635d304b34c 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -253,7 +253,7 @@ GitHub-hosted runner time is shared with every other Apache project, so the work - A draft pull request runs nothing unless it carries the `run ci` label, and a pull request labelled `no ci` runs nothing at all: every workflow that reacts to a pull request skips all of its jobs, except `cancel-unneeded-pr-runs.yml`, described below. The Release Drafter (`release-notes.yml`) does not react to pull requests: the action it pins cannot label them, and it builds the draft from merged pull requests, so it runs on pushes to a release branch. Marking a draft ready for review starts CI (the workflows list the `ready_for_review` trigger type, which is not a default). Labels and the draft flag are read when a run starts, so set them before pushing; adding `run ci` or removing `no ci` takes effect on the next push, or when the draft is marked ready, while adding `no ci` cancels the runs in flight (see below). A push to a draft, or to a `no ci` pull request, still cancels the run in flight for that pull request, as every push to a pull request or a branch does through the concurrency groups of the test workflows; the run that replaces it does nothing. A new workflow with a `pull_request` trigger lists the same `types` as its siblings and gates its jobs the same way. - Merging a pull request, or labelling it `no ci`, cancels its runs in flight: `cancel-unneeded-pr-runs.yml` cancels the queued, pending and in-progress `pull_request` runs of every open pull request labelled `no ci`, and on a push to a release branch also those of each pull request the pushed commit merged that were created before the merge. A run is kept while an open pull request not labelled `no ci` has the same head commit, and the runs of a merged pull request labelled `run ci` are kept too: on a release branch below the default, the push after the merge builds without the tests, so the tests the label asked for on the pull request are the only ones the change gets there, and a late failure still calls for a follow-up fix. The workflow runs on every push to a release branch and when a pull request is labelled `no ci`, but a `pull_request` run from a fork gets a read-only token that cannot cancel runs, so labelling a fork's pull request skips the job, and that pull request's runs are cancelled by the next push to a release branch. For the same reason merges are found from the push rather than from the pull request being closed. It lists the unfinished `pull_request` runs of the repository once per sweep, not once per pull request, to spare the `GITHUB_TOKEN` rate limit. -- A push that changes a pull request dismisses the approvals given before it: `dismiss-stale-reviews.yml` dismisses every approval that was given to another commit than the head of the pull request. GitHub itself moves an approval to the new head after a push that leaves the diff of the pull request as it was, such as a rebase or a merge of the base branch, so those approvals are kept. The release branches do not require pull requests, so GitHub's own stale-review setting, which is part of that requirement, is not available. The workflow reacts to the Code Style workflow being requested for a pull request (`workflow_run`), not to the pull request, because a `pull_request` run from a fork gets a read-only token that cannot dismiss a review; it therefore runs from the default branch, also for a draft or a pull request labelled `no ci`, and it never checks out the pull request. Renaming the Code Style workflow, or dropping its `pull_request` trigger, stops it. The workflow compares no diff: an approval GitHub has not moved is dismissed unless its commit has the very tree of the head, so a push that only changes a space, moves an edit to another method, or changes the mode of a file dismisses it. GitHub starts no `pull_request` workflow for a commit whose message asks to skip them (`[skip ci]` and its variants) or for a pull request that conflicts with its base branch, so the workflow also looks at every open pull request once an hour (`schedule`); an approval can outlive such a push by at most that long. A manual run looks at every open pull request too and only reports, unless its `dry-run` input is cleared. +- A push that changes a pull request dismisses the approvals given before it: `dismiss-stale-reviews.yml` dismisses every approval that was given to another commit than the head of the pull request. GitHub itself moves an approval to the new head after a push that leaves the diff of the pull request as it was, such as a rebase or a merge of the base branch, so those approvals are kept. The release branches do not require pull requests, so GitHub's own stale-review setting, which is part of that requirement, is not available. The workflow reacts to the Code Style workflow being requested for a pull request (`workflow_run`), not to the pull request, because a `pull_request` run from a fork gets a read-only token that cannot dismiss a review; it therefore runs from the default branch, also for a draft or a pull request labelled `no ci`, and it never checks out the pull request. Renaming the Code Style workflow, or dropping its `pull_request` trigger, stops it. The workflow compares no diff: an approval GitHub has not moved is dismissed unless its commit has the very tree of the head, so a push that only changes a space, moves an edit to another method, or changes the mode of a file dismisses it. The one other approval kept is one that only update merges separate from the head. GitHub does not move an approval over a merge of the base branch that had conflicts, because resolving them changes the diff of the pull request, so the workflow repeats each merge (`git merge-tree` in a bare repository, on trees fetched without history; nothing of the pull request is checked out or run) and keeps the approval when every commit after the approved one has two parents, the second a commit of the base branch, and differs from the merge git makes by itself only in the files git could not merge. A merge that changes any other file by hand, that merges another branch, or that follows an ordinary commit pushed after the approval dismisses it. GitHub starts no `pull_request` workflow for a commit whose message asks to skip them (`[skip ci]` and its variants) or for a pull request that conflicts with its base branch, so the workflow also looks at every open pull request once an hour (`schedule`); an approval can outlive such a push by at most that long. A manual run looks at every open pull request too and only reports, unless its `dry-run` input is cleared. - Every workflow that runs tests calls `.github/workflows/ci-policy.yml` as its first job, `policy`, and gates its test jobs (and the test steps of its build jobs) on `needs.policy.outputs.run-tests`. Never test `github.event.head_commit.message` in a workflow: a `pull_request` payload has no such field, so that test silently ran the tests on every pull request. The policy reads the head commit of the push, of the pull request, or of the dispatched branch, and matches the marker against the start of the message's first line. The read is retried with a growing pause; when it still fails, the tests run, as they did before the policy existed, and a warning annotation and the step summary say so, so an API outage costs runner time rather than a test result. - The tests run by default only on the default branch and the release branches above it, and there a commit message starting with `[skip tests]` skips them. Everywhere else, that is on a release branch below the default (7.0.x, 7.1.x and 7.2.x while 8.0.x is the default) and on a pull request whose base is a side branch rather than a release branch, the tests run only on request: when the commit message starts with `[run tests]`, when the pull request carries the `run ci` label, or when a manual run (`workflow_dispatch`) in `apache/grails-core` has its `run-tests` input ticked. Otherwise the run builds, and on a push publishes snapshots, without tests, exactly like a `[skip tests]` commit; a `[skip tests]` commit also wins over the label and the input. The label is the way to test a backport pull request without rewriting its head commit, and the input is how the commit a release is cut from gets tested (see RELEASE.md); both are read when the run starts. A marker anywhere but at the start of the first line is ignored. The rule follows the default branch: when a new one is promoted, the branches below it stop running tests by default without an edit. The older release branches are kept quiet on purpose: a backport lands as one push to the oldest branch and a merge-up to each branch above it, and its tests belong on the pull request, labelled `run ci`, not on every push after it. Side branches are unreviewed development work (see the review process in CONTRIBUTING.md); their tests run when the branch is proposed to a release branch. In a fork, where the runner time is the fork owner's and not the ASF's, a manual run runs the tests unless the commit message starts with `[skip tests]`. - The jobs that run no tests (dependency validation, the build-without-tests steps, code style and build health) still run on every push to a release branch and on every non-draft pull request; RAT and CodeQL run on every push to a release branch and on every non-draft pull request into one, since their `pull_request` triggers list only release-branch bases. Only the `no ci` label, or a draft without `run ci`, stops them. The snapshot publish runs on every push to a release branch and on a manual run (the docs publish only on a push), never on a pull request. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ddef0359ace..99320c0ed4b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -315,8 +315,10 @@ Concerning when a review is required for a `protected` branch: An approval covers the changes that were reviewed. When a later push changes a pull request, the approvals given before it are dismissed automatically and the pull request has to be approved again; a rebase, or a merge of the base -branch, that leaves the changes of the pull request as they were keeps them. A dismissed approval does not block the -merge button, so check the review state of a pull request before merging it. +branch, that leaves the changes of the pull request as they were keeps them. A merge of the base branch that had +conflicts keeps them too, as long as it changes nothing by hand outside the conflicted files, so resolve the conflicts +in the merge commit and push any other change as a commit of its own. A dismissed approval does not block the merge +button, so check the review state of a pull request before merging it. ## Join The Project Team For people willing to contribute more than an occasional pull request, consider joining our core team. Inquire in the `questions` channel in slack to learn more. From a695d6bf66fbe565d2b7d91b2f462cfa64e185dc Mon Sep 17 00:00:00 2001 From: Scott Murphy Heiberg Date: Wed, 18 Nov 2026 07:51:42 -0800 Subject: [PATCH 02/12] Bound the git commands that repeat a merge A fetch or a merge that hangs would end the job at its timeout, and with it the dismissals of every pull request listed after that one, on each run. Each git command now gets two minutes, after which the approval is dismissed like any other the workflow cannot verify. --- .github/workflows/dismiss-stale-reviews.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/dismiss-stale-reviews.yml b/.github/workflows/dismiss-stale-reviews.yml index 848ee50e387..ee6b68ad58f 100644 --- a/.github/workflows/dismiss-stale-reviews.yml +++ b/.github/workflows/dismiss-stale-reviews.yml @@ -74,7 +74,9 @@ jobs: # parents: the files that differ have to be among the conflicted ones. Three commits are fetched for a # merge, its parents and their merge base, without history and without file contents; git then asks for # the contents of the files changed on both sides only. Anything unexpected, such as a failed request, - # an unknown commit or more merges than the limit, answers no, and the approval is dismissed. + # an unknown commit or more merges than the limit, answers no, and the approval is dismissed. So does a + # git command that takes too long: left to hang, it would end the job at its timeout and with it the + # dismissals of every pull request after this one, on each run. only_merges_base() { local base=$1 approved=$2 commit=$3 merges=0 first second other fork merged tree changed while [[ "$commit" != "$approved" ]]; do @@ -84,11 +86,11 @@ jobs: [[ "$(gh api "repos/$REPO/compare/$second...$base?per_page=1" --jq '.behind_by')" == 0 ]] || return 1 fork=$(gh api "repos/$REPO/compare/$first...$second?per_page=1" --jq '.merge_base_commit.sha') || return 1 [[ -n "$fork" ]] || return 1 - git -C merges.git fetch --quiet --depth=1 --filter=blob:none origin "$commit" "$first" "$second" "$fork" || return 1 + timeout 120 git -C merges.git fetch --quiet --depth=1 --filter=blob:none origin "$commit" "$first" "$second" "$fork" || return 1 # The first line is the merged tree, the lines after it name the conflicted files, which fail the command. - merged=$(git -C merges.git merge-tree --write-tree --name-only --no-messages --merge-base="$fork" "$first" "$second") || [[ $? == 1 ]] || return 1 + merged=$(timeout 120 git -C merges.git merge-tree --write-tree --name-only --no-messages --merge-base="$fork" "$first" "$second") || [[ $? == 1 ]] || return 1 tree=${merged%%$'\n'*} - changed=$(git -C merges.git diff --name-only --no-renames "$tree" "$commit^{tree}") || return 1 + changed=$(timeout 120 git -C merges.git diff --name-only --no-renames "$tree" "$commit^{tree}") || return 1 [[ -z "$(comm -23 <(sort <<< "$changed") <(tail -n +2 <<< "$merged" | sort))" ]] || return 1 commit=$first done From eb50ebc977396b8253080770e4ab1e8936d79e19 Mon Sep 17 00:00:00 2001 From: Scott Murphy Heiberg Date: Wed, 18 Nov 2026 10:34:40 -0800 Subject: [PATCH 03/12] Accept a conflict resolution only inside the conflicts A merge of the base branch kept an approval when the files it changed by hand were among the conflicted ones, whatever it changed in them, so a merge could add an unreviewed line anywhere in a conflicted file. The merged file git writes holds each conflict between markers labelled with the two parents; the pushed file now has to keep every line outside them, and its mode, as git wrote them. A conflict without markers, of a binary file or of a file deleted on one side, dismisses the approval when it was resolved by hand. A kept approval and the files whose conflicts were resolved now go to the step summary, and the pull request gets one comment per merge naming them, found again by a hidden marker so that the hourly run does not repeat it. The walk over the merges states why it gave up: more than 20 commits, or a request or git command that failed or ran out of the two minutes the walk now has as a whole, is dismissed as not checked rather than as a change of the pull request. Its answer is reused within a run for every approval given to the same commit. --- .github/workflows/dismiss-stale-reviews.yml | 150 ++++++++++++++++---- 1 file changed, 126 insertions(+), 24 deletions(-) diff --git a/.github/workflows/dismiss-stale-reviews.yml b/.github/workflows/dismiss-stale-reviews.yml index ee6b68ad58f..2fdc80e2b26 100644 --- a/.github/workflows/dismiss-stale-reviews.yml +++ b/.github/workflows/dismiss-stale-reviews.yml @@ -22,8 +22,10 @@ # GitHub does not move an approval over a merge of the base branch that had conflicts, since resolving them changes # the diff of the pull request. Such an update merge is not a change of the pull request to review again, so the # approval is kept as well, as long as every commit pushed after it is a merge of the base branch that differs from -# the merge git makes by itself only in the files git could not merge. A merge that also changes another file, or -# that merges anything but the base branch, dismisses the approval like any other push. +# the merge git makes by itself only inside the conflicts git could not merge. The pull request then gets a comment +# naming the files whose conflicts were resolved, once for each merge, since nobody reviewed the resolution. A merge +# that changes any other line, or that merges anything but the base branch, dismisses the approval like any other +# push, and so does a walk over the merges that cannot finish: more than 20 commits, or more than two minutes. # # A pull_request run from a fork gets a read-only token that cannot dismiss a review, so this workflow does not react # to the pull request. It reacts to the Code Style workflow being requested for one, which a push to a pull request @@ -68,33 +70,129 @@ jobs: # Empty on a scheduled and on a manual run, which look at every open pull request. SHA: ${{ github.event.workflow_run.head_sha }} run: | + # A check of the merges after an approval has two minutes. Each git and gh command it runs gets what is left + # of them: a request or a fetch left to hang would end the job at its timeout, and with it the dismissals + # of every pull request after this one, on each run. + export GIT_LITERAL_PATHSPECS=1 + bounded() { + local left=$(( deadline - SECONDS )) + (( left > 0 )) || return 124 + timeout "$left" "$@" + } + # Whether a merge commit changed a conflicted file only inside its conflicts. The file git merges by itself + # holds each conflict between markers labelled with the two parents, and the pushed file has to keep every + # line outside them as it is, with the same mode. Answers 1 when it does not, also for a conflict git + # writes without markers, such as one of a binary file or of a file deleted on one side, which leaves no + # line to tell the resolution by; and 2 when a git command fails. + resolved_within_conflicts() { + local tree=$1 commit=$2 path=$3 first=$4 second=$5 entry regions hunks + entry=$(bounded git -C merges.git ls-tree --format='%(objectmode) %(objecttype)' "$tree" -- "$path") || return 2 + [[ "$entry" == 100*' blob' ]] || return 1 + [[ "$(bounded git -C merges.git ls-tree --format='%(objectmode) %(objecttype)' "$commit" -- "$path")" == "$entry" ]] || return 1 + # The first and last line of each conflict. A marker is matched with its label, the id of a parent, so + # that a line of the file that merely looks like one does not open a conflict. + regions=$(bounded git -C merges.git cat-file blob "$tree:$path" | awk -v opening="<<<<<<< $first" -v closing=">>>>>>> $second" ' + { sub(/\r$/, "") } + $0 == opening || index($0, opening ":") == 1 { if (start) exit 1; start = NR; next } + $0 == closing || index($0, closing ":") == 1 { if (!start) exit 1; printf "%d %d ", start, NR; start = 0 } + END { if (start) exit 1 }') || return 2 + [[ -n "$regions" ]] || return 1 + # Every line the merge commit removed or replaced lies in a conflict, and every line it inserted sits in + # or next to one. --text makes git compare a file it takes for binary line by line too, rather than only + # say that it differs. + hunks=$(bounded git -C merges.git diff -U0 --text --no-ext-diff --no-textconv --no-color "$tree:$path" "$commit:$path") || return 2 + awk -v regions="$regions" ' + BEGIN { n = split(regions, r, " ") } + /^@@ / { + split(substr($2, 2), h, ","); at = h[1] + 0; count = (2 in h) ? h[2] + 0 : 1; inside = 0 + for (i = 1; i < n; i += 2) + if (count > 0 ? (r[i] <= at && at + count - 1 <= r[i + 1]) : (r[i] - 1 <= at && at <= r[i + 1])) inside = 1 + if (!inside) exit 1 + }' <<< "$hunks" || return 1 + } # Whether every commit from the approved one to the head is a merge of the base branch that changes nothing - # by hand outside the files git could not merge. Each commit on the way has to have two parents, the + # by hand outside the conflicts git could not merge. Each commit on the way has to have two parents, the # second one a commit of the base branch, and its tree is compared with the one git merges from those - # parents: the files that differ have to be among the conflicted ones. Three commits are fetched for a - # merge, its parents and their merge base, without history and without file contents; git then asks for - # the contents of the files changed on both sides only. Anything unexpected, such as a failed request, - # an unknown commit or more merges than the limit, answers no, and the approval is dismissed. So does a - # git command that takes too long: left to hang, it would end the job at its timeout and with it the - # dismissals of every pull request after this one, on each run. + # parents: the files that differ have to be conflicted ones, changed only inside their conflicts. Three + # commits are fetched for a merge, its parents and their merge base, without history and without file + # contents; git then asks for the contents of the files changed on both sides, and of the conflicted files + # of the merge commit. Sets the reason of a dismissal, and lists the files whose conflicts were resolved by + # hand, one line with the merge and the file each. A commit that is not such a merge answers no, and so does + # anything that keeps the check from finishing: a failed request, a git command that fails or runs out of + # time, or more merges than the limit, which bounds what an approval kept this way, whose commit GitHub does + # not move, costs each hourly run. only_merges_base() { - local base=$1 approved=$2 commit=$3 merges=0 first second other fork merged tree changed + local base=$1 approved=$2 commit=$3 merges=0 deadline=$(( SECONDS + 120 )) first second other behind fork merged tree conflicts changed path + accepted= + reason="the commits after this approval could not be checked" while [[ "$commit" != "$approved" ]]; do - (( ++merges <= 20 )) || return 1 - read -r first second other < <(gh api "repos/$REPO/commits/$commit" --jq '[.parents[].sha] | join(" ")') - [[ -n "$second" && -z "$other" ]] || return 1 - [[ "$(gh api "repos/$REPO/compare/$second...$base?per_page=1" --jq '.behind_by')" == 0 ]] || return 1 - fork=$(gh api "repos/$REPO/compare/$first...$second?per_page=1" --jq '.merge_base_commit.sha') || return 1 + if (( ++merges > 20 )); then + reason="more than 20 commits followed this approval, more than this workflow checks" + return 1 + fi + read -r first second other < <(bounded gh api "repos/$REPO/commits/$commit" --jq '[.parents[].sha] | join(" ")') + [[ -n "$first" ]] || return 1 + [[ -n "$second" && -z "$other" ]] || { reason="the pull request changed after this approval"; return 1; } + behind=$(bounded gh api "repos/$REPO/compare/$second...$base?per_page=1" --jq '.behind_by') || return 1 + [[ "$behind" == 0 ]] || { reason="the pull request changed after this approval"; return 1; } + fork=$(bounded gh api "repos/$REPO/compare/$first...$second?per_page=1" --jq '.merge_base_commit.sha') || return 1 [[ -n "$fork" ]] || return 1 - timeout 120 git -C merges.git fetch --quiet --depth=1 --filter=blob:none origin "$commit" "$first" "$second" "$fork" || return 1 + bounded git -C merges.git fetch --quiet --depth=1 --filter=blob:none origin "$commit" "$first" "$second" "$fork" || return 1 # The first line is the merged tree, the lines after it name the conflicted files, which fail the command. - merged=$(timeout 120 git -C merges.git merge-tree --write-tree --name-only --no-messages --merge-base="$fork" "$first" "$second") || [[ $? == 1 ]] || return 1 + merged=$(bounded git -C merges.git -c merge.conflictStyle=merge merge-tree --write-tree --name-only --no-messages --merge-base="$fork" "$first" "$second") || [[ $? == 1 ]] || return 1 tree=${merged%%$'\n'*} - changed=$(timeout 120 git -C merges.git diff --name-only --no-renames "$tree" "$commit^{tree}") || return 1 - [[ -z "$(comm -23 <(sort <<< "$changed") <(tail -n +2 <<< "$merged" | sort))" ]] || return 1 + conflicts=$(tail -n +2 <<< "$merged") + changed=$(bounded git -C merges.git diff --name-only --no-renames "$tree" "$commit^{tree}") || return 1 + while IFS= read -r path; do + [[ -n "$path" ]] || continue + grep -qxF -- "$path" <<< "$conflicts" || { reason="the pull request changed after this approval"; return 1; } + resolved_within_conflicts "$tree" "$commit" "$path" "$first" "$second" || { + (( $? == 1 )) && reason="the pull request changed after this approval" + return 1 + } + accepted+="$commit $path"$'\n' + done <<< "$changed" commit=$first done } + # The answer of only_merges_base, worked out once per run for the same approved commit, head and base + # branch, such as for two approvals given to the same commit. + declare -A answers=() reasons=() resolutions=() + checked_merges() { + local key="$1 $2 $3" + if [[ -z "${answers[$key]+set}" ]]; then + only_merges_base "$@" < /dev/null + answers[$key]=$? reasons[$key]=$reason resolutions[$key]=$accepted + fi + reason=${reasons[$key]} accepted=${resolutions[$key]} + return "${answers[$key]}" + } + # A conflict resolution that keeps an approval was not reviewed, so the pull request says which files each + # merge resolved, once for each merge: every comment of this workflow names its merges in a hidden marker, + # and the markers are read once per pull request and run, before the first comment. + declare -A noted=() + note_resolutions() { + local number=$1 merges merge sha path files body + [[ -n "$accepted" && "$DRY_RUN" != true ]] || return 0 + if [[ -z "${noted[$number]+set}" ]]; then + noted[$number]=$(timeout 60 gh api --paginate "repos/$REPO/issues/$number/comments" \ + --jq '.[] | select(.user.login == "github-actions[bot]") | .body | scan("") | .[0]') || { + unset "noted[$number]" + return 1 + } + fi + merges=$(cut -d ' ' -f 1 <<< "$accepted" | awk 'NF && !seen[$0]++' | grep -vxF -f <(printf '%s\n' "${noted[$number]}")) || return 0 + body="An approval of this pull request was kept across merges of the base branch whose conflicts were resolved by hand. Each resolution changes the files below only inside the conflicts git could not merge, and nobody has reviewed it yet."$'\n' + for merge in $merges; do + files= + while read -r sha path; do + [[ "$sha" == "$merge" ]] && files+="${files:+, }\`${path//\`/}\`" + done <<< "$accepted" + body+=$'\n'"- $merge: $files " + done + timeout 60 gh api "repos/$REPO/issues/$number/comments" -f body="$body" > /dev/null || return 1 + noted[$number]+=$'\n'"$merges" + } git init --quiet --bare merges.git git -C merges.git remote add origin "$GITHUB_SERVER_URL/$REPO" git -C merges.git config "http.$GITHUB_SERVER_URL/.extraheader" "AUTHORIZATION: basic $(printf 'x-access-token:%s' "$GH_TOKEN" | base64 -w0)" @@ -126,15 +224,19 @@ jobs: (if $tree != "-" and .commit.tree.oid == $tree then "same" else "changed" end), $pull.baseRef.target.oid // "-"] | @tsv' > stale.tsv while IFS=$'\t' read -r number head review login commit tree base; do + reason="the pull request changed after this approval" accepted= if [[ "$tree" == same ]]; then echo "#$number: approval of $login at ${commit:0:10} kept, ${head:0:10} has the same files" - elif [[ "$commit" != - && "$base" != - ]] && only_merges_base "$base" "$commit" "$head" < /dev/null; then - echo "#$number: approval of $login at ${commit:0:10} kept, ${head:0:10} only merges the base branch" + elif [[ "$commit" != - && "$base" != - ]] && checked_merges "$base" "$commit" "$head"; then + echo "#$number: approval of $login at ${commit:0:10} kept, ${head:0:10} only merges the base branch$( + awk 'NF { files[$1] = files[$1] sep[$1] $2; sep[$1] = ", "; if (!($1 in seen)) order[++n] = $1; seen[$1] } + END { for (i = 1; i <= n; i++) printf "%s %s resolved %s", (i == 1 ? ";" : ","), substr(order[i], 1, 10), files[order[i]] }' <<< "$accepted")" | tee -a "$GITHUB_STEP_SUMMARY" + note_resolutions "$number" || echo "::warning title=Resolution not noted::Could not comment on pull request #$number about the conflicts resolved after an approval" elif [[ "$DRY_RUN" == true ]]; then - echo "#$number: approval of $login at ${commit:0:10} would be dismissed, the head is ${head:0:10}" | tee -a "$GITHUB_STEP_SUMMARY" + echo "#$number: approval of $login at ${commit:0:10} would be dismissed, $reason, the head is ${head:0:10}" | tee -a "$GITHUB_STEP_SUMMARY" elif gh api -X PUT "repos/$REPO/pulls/$number/reviews/$review/dismissals" -f event=DISMISS \ - -f message="Dismissed automatically: the pull request changed after this approval, from ${commit:0:10} to ${head:0:10}." > /dev/null; then - echo "#$number: approval of $login at ${commit:0:10} dismissed, the head is ${head:0:10}" | tee -a "$GITHUB_STEP_SUMMARY" + -f message="Dismissed automatically: $reason, from ${commit:0:10} to ${head:0:10}." > /dev/null; then + echo "#$number: approval of $login at ${commit:0:10} dismissed, $reason, the head is ${head:0:10}" | tee -a "$GITHUB_STEP_SUMMARY" else # Another run may have dismissed it first, which is the outcome wanted anyway. echo "::warning title=Review not dismissed::Could not dismiss review $review of $login on pull request #$number" From 1153680f8a8ea8f5d28d63652afc46c1407ce02c Mon Sep 17 00:00:00 2001 From: Scott Murphy Heiberg Date: Wed, 18 Nov 2026 10:34:40 -0800 Subject: [PATCH 04/12] Describe the conflict rule for kept approvals in the guides AGENTS.md said that the workflow compares no diff and then described a rule that repeats merges and compares them. The update-merge rule now comes first, and "compares no diff" is said of any other push. Both guides describe the narrower rule: only the lines inside the conflicts may change, and the pull request is told which files were resolved. --- AGENTS.md | 2 +- CONTRIBUTING.md | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 635d304b34c..c06927f4813 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -253,7 +253,7 @@ GitHub-hosted runner time is shared with every other Apache project, so the work - A draft pull request runs nothing unless it carries the `run ci` label, and a pull request labelled `no ci` runs nothing at all: every workflow that reacts to a pull request skips all of its jobs, except `cancel-unneeded-pr-runs.yml`, described below. The Release Drafter (`release-notes.yml`) does not react to pull requests: the action it pins cannot label them, and it builds the draft from merged pull requests, so it runs on pushes to a release branch. Marking a draft ready for review starts CI (the workflows list the `ready_for_review` trigger type, which is not a default). Labels and the draft flag are read when a run starts, so set them before pushing; adding `run ci` or removing `no ci` takes effect on the next push, or when the draft is marked ready, while adding `no ci` cancels the runs in flight (see below). A push to a draft, or to a `no ci` pull request, still cancels the run in flight for that pull request, as every push to a pull request or a branch does through the concurrency groups of the test workflows; the run that replaces it does nothing. A new workflow with a `pull_request` trigger lists the same `types` as its siblings and gates its jobs the same way. - Merging a pull request, or labelling it `no ci`, cancels its runs in flight: `cancel-unneeded-pr-runs.yml` cancels the queued, pending and in-progress `pull_request` runs of every open pull request labelled `no ci`, and on a push to a release branch also those of each pull request the pushed commit merged that were created before the merge. A run is kept while an open pull request not labelled `no ci` has the same head commit, and the runs of a merged pull request labelled `run ci` are kept too: on a release branch below the default, the push after the merge builds without the tests, so the tests the label asked for on the pull request are the only ones the change gets there, and a late failure still calls for a follow-up fix. The workflow runs on every push to a release branch and when a pull request is labelled `no ci`, but a `pull_request` run from a fork gets a read-only token that cannot cancel runs, so labelling a fork's pull request skips the job, and that pull request's runs are cancelled by the next push to a release branch. For the same reason merges are found from the push rather than from the pull request being closed. It lists the unfinished `pull_request` runs of the repository once per sweep, not once per pull request, to spare the `GITHUB_TOKEN` rate limit. -- A push that changes a pull request dismisses the approvals given before it: `dismiss-stale-reviews.yml` dismisses every approval that was given to another commit than the head of the pull request. GitHub itself moves an approval to the new head after a push that leaves the diff of the pull request as it was, such as a rebase or a merge of the base branch, so those approvals are kept. The release branches do not require pull requests, so GitHub's own stale-review setting, which is part of that requirement, is not available. The workflow reacts to the Code Style workflow being requested for a pull request (`workflow_run`), not to the pull request, because a `pull_request` run from a fork gets a read-only token that cannot dismiss a review; it therefore runs from the default branch, also for a draft or a pull request labelled `no ci`, and it never checks out the pull request. Renaming the Code Style workflow, or dropping its `pull_request` trigger, stops it. The workflow compares no diff: an approval GitHub has not moved is dismissed unless its commit has the very tree of the head, so a push that only changes a space, moves an edit to another method, or changes the mode of a file dismisses it. The one other approval kept is one that only update merges separate from the head. GitHub does not move an approval over a merge of the base branch that had conflicts, because resolving them changes the diff of the pull request, so the workflow repeats each merge (`git merge-tree` in a bare repository, on trees fetched without history; nothing of the pull request is checked out or run) and keeps the approval when every commit after the approved one has two parents, the second a commit of the base branch, and differs from the merge git makes by itself only in the files git could not merge. A merge that changes any other file by hand, that merges another branch, or that follows an ordinary commit pushed after the approval dismisses it. GitHub starts no `pull_request` workflow for a commit whose message asks to skip them (`[skip ci]` and its variants) or for a pull request that conflicts with its base branch, so the workflow also looks at every open pull request once an hour (`schedule`); an approval can outlive such a push by at most that long. A manual run looks at every open pull request too and only reports, unless its `dry-run` input is cleared. +- A push that changes a pull request dismisses the approvals given before it: `dismiss-stale-reviews.yml` dismisses every approval that was given to another commit than the head of the pull request. GitHub itself moves an approval to the new head after a push that leaves the diff of the pull request as it was, such as a rebase or a merge of the base branch, so those approvals are kept. The release branches do not require pull requests, so GitHub's own stale-review setting, which is part of that requirement, is not available. The workflow reacts to the Code Style workflow being requested for a pull request (`workflow_run`), not to the pull request, because a `pull_request` run from a fork gets a read-only token that cannot dismiss a review; it therefore runs from the default branch, also for a draft or a pull request labelled `no ci`, and it never checks out the pull request. Renaming the Code Style workflow, or dropping its `pull_request` trigger, stops it. One approval GitHub has not moved is still kept: one that only update merges separate from the head. GitHub does not move an approval over a merge of the base branch that had conflicts, because resolving them changes the diff of the pull request, so the workflow repeats each merge (`git merge-tree` in a bare repository, on trees fetched without history; nothing of the pull request is checked out or run) and keeps the approval when every commit after the approved one has two parents, the second a commit of the base branch, and differs from the merge git makes by itself only inside the conflicts git could not merge: every file it changes is a conflicted one, with its mode and every line outside the conflict markers as git wrote them. A merge that changes any other line, that resolves by hand a conflict git writes without markers (a binary file, a file deleted on one side), that merges another branch, or that follows an ordinary commit pushed after the approval dismisses it. A kept approval and the files whose conflicts were resolved go to the step summary, and the pull request gets one comment per merge naming them, since nobody reviewed the resolution; the comment carries a hidden marker with the merge, so the hourly run does not repeat it. The walk over the merges stops after 20 commits or two minutes and then dismisses the approval with a message saying the commits were not checked, not that the pull request changed; within a run its answer is reused for every approval given to the same commit. For any other push the workflow compares no diff: an approval GitHub has not moved is dismissed unless its commit has the very tree of the head, so a push that only changes a space, moves an edit to another method, or changes the mode of a file dismisses it. GitHub starts no `pull_request` workflow for a commit whose message asks to skip them (`[skip ci]` and its variants) or for a pull request that conflicts with its base branch, so the workflow also looks at every open pull request once an hour (`schedule`); an approval can outlive such a push by at most that long. A manual run looks at every open pull request too and only reports, unless its `dry-run` input is cleared. - Every workflow that runs tests calls `.github/workflows/ci-policy.yml` as its first job, `policy`, and gates its test jobs (and the test steps of its build jobs) on `needs.policy.outputs.run-tests`. Never test `github.event.head_commit.message` in a workflow: a `pull_request` payload has no such field, so that test silently ran the tests on every pull request. The policy reads the head commit of the push, of the pull request, or of the dispatched branch, and matches the marker against the start of the message's first line. The read is retried with a growing pause; when it still fails, the tests run, as they did before the policy existed, and a warning annotation and the step summary say so, so an API outage costs runner time rather than a test result. - The tests run by default only on the default branch and the release branches above it, and there a commit message starting with `[skip tests]` skips them. Everywhere else, that is on a release branch below the default (7.0.x, 7.1.x and 7.2.x while 8.0.x is the default) and on a pull request whose base is a side branch rather than a release branch, the tests run only on request: when the commit message starts with `[run tests]`, when the pull request carries the `run ci` label, or when a manual run (`workflow_dispatch`) in `apache/grails-core` has its `run-tests` input ticked. Otherwise the run builds, and on a push publishes snapshots, without tests, exactly like a `[skip tests]` commit; a `[skip tests]` commit also wins over the label and the input. The label is the way to test a backport pull request without rewriting its head commit, and the input is how the commit a release is cut from gets tested (see RELEASE.md); both are read when the run starts. A marker anywhere but at the start of the first line is ignored. The rule follows the default branch: when a new one is promoted, the branches below it stop running tests by default without an edit. The older release branches are kept quiet on purpose: a backport lands as one push to the oldest branch and a merge-up to each branch above it, and its tests belong on the pull request, labelled `run ci`, not on every push after it. Side branches are unreviewed development work (see the review process in CONTRIBUTING.md); their tests run when the branch is proposed to a release branch. In a fork, where the runner time is the fork owner's and not the ASF's, a manual run runs the tests unless the commit message starts with `[skip tests]`. - The jobs that run no tests (dependency validation, the build-without-tests steps, code style and build health) still run on every push to a release branch and on every non-draft pull request; RAT and CodeQL run on every push to a release branch and on every non-draft pull request into one, since their `pull_request` triggers list only release-branch bases. Only the `no ci` label, or a draft without `run ci`, stops them. The snapshot publish runs on every push to a release branch and on a manual run (the docs publish only on a push), never on a pull request. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 99320c0ed4b..12fdfc6f6dc 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -316,9 +316,10 @@ Concerning when a review is required for a `protected` branch: An approval covers the changes that were reviewed. When a later push changes a pull request, the approvals given before it are dismissed automatically and the pull request has to be approved again; a rebase, or a merge of the base branch, that leaves the changes of the pull request as they were keeps them. A merge of the base branch that had -conflicts keeps them too, as long as it changes nothing by hand outside the conflicted files, so resolve the conflicts -in the merge commit and push any other change as a commit of its own. A dismissed approval does not block the merge -button, so check the review state of a pull request before merging it. +conflicts keeps them too, as long as it changes nothing by hand outside the conflicts git could not merge, so resolve +the conflicts in the merge commit and push any other change, also one in a conflicted file, as a commit of its own. +The pull request then gets a comment naming the files whose conflicts were resolved, for the reviewers to look at. A +dismissed approval does not block the merge button, so check the review state of a pull request before merging it. ## Join The Project Team For people willing to contribute more than an occasional pull request, consider joining our core team. Inquire in the `questions` channel in slack to learn more. From f3c4b6ed73fb85435cf1f69d167bcbe90af897e3 Mon Sep 17 00:00:00 2001 From: Scott Murphy Heiberg Date: Wed, 18 Nov 2026 13:10:13 -0800 Subject: [PATCH 05/12] Keep git from starting a gc in the bare repository of the merges Every fetch of a merge adds a pack to merges.git, and after about fifty of them, across all the pull requests of one run, git starts gc --auto in the background. It holds the lock of the shallow commits, so the next fetch fails and the approval it was checking is dismissed as one whose commits could not be checked. A synthetic run over 61 merges hit it. --- .github/workflows/dismiss-stale-reviews.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/dismiss-stale-reviews.yml b/.github/workflows/dismiss-stale-reviews.yml index 2fdc80e2b26..eeb36289fe0 100644 --- a/.github/workflows/dismiss-stale-reviews.yml +++ b/.github/workflows/dismiss-stale-reviews.yml @@ -194,6 +194,10 @@ jobs: noted[$number]+=$'\n'"$merges" } git init --quiet --bare merges.git + # Every fetch adds a pack, and once there are enough of them git would start a gc in the background, which + # holds the lock of the shallow commits that the next fetch has to take, and that fetch would then fail. + git -C merges.git config gc.auto 0 + git -C merges.git config maintenance.auto false git -C merges.git remote add origin "$GITHUB_SERVER_URL/$REPO" git -C merges.git config "http.$GITHUB_SERVER_URL/.extraheader" "AUTHORIZATION: basic $(printf 'x-access-token:%s' "$GH_TOKEN" | base64 -w0)" # The approvals given to another commit than the head, of every open pull request or of the ones whose head From f190f0f2c17e4a195b39e742f6b9095b249c6fa1 Mon Sep 17 00:00:00 2001 From: Scott Murphy Heiberg Date: Wed, 18 Nov 2026 13:10:13 -0800 Subject: [PATCH 06/12] Check every merge after an approval, however many there are The walk stopped after 20 commits and dismissed the approval, although running out of commits to check is no sign of a change. It now goes back to the approved commit, bounded by time only: two minutes for one approval, as before, and seven for all the checks of a run, so that one pull request with a long run of merges, or several slow ones, cannot end the job at its ten-minute timeout before the dismissals after them. --- .github/workflows/dismiss-stale-reviews.yml | 24 ++++++++++----------- AGENTS.md | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/dismiss-stale-reviews.yml b/.github/workflows/dismiss-stale-reviews.yml index eeb36289fe0..5bce0775b9a 100644 --- a/.github/workflows/dismiss-stale-reviews.yml +++ b/.github/workflows/dismiss-stale-reviews.yml @@ -25,7 +25,8 @@ # the merge git makes by itself only inside the conflicts git could not merge. The pull request then gets a comment # naming the files whose conflicts were resolved, once for each merge, since nobody reviewed the resolution. A merge # that changes any other line, or that merges anything but the base branch, dismisses the approval like any other -# push, and so does a walk over the merges that cannot finish: more than 20 commits, or more than two minutes. +# push, and so does a walk over the merges that cannot finish, because a request fails or the walk takes more than +# its two minutes. How many merges follow the approval does not matter. # # A pull_request run from a fork gets a read-only token that cannot dismiss a review, so this workflow does not react # to the pull request. It reacts to the Code Style workflow being requested for one, which a push to a pull request @@ -70,10 +71,12 @@ jobs: # Empty on a scheduled and on a manual run, which look at every open pull request. SHA: ${{ github.event.workflow_run.head_sha }} run: | - # A check of the merges after an approval has two minutes. Each git and gh command it runs gets what is left - # of them: a request or a fetch left to hang would end the job at its timeout, and with it the dismissals - # of every pull request after this one, on each run. + # A check of the merges after an approval has two minutes, and all of them together have seven, which + # leaves the job three for the rest before its timeout. Each git and gh command a check runs gets what is + # left: a request or a fetch left to hang, or one pull request with a long run of merges, would otherwise + # end the job at its timeout, and with it the dismissals of every pull request after that one, on each run. export GIT_LITERAL_PATHSPECS=1 + checks_end=$(( SECONDS + 420 )) bounded() { local left=$(( deadline - SECONDS )) (( left > 0 )) || return 124 @@ -118,18 +121,15 @@ jobs: # contents; git then asks for the contents of the files changed on both sides, and of the conflicted files # of the merge commit. Sets the reason of a dismissal, and lists the files whose conflicts were resolved by # hand, one line with the merge and the file each. A commit that is not such a merge answers no, and so does - # anything that keeps the check from finishing: a failed request, a git command that fails or runs out of - # time, or more merges than the limit, which bounds what an approval kept this way, whose commit GitHub does - # not move, costs each hourly run. + # anything that keeps the check from finishing: a failed request, or a git command that fails or runs out of + # time. The number of merges is not limited, only the time: GitHub does not move an approval kept this way, + # so each hourly run walks its merges again, and the time limit is what bounds that cost. only_merges_base() { - local base=$1 approved=$2 commit=$3 merges=0 deadline=$(( SECONDS + 120 )) first second other behind fork merged tree conflicts changed path + local base=$1 approved=$2 commit=$3 deadline=$(( SECONDS + 120 )) first second other behind fork merged tree conflicts changed path + (( deadline <= checks_end )) || deadline=$checks_end accepted= reason="the commits after this approval could not be checked" while [[ "$commit" != "$approved" ]]; do - if (( ++merges > 20 )); then - reason="more than 20 commits followed this approval, more than this workflow checks" - return 1 - fi read -r first second other < <(bounded gh api "repos/$REPO/commits/$commit" --jq '[.parents[].sha] | join(" ")') [[ -n "$first" ]] || return 1 [[ -n "$second" && -z "$other" ]] || { reason="the pull request changed after this approval"; return 1; } diff --git a/AGENTS.md b/AGENTS.md index c06927f4813..9896635a5e3 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -253,7 +253,7 @@ GitHub-hosted runner time is shared with every other Apache project, so the work - A draft pull request runs nothing unless it carries the `run ci` label, and a pull request labelled `no ci` runs nothing at all: every workflow that reacts to a pull request skips all of its jobs, except `cancel-unneeded-pr-runs.yml`, described below. The Release Drafter (`release-notes.yml`) does not react to pull requests: the action it pins cannot label them, and it builds the draft from merged pull requests, so it runs on pushes to a release branch. Marking a draft ready for review starts CI (the workflows list the `ready_for_review` trigger type, which is not a default). Labels and the draft flag are read when a run starts, so set them before pushing; adding `run ci` or removing `no ci` takes effect on the next push, or when the draft is marked ready, while adding `no ci` cancels the runs in flight (see below). A push to a draft, or to a `no ci` pull request, still cancels the run in flight for that pull request, as every push to a pull request or a branch does through the concurrency groups of the test workflows; the run that replaces it does nothing. A new workflow with a `pull_request` trigger lists the same `types` as its siblings and gates its jobs the same way. - Merging a pull request, or labelling it `no ci`, cancels its runs in flight: `cancel-unneeded-pr-runs.yml` cancels the queued, pending and in-progress `pull_request` runs of every open pull request labelled `no ci`, and on a push to a release branch also those of each pull request the pushed commit merged that were created before the merge. A run is kept while an open pull request not labelled `no ci` has the same head commit, and the runs of a merged pull request labelled `run ci` are kept too: on a release branch below the default, the push after the merge builds without the tests, so the tests the label asked for on the pull request are the only ones the change gets there, and a late failure still calls for a follow-up fix. The workflow runs on every push to a release branch and when a pull request is labelled `no ci`, but a `pull_request` run from a fork gets a read-only token that cannot cancel runs, so labelling a fork's pull request skips the job, and that pull request's runs are cancelled by the next push to a release branch. For the same reason merges are found from the push rather than from the pull request being closed. It lists the unfinished `pull_request` runs of the repository once per sweep, not once per pull request, to spare the `GITHUB_TOKEN` rate limit. -- A push that changes a pull request dismisses the approvals given before it: `dismiss-stale-reviews.yml` dismisses every approval that was given to another commit than the head of the pull request. GitHub itself moves an approval to the new head after a push that leaves the diff of the pull request as it was, such as a rebase or a merge of the base branch, so those approvals are kept. The release branches do not require pull requests, so GitHub's own stale-review setting, which is part of that requirement, is not available. The workflow reacts to the Code Style workflow being requested for a pull request (`workflow_run`), not to the pull request, because a `pull_request` run from a fork gets a read-only token that cannot dismiss a review; it therefore runs from the default branch, also for a draft or a pull request labelled `no ci`, and it never checks out the pull request. Renaming the Code Style workflow, or dropping its `pull_request` trigger, stops it. One approval GitHub has not moved is still kept: one that only update merges separate from the head. GitHub does not move an approval over a merge of the base branch that had conflicts, because resolving them changes the diff of the pull request, so the workflow repeats each merge (`git merge-tree` in a bare repository, on trees fetched without history; nothing of the pull request is checked out or run) and keeps the approval when every commit after the approved one has two parents, the second a commit of the base branch, and differs from the merge git makes by itself only inside the conflicts git could not merge: every file it changes is a conflicted one, with its mode and every line outside the conflict markers as git wrote them. A merge that changes any other line, that resolves by hand a conflict git writes without markers (a binary file, a file deleted on one side), that merges another branch, or that follows an ordinary commit pushed after the approval dismisses it. A kept approval and the files whose conflicts were resolved go to the step summary, and the pull request gets one comment per merge naming them, since nobody reviewed the resolution; the comment carries a hidden marker with the merge, so the hourly run does not repeat it. The walk over the merges stops after 20 commits or two minutes and then dismisses the approval with a message saying the commits were not checked, not that the pull request changed; within a run its answer is reused for every approval given to the same commit. For any other push the workflow compares no diff: an approval GitHub has not moved is dismissed unless its commit has the very tree of the head, so a push that only changes a space, moves an edit to another method, or changes the mode of a file dismisses it. GitHub starts no `pull_request` workflow for a commit whose message asks to skip them (`[skip ci]` and its variants) or for a pull request that conflicts with its base branch, so the workflow also looks at every open pull request once an hour (`schedule`); an approval can outlive such a push by at most that long. A manual run looks at every open pull request too and only reports, unless its `dry-run` input is cleared. +- A push that changes a pull request dismisses the approvals given before it: `dismiss-stale-reviews.yml` dismisses every approval that was given to another commit than the head of the pull request. GitHub itself moves an approval to the new head after a push that leaves the diff of the pull request as it was, such as a rebase or a merge of the base branch, so those approvals are kept. The release branches do not require pull requests, so GitHub's own stale-review setting, which is part of that requirement, is not available. The workflow reacts to the Code Style workflow being requested for a pull request (`workflow_run`), not to the pull request, because a `pull_request` run from a fork gets a read-only token that cannot dismiss a review; it therefore runs from the default branch, also for a draft or a pull request labelled `no ci`, and it never checks out the pull request. Renaming the Code Style workflow, or dropping its `pull_request` trigger, stops it. One approval GitHub has not moved is still kept: one that only update merges separate from the head. GitHub does not move an approval over a merge of the base branch that had conflicts, because resolving them changes the diff of the pull request, so the workflow repeats each merge (`git merge-tree` in a bare repository, on trees fetched without history; nothing of the pull request is checked out or run) and keeps the approval when every commit after the approved one has two parents, the second a commit of the base branch, and differs from the merge git makes by itself only inside the conflicts git could not merge: every file it changes is a conflicted one, with its mode and every line outside the conflict markers as git wrote them. A merge that changes any other line, that resolves by hand a conflict git writes without markers (a binary file, a file deleted on one side), that merges another branch, or that follows an ordinary commit pushed after the approval dismisses it. A kept approval and the files whose conflicts were resolved go to the step summary, and the pull request gets one comment per merge naming them, since nobody reviewed the resolution; the comment carries a hidden marker with the merge, so the hourly run does not repeat it. The walk over the merges goes back to the approved commit however many merges there are; only time bounds it, two minutes for one approval and seven for all of a run, so that the job always gets to the dismissals after it. A walk that runs out of time, or whose requests fail, dismisses the approval with a message saying the commits could not be checked, not that the pull request changed; within a run its answer is reused for every approval given to the same commit. For any other push the workflow compares no diff: an approval GitHub has not moved is dismissed unless its commit has the very tree of the head, so a push that only changes a space, moves an edit to another method, or changes the mode of a file dismisses it. GitHub starts no `pull_request` workflow for a commit whose message asks to skip them (`[skip ci]` and its variants) or for a pull request that conflicts with its base branch, so the workflow also looks at every open pull request once an hour (`schedule`); an approval can outlive such a push by at most that long. A manual run looks at every open pull request too and only reports, unless its `dry-run` input is cleared. - Every workflow that runs tests calls `.github/workflows/ci-policy.yml` as its first job, `policy`, and gates its test jobs (and the test steps of its build jobs) on `needs.policy.outputs.run-tests`. Never test `github.event.head_commit.message` in a workflow: a `pull_request` payload has no such field, so that test silently ran the tests on every pull request. The policy reads the head commit of the push, of the pull request, or of the dispatched branch, and matches the marker against the start of the message's first line. The read is retried with a growing pause; when it still fails, the tests run, as they did before the policy existed, and a warning annotation and the step summary say so, so an API outage costs runner time rather than a test result. - The tests run by default only on the default branch and the release branches above it, and there a commit message starting with `[skip tests]` skips them. Everywhere else, that is on a release branch below the default (7.0.x, 7.1.x and 7.2.x while 8.0.x is the default) and on a pull request whose base is a side branch rather than a release branch, the tests run only on request: when the commit message starts with `[run tests]`, when the pull request carries the `run ci` label, or when a manual run (`workflow_dispatch`) in `apache/grails-core` has its `run-tests` input ticked. Otherwise the run builds, and on a push publishes snapshots, without tests, exactly like a `[skip tests]` commit; a `[skip tests]` commit also wins over the label and the input. The label is the way to test a backport pull request without rewriting its head commit, and the input is how the commit a release is cut from gets tested (see RELEASE.md); both are read when the run starts. A marker anywhere but at the start of the first line is ignored. The rule follows the default branch: when a new one is promoted, the branches below it stop running tests by default without an edit. The older release branches are kept quiet on purpose: a backport lands as one push to the oldest branch and a merge-up to each branch above it, and its tests belong on the pull request, labelled `run ci`, not on every push after it. Side branches are unreviewed development work (see the review process in CONTRIBUTING.md); their tests run when the branch is proposed to a release branch. In a fork, where the runner time is the fork owner's and not the ASF's, a manual run runs the tests unless the commit message starts with `[skip tests]`. - The jobs that run no tests (dependency validation, the build-without-tests steps, code style and build health) still run on every push to a release branch and on every non-draft pull request; RAT and CodeQL run on every push to a release branch and on every non-draft pull request into one, since their `pull_request` triggers list only release-branch bases. Only the `no ci` label, or a draft without `run ci`, stops them. The snapshot publish runs on every push to a release branch and on a manual run (the docs publish only on a push), never on a pull request. From 65f998710956bb40f964149ac32f4eac04359ee9 Mon Sep 17 00:00:00 2001 From: Scott Murphy Heiberg Date: Wed, 18 Nov 2026 13:10:13 -0800 Subject: [PATCH 07/12] Read the parents of each later merge from the commit already fetched Every merge after the head was fetched as the first parent of the merge before it, so its parents are in its commit object. Reading them there saves one of the three requests a merge cost, which matters now that the number of merges is bounded by time only. --- .github/workflows/dismiss-stale-reviews.yml | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/.github/workflows/dismiss-stale-reviews.yml b/.github/workflows/dismiss-stale-reviews.yml index 5bce0775b9a..039dcfba10b 100644 --- a/.github/workflows/dismiss-stale-reviews.yml +++ b/.github/workflows/dismiss-stale-reviews.yml @@ -119,18 +119,25 @@ jobs: # parents: the files that differ have to be conflicted ones, changed only inside their conflicts. Three # commits are fetched for a merge, its parents and their merge base, without history and without file # contents; git then asks for the contents of the files changed on both sides, and of the conflicted files - # of the merge commit. Sets the reason of a dismissal, and lists the files whose conflicts were resolved by - # hand, one line with the merge and the file each. A commit that is not such a merge answers no, and so does - # anything that keeps the check from finishing: a failed request, or a git command that fails or runs out of - # time. The number of merges is not limited, only the time: GitHub does not move an approval kept this way, - # so each hourly run walks its merges again, and the time limit is what bounds that cost. + # of the merge commit. The parents of the head are asked for, those of every merge after it are read from + # the commit already fetched, so a merge costs two requests. Sets the reason of a dismissal, and lists the + # files whose conflicts were resolved by hand, one line with the merge and the file each. A commit that is + # not such a merge answers no, and so does anything that keeps the check from finishing: a failed request, + # or a git command that fails or runs out of time. The number of merges is not limited, only the time: + # GitHub does not move an approval kept this way, so each hourly run walks its merges again, and the time + # limit is what bounds that cost. only_merges_base() { - local base=$1 approved=$2 commit=$3 deadline=$(( SECONDS + 120 )) first second other behind fork merged tree conflicts changed path + local base=$1 approved=$2 commit=$3 deadline=$(( SECONDS + 120 )) fork= first second other behind merged tree conflicts changed path (( deadline <= checks_end )) || deadline=$checks_end accepted= reason="the commits after this approval could not be checked" while [[ "$commit" != "$approved" ]]; do - read -r first second other < <(bounded gh api "repos/$REPO/commits/$commit" --jq '[.parents[].sha] | join(" ")') + if [[ -n "$fork" ]]; then + # The commit was fetched as the first parent of the merge before it, so its parents are read from it. + read -r first second other < <(bounded env GIT_NO_LAZY_FETCH=1 git -C merges.git cat-file commit "$commit" | sed -n '/^$/q; s/^parent //p' | tr '\n' ' ') + else + read -r first second other < <(bounded gh api "repos/$REPO/commits/$commit" --jq '[.parents[].sha] | join(" ")') + fi [[ -n "$first" ]] || return 1 [[ -n "$second" && -z "$other" ]] || { reason="the pull request changed after this approval"; return 1; } behind=$(bounded gh api "repos/$REPO/compare/$second...$base?per_page=1" --jq '.behind_by') || return 1 From 58b1f383d7e2e26196c24addffeec3c5c5a2ff45 Mon Sep 17 00:00:00 2001 From: Scott Murphy Heiberg Date: Thu, 19 Nov 2026 06:50:50 -0800 Subject: [PATCH 08/12] Report a failed request or git command while checking merges as such Three places lost the exit status of the command they read, so a failure there dismissed the approval as a change of the pull request instead of as commits that could not be checked: - The parents of a merge were read from a process substitution. gh prints the body of a failed request, and a 422 split into words looked like a commit with more than two parents. They are now read into a variable, with the status checked, before they are split. - The mode of the pushed file came from a substitution inside a test, so a git command that failed or ran out of time read as another mode. - The step runs without pipefail, so when cat-file failed or ran out of time awk read nothing and the file looked like one without conflicts. That pipeline, and the one reading the parents of a later merge, now set pipefail in their own subshell. --- .github/workflows/dismiss-stale-reviews.yml | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/.github/workflows/dismiss-stale-reviews.yml b/.github/workflows/dismiss-stale-reviews.yml index 039dcfba10b..b84fe5b1cdb 100644 --- a/.github/workflows/dismiss-stale-reviews.yml +++ b/.github/workflows/dismiss-stale-reviews.yml @@ -88,13 +88,16 @@ jobs: # writes without markers, such as one of a binary file or of a file deleted on one side, which leaves no # line to tell the resolution by; and 2 when a git command fails. resolved_within_conflicts() { - local tree=$1 commit=$2 path=$3 first=$4 second=$5 entry regions hunks + local tree=$1 commit=$2 path=$3 first=$4 second=$5 entry pushed regions hunks entry=$(bounded git -C merges.git ls-tree --format='%(objectmode) %(objecttype)' "$tree" -- "$path") || return 2 [[ "$entry" == 100*' blob' ]] || return 1 - [[ "$(bounded git -C merges.git ls-tree --format='%(objectmode) %(objecttype)' "$commit" -- "$path")" == "$entry" ]] || return 1 + pushed=$(bounded git -C merges.git ls-tree --format='%(objectmode) %(objecttype)' "$commit" -- "$path") || return 2 + [[ "$pushed" == "$entry" ]] || return 1 # The first and last line of each conflict. A marker is matched with its label, the id of a parent, so - # that a line of the file that merely looks like one does not open a conflict. - regions=$(bounded git -C merges.git cat-file blob "$tree:$path" | awk -v opening="<<<<<<< $first" -v closing=">>>>>>> $second" ' + # that a line of the file that merely looks like one does not open a conflict. The step runs without + # pipefail, so it is set here: a git command that fails or runs out of time would otherwise leave awk + # nothing to read, and the file would look like one without conflicts. + regions=$(set -o pipefail; bounded git -C merges.git cat-file blob "$tree:$path" | awk -v opening="<<<<<<< $first" -v closing=">>>>>>> $second" ' { sub(/\r$/, "") } $0 == opening || index($0, opening ":") == 1 { if (start) exit 1; start = NR; next } $0 == closing || index($0, closing ":") == 1 { if (!start) exit 1; printf "%d %d ", start, NR; start = 0 } @@ -127,17 +130,20 @@ jobs: # GitHub does not move an approval kept this way, so each hourly run walks its merges again, and the time # limit is what bounds that cost. only_merges_base() { - local base=$1 approved=$2 commit=$3 deadline=$(( SECONDS + 120 )) fork= first second other behind merged tree conflicts changed path + local base=$1 approved=$2 commit=$3 deadline=$(( SECONDS + 120 )) fork= parents first second other behind merged tree conflicts changed path (( deadline <= checks_end )) || deadline=$checks_end accepted= reason="the commits after this approval could not be checked" while [[ "$commit" != "$approved" ]]; do + # The parents are read into a variable first, so that a failed command answers as one: gh prints the + # body of a failed request, which split into words would look like a commit with more than two parents. if [[ -n "$fork" ]]; then # The commit was fetched as the first parent of the merge before it, so its parents are read from it. - read -r first second other < <(bounded env GIT_NO_LAZY_FETCH=1 git -C merges.git cat-file commit "$commit" | sed -n '/^$/q; s/^parent //p' | tr '\n' ' ') + parents=$(set -o pipefail; bounded env GIT_NO_LAZY_FETCH=1 git -C merges.git cat-file commit "$commit" | sed -n '1,/^$/s/^parent //p' | tr '\n' ' ') || return 1 else - read -r first second other < <(bounded gh api "repos/$REPO/commits/$commit" --jq '[.parents[].sha] | join(" ")') + parents=$(bounded gh api "repos/$REPO/commits/$commit" --jq '[.parents[].sha] | join(" ")') || return 1 fi + read -r first second other <<< "$parents" [[ -n "$first" ]] || return 1 [[ -n "$second" && -z "$other" ]] || { reason="the pull request changed after this approval"; return 1; } behind=$(bounded gh api "repos/$REPO/compare/$second...$base?per_page=1" --jq '.behind_by') || return 1 From b467a46d5141bda0ee9862564373172193f5f8fc Mon Sep 17 00:00:00 2001 From: Scott Murphy Heiberg Date: Thu, 19 Nov 2026 06:53:28 -0800 Subject: [PATCH 09/12] Ask a failed request of the merge check once more GitHub never moves an approval kept across update merges, so every hourly run checks it again, and one passing error of the API in any of those runs dismissed it although nothing was pushed. A failed request is now asked once more after five seconds, as long as the check has that time left. Only the answer of the request that succeeds is used, never the error body gh prints for the failed one. --- .github/workflows/dismiss-stale-reviews.yml | 18 +++++++++++++++--- AGENTS.md | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/.github/workflows/dismiss-stale-reviews.yml b/.github/workflows/dismiss-stale-reviews.yml index b84fe5b1cdb..69dacec8c46 100644 --- a/.github/workflows/dismiss-stale-reviews.yml +++ b/.github/workflows/dismiss-stale-reviews.yml @@ -82,6 +82,18 @@ jobs: (( left > 0 )) || return 124 timeout "$left" "$@" } + # A request of the check, asked again once after a pause when it fails, as long as the check has time left: + # an approval kept this way is checked again on every hourly run, and one passing error of the API should + # not dismiss it. Only the answer of the request that succeeds is printed, not the error body gh prints. + requested() { + local answer + answer=$(bounded gh api "$@") || { + (( deadline - SECONDS > 5 )) || return 124 + sleep 5 + answer=$(bounded gh api "$@") || return + } + printf '%s\n' "$answer" + } # Whether a merge commit changed a conflicted file only inside its conflicts. The file git merges by itself # holds each conflict between markers labelled with the two parents, and the pushed file has to keep every # line outside them as it is, with the same mode. Answers 1 when it does not, also for a conflict git @@ -141,14 +153,14 @@ jobs: # The commit was fetched as the first parent of the merge before it, so its parents are read from it. parents=$(set -o pipefail; bounded env GIT_NO_LAZY_FETCH=1 git -C merges.git cat-file commit "$commit" | sed -n '1,/^$/s/^parent //p' | tr '\n' ' ') || return 1 else - parents=$(bounded gh api "repos/$REPO/commits/$commit" --jq '[.parents[].sha] | join(" ")') || return 1 + parents=$(requested "repos/$REPO/commits/$commit" --jq '[.parents[].sha] | join(" ")') || return 1 fi read -r first second other <<< "$parents" [[ -n "$first" ]] || return 1 [[ -n "$second" && -z "$other" ]] || { reason="the pull request changed after this approval"; return 1; } - behind=$(bounded gh api "repos/$REPO/compare/$second...$base?per_page=1" --jq '.behind_by') || return 1 + behind=$(requested "repos/$REPO/compare/$second...$base?per_page=1" --jq '.behind_by') || return 1 [[ "$behind" == 0 ]] || { reason="the pull request changed after this approval"; return 1; } - fork=$(bounded gh api "repos/$REPO/compare/$first...$second?per_page=1" --jq '.merge_base_commit.sha') || return 1 + fork=$(requested "repos/$REPO/compare/$first...$second?per_page=1" --jq '.merge_base_commit.sha') || return 1 [[ -n "$fork" ]] || return 1 bounded git -C merges.git fetch --quiet --depth=1 --filter=blob:none origin "$commit" "$first" "$second" "$fork" || return 1 # The first line is the merged tree, the lines after it name the conflicted files, which fail the command. diff --git a/AGENTS.md b/AGENTS.md index 9896635a5e3..27c4d767538 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -253,7 +253,7 @@ GitHub-hosted runner time is shared with every other Apache project, so the work - A draft pull request runs nothing unless it carries the `run ci` label, and a pull request labelled `no ci` runs nothing at all: every workflow that reacts to a pull request skips all of its jobs, except `cancel-unneeded-pr-runs.yml`, described below. The Release Drafter (`release-notes.yml`) does not react to pull requests: the action it pins cannot label them, and it builds the draft from merged pull requests, so it runs on pushes to a release branch. Marking a draft ready for review starts CI (the workflows list the `ready_for_review` trigger type, which is not a default). Labels and the draft flag are read when a run starts, so set them before pushing; adding `run ci` or removing `no ci` takes effect on the next push, or when the draft is marked ready, while adding `no ci` cancels the runs in flight (see below). A push to a draft, or to a `no ci` pull request, still cancels the run in flight for that pull request, as every push to a pull request or a branch does through the concurrency groups of the test workflows; the run that replaces it does nothing. A new workflow with a `pull_request` trigger lists the same `types` as its siblings and gates its jobs the same way. - Merging a pull request, or labelling it `no ci`, cancels its runs in flight: `cancel-unneeded-pr-runs.yml` cancels the queued, pending and in-progress `pull_request` runs of every open pull request labelled `no ci`, and on a push to a release branch also those of each pull request the pushed commit merged that were created before the merge. A run is kept while an open pull request not labelled `no ci` has the same head commit, and the runs of a merged pull request labelled `run ci` are kept too: on a release branch below the default, the push after the merge builds without the tests, so the tests the label asked for on the pull request are the only ones the change gets there, and a late failure still calls for a follow-up fix. The workflow runs on every push to a release branch and when a pull request is labelled `no ci`, but a `pull_request` run from a fork gets a read-only token that cannot cancel runs, so labelling a fork's pull request skips the job, and that pull request's runs are cancelled by the next push to a release branch. For the same reason merges are found from the push rather than from the pull request being closed. It lists the unfinished `pull_request` runs of the repository once per sweep, not once per pull request, to spare the `GITHUB_TOKEN` rate limit. -- A push that changes a pull request dismisses the approvals given before it: `dismiss-stale-reviews.yml` dismisses every approval that was given to another commit than the head of the pull request. GitHub itself moves an approval to the new head after a push that leaves the diff of the pull request as it was, such as a rebase or a merge of the base branch, so those approvals are kept. The release branches do not require pull requests, so GitHub's own stale-review setting, which is part of that requirement, is not available. The workflow reacts to the Code Style workflow being requested for a pull request (`workflow_run`), not to the pull request, because a `pull_request` run from a fork gets a read-only token that cannot dismiss a review; it therefore runs from the default branch, also for a draft or a pull request labelled `no ci`, and it never checks out the pull request. Renaming the Code Style workflow, or dropping its `pull_request` trigger, stops it. One approval GitHub has not moved is still kept: one that only update merges separate from the head. GitHub does not move an approval over a merge of the base branch that had conflicts, because resolving them changes the diff of the pull request, so the workflow repeats each merge (`git merge-tree` in a bare repository, on trees fetched without history; nothing of the pull request is checked out or run) and keeps the approval when every commit after the approved one has two parents, the second a commit of the base branch, and differs from the merge git makes by itself only inside the conflicts git could not merge: every file it changes is a conflicted one, with its mode and every line outside the conflict markers as git wrote them. A merge that changes any other line, that resolves by hand a conflict git writes without markers (a binary file, a file deleted on one side), that merges another branch, or that follows an ordinary commit pushed after the approval dismisses it. A kept approval and the files whose conflicts were resolved go to the step summary, and the pull request gets one comment per merge naming them, since nobody reviewed the resolution; the comment carries a hidden marker with the merge, so the hourly run does not repeat it. The walk over the merges goes back to the approved commit however many merges there are; only time bounds it, two minutes for one approval and seven for all of a run, so that the job always gets to the dismissals after it. A walk that runs out of time, or whose requests fail, dismisses the approval with a message saying the commits could not be checked, not that the pull request changed; within a run its answer is reused for every approval given to the same commit. For any other push the workflow compares no diff: an approval GitHub has not moved is dismissed unless its commit has the very tree of the head, so a push that only changes a space, moves an edit to another method, or changes the mode of a file dismisses it. GitHub starts no `pull_request` workflow for a commit whose message asks to skip them (`[skip ci]` and its variants) or for a pull request that conflicts with its base branch, so the workflow also looks at every open pull request once an hour (`schedule`); an approval can outlive such a push by at most that long. A manual run looks at every open pull request too and only reports, unless its `dry-run` input is cleared. +- A push that changes a pull request dismisses the approvals given before it: `dismiss-stale-reviews.yml` dismisses every approval that was given to another commit than the head of the pull request. GitHub itself moves an approval to the new head after a push that leaves the diff of the pull request as it was, such as a rebase or a merge of the base branch, so those approvals are kept. The release branches do not require pull requests, so GitHub's own stale-review setting, which is part of that requirement, is not available. The workflow reacts to the Code Style workflow being requested for a pull request (`workflow_run`), not to the pull request, because a `pull_request` run from a fork gets a read-only token that cannot dismiss a review; it therefore runs from the default branch, also for a draft or a pull request labelled `no ci`, and it never checks out the pull request. Renaming the Code Style workflow, or dropping its `pull_request` trigger, stops it. One approval GitHub has not moved is still kept: one that only update merges separate from the head. GitHub does not move an approval over a merge of the base branch that had conflicts, because resolving them changes the diff of the pull request, so the workflow repeats each merge (`git merge-tree` in a bare repository, on trees fetched without history; nothing of the pull request is checked out or run) and keeps the approval when every commit after the approved one has two parents, the second a commit of the base branch, and differs from the merge git makes by itself only inside the conflicts git could not merge: every file it changes is a conflicted one, with its mode and every line outside the conflict markers as git wrote them. A merge that changes any other line, that resolves by hand a conflict git writes without markers (a binary file, a file deleted on one side), that merges another branch, or that follows an ordinary commit pushed after the approval dismisses it. A kept approval and the files whose conflicts were resolved go to the step summary, and the pull request gets one comment per merge naming them, since nobody reviewed the resolution; the comment carries a hidden marker with the merge, so the hourly run does not repeat it. The walk over the merges goes back to the approved commit however many merges there are; only time bounds it, two minutes for one approval and seven for all of a run, so that the job always gets to the dismissals after it. A failed request is asked once more after a pause. A walk that runs out of time, or whose requests or git commands still fail, dismisses the approval with a message saying the commits could not be checked, not that the pull request changed; within a run its answer is reused for every approval given to the same commit. For any other push the workflow compares no diff: an approval GitHub has not moved is dismissed unless its commit has the very tree of the head, so a push that only changes a space, moves an edit to another method, or changes the mode of a file dismisses it. GitHub starts no `pull_request` workflow for a commit whose message asks to skip them (`[skip ci]` and its variants) or for a pull request that conflicts with its base branch, so the workflow also looks at every open pull request once an hour (`schedule`); an approval can outlive such a push by at most that long. A manual run looks at every open pull request too and only reports, unless its `dry-run` input is cleared. - Every workflow that runs tests calls `.github/workflows/ci-policy.yml` as its first job, `policy`, and gates its test jobs (and the test steps of its build jobs) on `needs.policy.outputs.run-tests`. Never test `github.event.head_commit.message` in a workflow: a `pull_request` payload has no such field, so that test silently ran the tests on every pull request. The policy reads the head commit of the push, of the pull request, or of the dispatched branch, and matches the marker against the start of the message's first line. The read is retried with a growing pause; when it still fails, the tests run, as they did before the policy existed, and a warning annotation and the step summary say so, so an API outage costs runner time rather than a test result. - The tests run by default only on the default branch and the release branches above it, and there a commit message starting with `[skip tests]` skips them. Everywhere else, that is on a release branch below the default (7.0.x, 7.1.x and 7.2.x while 8.0.x is the default) and on a pull request whose base is a side branch rather than a release branch, the tests run only on request: when the commit message starts with `[run tests]`, when the pull request carries the `run ci` label, or when a manual run (`workflow_dispatch`) in `apache/grails-core` has its `run-tests` input ticked. Otherwise the run builds, and on a push publishes snapshots, without tests, exactly like a `[skip tests]` commit; a `[skip tests]` commit also wins over the label and the input. The label is the way to test a backport pull request without rewriting its head commit, and the input is how the commit a release is cut from gets tested (see RELEASE.md); both are read when the run starts. A marker anywhere but at the start of the first line is ignored. The rule follows the default branch: when a new one is promoted, the branches below it stop running tests by default without an edit. The older release branches are kept quiet on purpose: a backport lands as one push to the oldest branch and a merge-up to each branch above it, and its tests belong on the pull request, labelled `run ci`, not on every push after it. Side branches are unreviewed development work (see the review process in CONTRIBUTING.md); their tests run when the branch is proposed to a release branch. In a fork, where the runner time is the fork owner's and not the ASF's, a manual run runs the tests unless the commit message starts with `[skip tests]`. - The jobs that run no tests (dependency validation, the build-without-tests steps, code style and build health) still run on every push to a release branch and on every non-draft pull request; RAT and CodeQL run on every push to a release branch and on every non-draft pull request into one, since their `pull_request` triggers list only release-branch bases. Only the `no ci` label, or a draft without `run ci`, stops them. The snapshot publish runs on every push to a release branch and on a manual run (the docs publish only on a push), never on a pull request. From c2b33452a539b3f5af9db8c50f0f5b4f101aca80 Mon Sep 17 00:00:00 2001 From: Scott Murphy Heiberg Date: Thu, 19 Nov 2026 11:10:10 -0800 Subject: [PATCH 10/12] Accept a line inserted beside a conflict only between its markers A hunk that only inserts lines passed when it sat next to a conflict, just before the opening marker or just after the closing one. A merge pushed with git's conflict markers still in place, and a line added just outside them, therefore kept the approval, although that line is outside the conflict. An inserted line now has to land between the markers. A resolution that removes the markers is not affected: git reports it as a change of the conflict's own lines, also when it repeats the lines around the conflict, so those hunks already had to lie within the markers. --- .github/workflows/dismiss-stale-reviews.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/dismiss-stale-reviews.yml b/.github/workflows/dismiss-stale-reviews.yml index 69dacec8c46..fa968539d62 100644 --- a/.github/workflows/dismiss-stale-reviews.yml +++ b/.github/workflows/dismiss-stale-reviews.yml @@ -115,16 +115,19 @@ jobs: $0 == closing || index($0, closing ":") == 1 { if (!start) exit 1; printf "%d %d ", start, NR; start = 0 } END { if (start) exit 1 }') || return 2 [[ -n "$regions" ]] || return 1 - # Every line the merge commit removed or replaced lies in a conflict, and every line it inserted sits in - # or next to one. --text makes git compare a file it takes for binary line by line too, rather than only - # say that it differs. + # Every line the merge commit removed or replaced lies in a conflict, markers included, and every line it + # only inserted lands between the markers of one: git reports an insertion after an old line, so that + # line has to be the opening marker or a line after it, before the closing marker. A line inserted next + # to a conflict whose markers are kept is a change outside it. A resolution that removes the markers is + # a change of the conflict's own lines, whatever it adds. --text makes git compare a file it takes for + # binary line by line too, rather than only say that it differs. hunks=$(bounded git -C merges.git diff -U0 --text --no-ext-diff --no-textconv --no-color "$tree:$path" "$commit:$path") || return 2 awk -v regions="$regions" ' BEGIN { n = split(regions, r, " ") } /^@@ / { split(substr($2, 2), h, ","); at = h[1] + 0; count = (2 in h) ? h[2] + 0 : 1; inside = 0 for (i = 1; i < n; i += 2) - if (count > 0 ? (r[i] <= at && at + count - 1 <= r[i + 1]) : (r[i] - 1 <= at && at <= r[i + 1])) inside = 1 + if (count > 0 ? (r[i] <= at && at + count - 1 <= r[i + 1]) : (r[i] <= at && at < r[i + 1])) inside = 1 if (!inside) exit 1 }' <<< "$hunks" || return 1 } From 9b4d48cef758973261a92ce0f63f9fd516e4a817 Mon Sep 17 00:00:00 2001 From: Scott Murphy Heiberg Date: Thu, 19 Nov 2026 20:11:29 -0800 Subject: [PATCH 11/12] Accept only lines of the two sides inside a conflict resolution A resolution could write any line between the markers of a conflict, so a line added just before the opening marker, followed by one side of the conflict, kept the approval: once the markers are gone, that line is part of the resolution and git cannot tell it from one. Every line a merge writes inside a conflict now has to be a line of one of its two sides; which lines it keeps, and in which order, is still up to the resolution. A line written by hand inside a conflict now dismisses the approval like any other change. Of the seven historical merges kept before, the ones of #16453, #16495, #16726 and #16877 are now dismissed: they renumber a heading of the upgrade guide, or merge a line of prose or code by hand. --- .github/workflows/dismiss-stale-reviews.yml | 37 +++++++++++++-------- AGENTS.md | 2 +- CONTRIBUTING.md | 6 ++-- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/.github/workflows/dismiss-stale-reviews.yml b/.github/workflows/dismiss-stale-reviews.yml index fa968539d62..3a6f02d3020 100644 --- a/.github/workflows/dismiss-stale-reviews.yml +++ b/.github/workflows/dismiss-stale-reviews.yml @@ -22,7 +22,8 @@ # GitHub does not move an approval over a merge of the base branch that had conflicts, since resolving them changes # the diff of the pull request. Such an update merge is not a change of the pull request to review again, so the # approval is kept as well, as long as every commit pushed after it is a merge of the base branch that differs from -# the merge git makes by itself only inside the conflicts git could not merge. The pull request then gets a comment +# the merge git makes by itself only inside the conflicts git could not merge, and writes in each of them only lines +# of its two sides. A line written by hand there is a change like any other. The pull request then gets a comment # naming the files whose conflicts were resolved, once for each merge, since nobody reviewed the resolution. A merge # that changes any other line, or that merges anything but the base branch, dismisses the approval like any other # push, and so does a walk over the merges that cannot finish, because a request fails or the walk takes more than @@ -105,31 +106,39 @@ jobs: [[ "$entry" == 100*' blob' ]] || return 1 pushed=$(bounded git -C merges.git ls-tree --format='%(objectmode) %(objecttype)' "$commit" -- "$path") || return 2 [[ "$pushed" == "$entry" ]] || return 1 + bounded git -C merges.git cat-file blob "$tree:$path" > conflicted.file || return 2 # The first and last line of each conflict. A marker is matched with its label, the id of a parent, so - # that a line of the file that merely looks like one does not open a conflict. The step runs without - # pipefail, so it is set here: a git command that fails or runs out of time would otherwise leave awk - # nothing to read, and the file would look like one without conflicts. - regions=$(set -o pipefail; bounded git -C merges.git cat-file blob "$tree:$path" | awk -v opening="<<<<<<< $first" -v closing=">>>>>>> $second" ' + # that a line of the file that merely looks like one does not open a conflict. + regions=$(awk -v opening="<<<<<<< $first" -v closing=">>>>>>> $second" ' { sub(/\r$/, "") } $0 == opening || index($0, opening ":") == 1 { if (start) exit 1; start = NR; next } $0 == closing || index($0, closing ":") == 1 { if (!start) exit 1; printf "%d %d ", start, NR; start = 0 } - END { if (start) exit 1 }') || return 2 + END { if (start) exit 1 }' conflicted.file) || return 2 [[ -n "$regions" ]] || return 1 # Every line the merge commit removed or replaced lies in a conflict, markers included, and every line it # only inserted lands between the markers of one: git reports an insertion after an old line, so that - # line has to be the opening marker or a line after it, before the closing marker. A line inserted next - # to a conflict whose markers are kept is a change outside it. A resolution that removes the markers is - # a change of the conflict's own lines, whatever it adds. --text makes git compare a file it takes for - # binary line by line too, rather than only say that it differs. + # line has to be the opening marker or a line after it, before the closing marker. And every line the + # resolution writes is a line of one of the two sides of that conflict: which lines it keeps, and in + # which order, is up to the resolution, but a line written by hand, even one placed where a marker was, + # is a change nobody reviewed. --text makes git compare a file it takes for binary line by line too, + # rather than only say that it differs. hunks=$(bounded git -C merges.git diff -U0 --text --no-ext-diff --no-textconv --no-color "$tree:$path" "$commit:$path") || return 2 awk -v regions="$regions" ' BEGIN { n = split(regions, r, " ") } + FNR == NR { merged[FNR] = $0; next } /^@@ / { - split(substr($2, 2), h, ","); at = h[1] + 0; count = (2 in h) ? h[2] + 0 : 1; inside = 0 + split(substr($2, 2), h, ","); at = h[1] + 0; count = (2 in h) ? h[2] + 0 : 1; conflict = 0 for (i = 1; i < n; i += 2) - if (count > 0 ? (r[i] <= at && at + count - 1 <= r[i + 1]) : (r[i] <= at && at < r[i + 1])) inside = 1 - if (!inside) exit 1 - }' <<< "$hunks" || return 1 + if (count > 0 ? (r[i] <= at && at + count - 1 <= r[i + 1]) : (r[i] <= at && at < r[i + 1])) conflict = i + if (!conflict) exit 1 + next + } + conflict && /^\+/ { + written = substr($0, 2); side = 0 + for (j = r[conflict] + 1; j < r[conflict + 1] && !side; j++) + side = merged[j] == written && merged[j] !~ /^=======\r?$/ + if (!side) exit 1 + }' conflicted.file - <<< "$hunks" || return 1 } # Whether every commit from the approved one to the head is a merge of the base branch that changes nothing # by hand outside the conflicts git could not merge. Each commit on the way has to have two parents, the diff --git a/AGENTS.md b/AGENTS.md index cb1cff1f6cb..e1e7c225586 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -255,7 +255,7 @@ GitHub-hosted runner time is shared with every other Apache project, so the work - A draft pull request runs nothing unless it carries the `run ci` label, and a pull request labelled `no ci` runs nothing at all: every workflow that reacts to a pull request skips all of its jobs, except `cancel-unneeded-pr-runs.yml`, described below. The Release Drafter (`release-notes.yml`) does not react to pull requests: the action it pins cannot label them, and it builds the draft from merged pull requests, so it runs on pushes to a release branch. Marking a draft ready for review starts CI (the workflows list the `ready_for_review` trigger type, which is not a default). Labels and the draft flag are read when a run starts, so set them before pushing; adding `run ci` or removing `no ci` takes effect on the next push, or when the draft is marked ready, while adding `no ci` cancels the runs in flight (see below). A push to a draft, or to a `no ci` pull request, still cancels the run in flight for that pull request, as every push to a pull request or a branch does through the concurrency groups of the test workflows; the run that replaces it does nothing. A new workflow with a `pull_request` trigger lists the same `types` as its siblings and gates its jobs the same way. - Merging a pull request, or labelling it `no ci`, cancels its runs in flight: `cancel-unneeded-pr-runs.yml` cancels the queued, pending and in-progress `pull_request` runs of every open pull request labelled `no ci`, and on a push to a release branch also those of each pull request the pushed commit merged that were created before the merge. A run is kept while an open pull request not labelled `no ci` has the same head commit, and the runs of a merged pull request labelled `run ci` are kept too: on a release branch below the default, the push after the merge builds without the tests, so the tests the label asked for on the pull request are the only ones the change gets there, and a late failure still calls for a follow-up fix. The workflow runs on every push to a release branch and when a pull request is labelled `no ci`, but a `pull_request` run from a fork gets a read-only token that cannot cancel runs, so labelling a fork's pull request skips the job, and that pull request's runs are cancelled by the next push to a release branch. For the same reason merges are found from the push rather than from the pull request being closed. It lists the unfinished `pull_request` runs of the repository once per sweep, not once per pull request, to spare the `GITHUB_TOKEN` rate limit. -- A push that changes a pull request dismisses the approvals given before it: `dismiss-stale-reviews.yml` dismisses every approval that was given to another commit than the head of the pull request. GitHub itself moves an approval to the new head after a push that leaves the diff of the pull request as it was, such as a rebase or a merge of the base branch, so those approvals are kept. The release branches do not require pull requests, so GitHub's own stale-review setting, which is part of that requirement, is not available. The workflow reacts to the Code Style workflow being requested for a pull request (`workflow_run`), not to the pull request, because a `pull_request` run from a fork gets a read-only token that cannot dismiss a review; it therefore runs from the default branch, also for a draft or a pull request labelled `no ci`, and it never checks out the pull request. Renaming the Code Style workflow, or dropping its `pull_request` trigger, stops it. One approval GitHub has not moved is still kept: one that only update merges separate from the head. GitHub does not move an approval over a merge of the base branch that had conflicts, because resolving them changes the diff of the pull request, so the workflow repeats each merge (`git merge-tree` in a bare repository, on trees fetched without history; nothing of the pull request is checked out or run) and keeps the approval when every commit after the approved one has two parents, the second a commit of the base branch, and differs from the merge git makes by itself only inside the conflicts git could not merge: every file it changes is a conflicted one, with its mode and every line outside the conflict markers as git wrote them. A merge that changes any other line, that resolves by hand a conflict git writes without markers (a binary file, a file deleted on one side), that merges another branch, or that follows an ordinary commit pushed after the approval dismisses it. A kept approval and the files whose conflicts were resolved go to the step summary, and the pull request gets one comment per merge naming them, since nobody reviewed the resolution; the comment carries a hidden marker with the merge, so the hourly run does not repeat it. The walk over the merges goes back to the approved commit however many merges there are; only time bounds it, two minutes for one approval and seven for all of a run, so that the job always gets to the dismissals after it. A failed request is asked once more after a pause. A walk that runs out of time, or whose requests or git commands still fail, dismisses the approval with a message saying the commits could not be checked, not that the pull request changed; within a run its answer is reused for every approval given to the same commit. For any other push the workflow compares no diff: an approval GitHub has not moved is dismissed unless its commit has the very tree of the head, so a push that only changes a space, moves an edit to another method, or changes the mode of a file dismisses it. GitHub starts no `pull_request` workflow for a commit whose message asks to skip them (`[skip ci]` and its variants) or for a pull request that conflicts with its base branch, so the workflow also looks at every open pull request once an hour (`schedule`); an approval can outlive such a push by at most that long. A manual run looks at every open pull request too and only reports, unless its `dry-run` input is cleared. +- A push that changes a pull request dismisses the approvals given before it: `dismiss-stale-reviews.yml` dismisses every approval that was given to another commit than the head of the pull request. GitHub itself moves an approval to the new head after a push that leaves the diff of the pull request as it was, such as a rebase or a merge of the base branch, so those approvals are kept. The release branches do not require pull requests, so GitHub's own stale-review setting, which is part of that requirement, is not available. The workflow reacts to the Code Style workflow being requested for a pull request (`workflow_run`), not to the pull request, because a `pull_request` run from a fork gets a read-only token that cannot dismiss a review; it therefore runs from the default branch, also for a draft or a pull request labelled `no ci`, and it never checks out the pull request. Renaming the Code Style workflow, or dropping its `pull_request` trigger, stops it. One approval GitHub has not moved is still kept: one that only update merges separate from the head. GitHub does not move an approval over a merge of the base branch that had conflicts, because resolving them changes the diff of the pull request, so the workflow repeats each merge (`git merge-tree` in a bare repository, on trees fetched without history; nothing of the pull request is checked out or run) and keeps the approval when every commit after the approved one has two parents, the second a commit of the base branch, and differs from the merge git makes by itself only inside the conflicts git could not merge: every file it changes is a conflicted one, with its mode and every line outside the conflict markers as git wrote them, and every line it writes inside a conflict is a line of one of the conflict's two sides, in whatever order. A merge that changes any other line, that writes a line of its own in a resolution (a renumbered heading, a line merged by hand from both sides), that resolves by hand a conflict git writes without markers (a binary file, a file deleted on one side), that merges another branch, or that follows an ordinary commit pushed after the approval dismisses it. A kept approval and the files whose conflicts were resolved go to the step summary, and the pull request gets one comment per merge naming them, since nobody reviewed the resolution; the comment carries a hidden marker with the merge, so the hourly run does not repeat it. The walk over the merges goes back to the approved commit however many merges there are; only time bounds it, two minutes for one approval and seven for all of a run, so that the job always gets to the dismissals after it. A failed request is asked once more after a pause. A walk that runs out of time, or whose requests or git commands still fail, dismisses the approval with a message saying the commits could not be checked, not that the pull request changed; within a run its answer is reused for every approval given to the same commit. For any other push the workflow compares no diff: an approval GitHub has not moved is dismissed unless its commit has the very tree of the head, so a push that only changes a space, moves an edit to another method, or changes the mode of a file dismisses it. GitHub starts no `pull_request` workflow for a commit whose message asks to skip them (`[skip ci]` and its variants) or for a pull request that conflicts with its base branch, so the workflow also looks at every open pull request once an hour (`schedule`); an approval can outlive such a push by at most that long. A manual run looks at every open pull request too and only reports, unless its `dry-run` input is cleared. - Every workflow that runs tests calls `.github/workflows/ci-policy.yml` as its first job, `policy`, and gates its test jobs (and the test steps of its build jobs) on `needs.policy.outputs.run-tests`. Never test `github.event.head_commit.message` in a workflow: a `pull_request` payload has no such field, so that test silently ran the tests on every pull request. The policy reads the head commit of the push, of the pull request, or of the dispatched branch, and matches the marker against the start of the message's first line. The read is retried with a growing pause; when it still fails, the tests run, as they did before the policy existed, and a warning annotation and the step summary say so, so an API outage costs runner time rather than a test result. - The tests run by default only on the default branch and the release branches above it, and there a commit message starting with `[skip tests]` skips them. Everywhere else, that is on a release branch below the default (7.0.x, 7.1.x and 7.2.x while 8.0.x is the default) and on a pull request whose base is a side branch rather than a release branch, the tests run only on request: when the commit message starts with `[run tests]`, when the pull request carries the `run ci` label, or when a manual run (`workflow_dispatch`) in `apache/grails-core` has its `run-tests` input ticked. Otherwise the run builds, and on a push publishes snapshots, without tests, exactly like a `[skip tests]` commit; a `[skip tests]` commit also wins over the label and the input. The label is the way to test a backport pull request without rewriting its head commit, and the input is how the commit a release is cut from gets tested (see RELEASE.md); both are read when the run starts. A marker anywhere but at the start of the first line is ignored. The rule follows the default branch: when a new one is promoted, the branches below it stop running tests by default without an edit. The older release branches are kept quiet on purpose: a backport lands as one push to the oldest branch and a merge-up to each branch above it, and its tests belong on the pull request, labelled `run ci`, not on every push after it. Side branches are unreviewed development work (see the review process in CONTRIBUTING.md); their tests run when the branch is proposed to a release branch. In a fork, where the runner time is the fork owner's and not the ASF's, a manual run runs the tests unless the commit message starts with `[skip tests]`. - The jobs that run no tests (dependency validation, the build-without-tests steps, code style and build health) still run on every push to a release branch and on every non-draft pull request; RAT and CodeQL run on every push to a release branch and on every non-draft pull request into one, since their `pull_request` triggers list only release-branch bases. Only the `no ci` label, or a draft without `run ci`, stops them. The snapshot publish runs on every push to a release branch and on a manual run (the docs publish only on a push), never on a pull request. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 12fdfc6f6dc..ac9bf27eeb8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -316,8 +316,10 @@ Concerning when a review is required for a `protected` branch: An approval covers the changes that were reviewed. When a later push changes a pull request, the approvals given before it are dismissed automatically and the pull request has to be approved again; a rebase, or a merge of the base branch, that leaves the changes of the pull request as they were keeps them. A merge of the base branch that had -conflicts keeps them too, as long as it changes nothing by hand outside the conflicts git could not merge, so resolve -the conflicts in the merge commit and push any other change, also one in a conflicted file, as a commit of its own. +conflicts keeps them too, as long as each conflict is resolved by keeping lines of its two sides, in any order, and +nothing outside the conflicts changes. A line written by hand, such as a renumbered heading or a line merged from both +sides, dismisses them like any other change; made in a commit of its own after the merge, it is at least easy to +review again. The pull request then gets a comment naming the files whose conflicts were resolved, for the reviewers to look at. A dismissed approval does not block the merge button, so check the review state of a pull request before merging it. From 0b57e0b61fdcdaaf3b7c0605a49ee1c4f5858973 Mon Sep 17 00:00:00 2001 From: Scott Murphy Heiberg Date: Fri, 20 Nov 2026 06:50:26 -0800 Subject: [PATCH 12/12] Accept a conflict resolution only as one side, the other, or both Checking each line of a resolution against the lines of the two sides still let a resolution change the code: a line of a side could be repeated, so an increment added before the conflict and the side's own increment made the file increment twice, and lines could be dropped, reordered or combined from both sides. Each conflict is now resolved as a whole, as git offers to: the pull request's side, the base branch's side, or both one after the other, in either order. A conflict left as git wrote it, markers and all, is no change either. Of the historical merges, #16838 is now dismissed too: it kept the method signature of one side and the body of the other. #16958 and #16552 keep their approvals. --- .github/workflows/dismiss-stale-reviews.yml | 50 ++++++++++++++------- AGENTS.md | 2 +- CONTRIBUTING.md | 8 ++-- 3 files changed, 38 insertions(+), 22 deletions(-) diff --git a/.github/workflows/dismiss-stale-reviews.yml b/.github/workflows/dismiss-stale-reviews.yml index 3a6f02d3020..d2c099385de 100644 --- a/.github/workflows/dismiss-stale-reviews.yml +++ b/.github/workflows/dismiss-stale-reviews.yml @@ -22,8 +22,8 @@ # GitHub does not move an approval over a merge of the base branch that had conflicts, since resolving them changes # the diff of the pull request. Such an update merge is not a change of the pull request to review again, so the # approval is kept as well, as long as every commit pushed after it is a merge of the base branch that differs from -# the merge git makes by itself only inside the conflicts git could not merge, and writes in each of them only lines -# of its two sides. A line written by hand there is a change like any other. The pull request then gets a comment +# the merge git makes by itself only inside the conflicts git could not merge, and resolves each of them as a whole: +# one side, the other, or both. Any other resolution is a change like any other. The pull request then gets a comment # naming the files whose conflicts were resolved, once for each merge, since nobody reviewed the resolution. A merge # that changes any other line, or that merges anything but the base branch, dismisses the approval like any other # push, and so does a walk over the merges that cannot finish, because a request fails or the walk takes more than @@ -107,6 +107,7 @@ jobs: pushed=$(bounded git -C merges.git ls-tree --format='%(objectmode) %(objecttype)' "$commit" -- "$path") || return 2 [[ "$pushed" == "$entry" ]] || return 1 bounded git -C merges.git cat-file blob "$tree:$path" > conflicted.file || return 2 + bounded git -C merges.git cat-file blob "$commit:$path" > resolved.file || return 2 # The first and last line of each conflict. A marker is matched with its label, the id of a parent, so # that a line of the file that merely looks like one does not open a conflict. regions=$(awk -v opening="<<<<<<< $first" -v closing=">>>>>>> $second" ' @@ -117,28 +118,43 @@ jobs: [[ -n "$regions" ]] || return 1 # Every line the merge commit removed or replaced lies in a conflict, markers included, and every line it # only inserted lands between the markers of one: git reports an insertion after an old line, so that - # line has to be the opening marker or a line after it, before the closing marker. And every line the - # resolution writes is a line of one of the two sides of that conflict: which lines it keeps, and in - # which order, is up to the resolution, but a line written by hand, even one placed where a marker was, - # is a change nobody reviewed. --text makes git compare a file it takes for binary line by line too, - # rather than only say that it differs. + # line has to be the opening marker or a line after it, before the closing marker. Each conflict is then + # resolved as a whole, by what git offers for one: the lines of the pull request's side, those of the + # base branch's side, or both sides one after the other, in either order. Lines picked from the sides, + # repeated, reordered or written by hand are a change nobody reviewed, even when each line looks like + # one of a side. A conflict left as git wrote it, markers and all, is no change either. --text makes git + # compare a file it takes for binary line by line too, rather than only say that it differs. hunks=$(bounded git -C merges.git diff -U0 --text --no-ext-diff --no-textconv --no-color "$tree:$path" "$commit:$path") || return 2 awk -v regions="$regions" ' BEGIN { n = split(regions, r, " ") } - FNR == NR { merged[FNR] = $0; next } + FILENAME == ARGV[1] { merged[FNR] = $0; next } + FILENAME == ARGV[2] { resolved[FNR] = $0; next } /^@@ / { - split(substr($2, 2), h, ","); at = h[1] + 0; count = (2 in h) ? h[2] + 0 : 1; conflict = 0 + split(substr($2, 2), h, ","); at = h[1] + 0; count = (2 in h) ? h[2] + 0 : 1 + split(substr($3, 2), g, ","); written = (2 in g) ? g[2] + 0 : 1; conflict = 0 for (i = 1; i < n; i += 2) if (count > 0 ? (r[i] <= at && at + count - 1 <= r[i + 1]) : (r[i] <= at && at < r[i + 1])) conflict = i - if (!conflict) exit 1 - next + if (!conflict) { outside = 1; exit 1 } + grown[conflict] += written - count } - conflict && /^\+/ { - written = substr($0, 2); side = 0 - for (j = r[conflict] + 1; j < r[conflict + 1] && !side; j++) - side = merged[j] == written && merged[j] !~ /^=======\r?$/ - if (!side) exit 1 - }' conflicted.file - <<< "$hunks" || return 1 + # The resolution of each conflict is where its lines moved to in the pushed file, as far as the + # changes before it and in it have shifted them. + END { + if (outside) exit 1 + for (i = 1; i < n; i += 2) { + from = r[i] + shift; to = r[i + 1] + shift + grown[i]; shift += grown[i] + resolution = ""; for (j = from; j <= to; j++) resolution = resolution resolved[j] "\n" + conflict = ""; ours = ""; theirs = ""; separators = 0 + for (j = r[i]; j <= r[i + 1]; j++) conflict = conflict merged[j] "\n" + for (j = r[i] + 1; j < r[i + 1]; j++) + if (merged[j] ~ /^=======\r?$/) separators++ + else if (separators) theirs = theirs merged[j] "\n" + else ours = ours merged[j] "\n" + if (resolution == conflict) continue + if (separators != 1) exit 1 + if (resolution != ours && resolution != theirs && resolution != ours theirs && resolution != theirs ours) exit 1 + } + }' conflicted.file resolved.file - <<< "$hunks" || return 1 } # Whether every commit from the approved one to the head is a merge of the base branch that changes nothing # by hand outside the conflicts git could not merge. Each commit on the way has to have two parents, the diff --git a/AGENTS.md b/AGENTS.md index e1e7c225586..e23d35310af 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -255,7 +255,7 @@ GitHub-hosted runner time is shared with every other Apache project, so the work - A draft pull request runs nothing unless it carries the `run ci` label, and a pull request labelled `no ci` runs nothing at all: every workflow that reacts to a pull request skips all of its jobs, except `cancel-unneeded-pr-runs.yml`, described below. The Release Drafter (`release-notes.yml`) does not react to pull requests: the action it pins cannot label them, and it builds the draft from merged pull requests, so it runs on pushes to a release branch. Marking a draft ready for review starts CI (the workflows list the `ready_for_review` trigger type, which is not a default). Labels and the draft flag are read when a run starts, so set them before pushing; adding `run ci` or removing `no ci` takes effect on the next push, or when the draft is marked ready, while adding `no ci` cancels the runs in flight (see below). A push to a draft, or to a `no ci` pull request, still cancels the run in flight for that pull request, as every push to a pull request or a branch does through the concurrency groups of the test workflows; the run that replaces it does nothing. A new workflow with a `pull_request` trigger lists the same `types` as its siblings and gates its jobs the same way. - Merging a pull request, or labelling it `no ci`, cancels its runs in flight: `cancel-unneeded-pr-runs.yml` cancels the queued, pending and in-progress `pull_request` runs of every open pull request labelled `no ci`, and on a push to a release branch also those of each pull request the pushed commit merged that were created before the merge. A run is kept while an open pull request not labelled `no ci` has the same head commit, and the runs of a merged pull request labelled `run ci` are kept too: on a release branch below the default, the push after the merge builds without the tests, so the tests the label asked for on the pull request are the only ones the change gets there, and a late failure still calls for a follow-up fix. The workflow runs on every push to a release branch and when a pull request is labelled `no ci`, but a `pull_request` run from a fork gets a read-only token that cannot cancel runs, so labelling a fork's pull request skips the job, and that pull request's runs are cancelled by the next push to a release branch. For the same reason merges are found from the push rather than from the pull request being closed. It lists the unfinished `pull_request` runs of the repository once per sweep, not once per pull request, to spare the `GITHUB_TOKEN` rate limit. -- A push that changes a pull request dismisses the approvals given before it: `dismiss-stale-reviews.yml` dismisses every approval that was given to another commit than the head of the pull request. GitHub itself moves an approval to the new head after a push that leaves the diff of the pull request as it was, such as a rebase or a merge of the base branch, so those approvals are kept. The release branches do not require pull requests, so GitHub's own stale-review setting, which is part of that requirement, is not available. The workflow reacts to the Code Style workflow being requested for a pull request (`workflow_run`), not to the pull request, because a `pull_request` run from a fork gets a read-only token that cannot dismiss a review; it therefore runs from the default branch, also for a draft or a pull request labelled `no ci`, and it never checks out the pull request. Renaming the Code Style workflow, or dropping its `pull_request` trigger, stops it. One approval GitHub has not moved is still kept: one that only update merges separate from the head. GitHub does not move an approval over a merge of the base branch that had conflicts, because resolving them changes the diff of the pull request, so the workflow repeats each merge (`git merge-tree` in a bare repository, on trees fetched without history; nothing of the pull request is checked out or run) and keeps the approval when every commit after the approved one has two parents, the second a commit of the base branch, and differs from the merge git makes by itself only inside the conflicts git could not merge: every file it changes is a conflicted one, with its mode and every line outside the conflict markers as git wrote them, and every line it writes inside a conflict is a line of one of the conflict's two sides, in whatever order. A merge that changes any other line, that writes a line of its own in a resolution (a renumbered heading, a line merged by hand from both sides), that resolves by hand a conflict git writes without markers (a binary file, a file deleted on one side), that merges another branch, or that follows an ordinary commit pushed after the approval dismisses it. A kept approval and the files whose conflicts were resolved go to the step summary, and the pull request gets one comment per merge naming them, since nobody reviewed the resolution; the comment carries a hidden marker with the merge, so the hourly run does not repeat it. The walk over the merges goes back to the approved commit however many merges there are; only time bounds it, two minutes for one approval and seven for all of a run, so that the job always gets to the dismissals after it. A failed request is asked once more after a pause. A walk that runs out of time, or whose requests or git commands still fail, dismisses the approval with a message saying the commits could not be checked, not that the pull request changed; within a run its answer is reused for every approval given to the same commit. For any other push the workflow compares no diff: an approval GitHub has not moved is dismissed unless its commit has the very tree of the head, so a push that only changes a space, moves an edit to another method, or changes the mode of a file dismisses it. GitHub starts no `pull_request` workflow for a commit whose message asks to skip them (`[skip ci]` and its variants) or for a pull request that conflicts with its base branch, so the workflow also looks at every open pull request once an hour (`schedule`); an approval can outlive such a push by at most that long. A manual run looks at every open pull request too and only reports, unless its `dry-run` input is cleared. +- A push that changes a pull request dismisses the approvals given before it: `dismiss-stale-reviews.yml` dismisses every approval that was given to another commit than the head of the pull request. GitHub itself moves an approval to the new head after a push that leaves the diff of the pull request as it was, such as a rebase or a merge of the base branch, so those approvals are kept. The release branches do not require pull requests, so GitHub's own stale-review setting, which is part of that requirement, is not available. The workflow reacts to the Code Style workflow being requested for a pull request (`workflow_run`), not to the pull request, because a `pull_request` run from a fork gets a read-only token that cannot dismiss a review; it therefore runs from the default branch, also for a draft or a pull request labelled `no ci`, and it never checks out the pull request. Renaming the Code Style workflow, or dropping its `pull_request` trigger, stops it. One approval GitHub has not moved is still kept: one that only update merges separate from the head. GitHub does not move an approval over a merge of the base branch that had conflicts, because resolving them changes the diff of the pull request, so the workflow repeats each merge (`git merge-tree` in a bare repository, on trees fetched without history; nothing of the pull request is checked out or run) and keeps the approval when every commit after the approved one has two parents, the second a commit of the base branch, and differs from the merge git makes by itself only inside the conflicts git could not merge: every file it changes is a conflicted one, with its mode and every line outside the conflict markers as git wrote them, and each conflict is resolved as a whole, the way git offers to: the pull request's side, the base branch's side, or both sides one after the other. A merge that changes any other line, that resolves a conflict any other way (a renumbered heading, lines picked from both sides, a line repeated or written by hand), that resolves by hand a conflict git writes without markers (a binary file, a file deleted on one side), that merges another branch, or that follows an ordinary commit pushed after the approval dismisses it. A kept approval and the files whose conflicts were resolved go to the step summary, and the pull request gets one comment per merge naming them, since nobody reviewed the resolution; the comment carries a hidden marker with the merge, so the hourly run does not repeat it. The walk over the merges goes back to the approved commit however many merges there are; only time bounds it, two minutes for one approval and seven for all of a run, so that the job always gets to the dismissals after it. A failed request is asked once more after a pause. A walk that runs out of time, or whose requests or git commands still fail, dismisses the approval with a message saying the commits could not be checked, not that the pull request changed; within a run its answer is reused for every approval given to the same commit. For any other push the workflow compares no diff: an approval GitHub has not moved is dismissed unless its commit has the very tree of the head, so a push that only changes a space, moves an edit to another method, or changes the mode of a file dismisses it. GitHub starts no `pull_request` workflow for a commit whose message asks to skip them (`[skip ci]` and its variants) or for a pull request that conflicts with its base branch, so the workflow also looks at every open pull request once an hour (`schedule`); an approval can outlive such a push by at most that long. A manual run looks at every open pull request too and only reports, unless its `dry-run` input is cleared. - Every workflow that runs tests calls `.github/workflows/ci-policy.yml` as its first job, `policy`, and gates its test jobs (and the test steps of its build jobs) on `needs.policy.outputs.run-tests`. Never test `github.event.head_commit.message` in a workflow: a `pull_request` payload has no such field, so that test silently ran the tests on every pull request. The policy reads the head commit of the push, of the pull request, or of the dispatched branch, and matches the marker against the start of the message's first line. The read is retried with a growing pause; when it still fails, the tests run, as they did before the policy existed, and a warning annotation and the step summary say so, so an API outage costs runner time rather than a test result. - The tests run by default only on the default branch and the release branches above it, and there a commit message starting with `[skip tests]` skips them. Everywhere else, that is on a release branch below the default (7.0.x, 7.1.x and 7.2.x while 8.0.x is the default) and on a pull request whose base is a side branch rather than a release branch, the tests run only on request: when the commit message starts with `[run tests]`, when the pull request carries the `run ci` label, or when a manual run (`workflow_dispatch`) in `apache/grails-core` has its `run-tests` input ticked. Otherwise the run builds, and on a push publishes snapshots, without tests, exactly like a `[skip tests]` commit; a `[skip tests]` commit also wins over the label and the input. The label is the way to test a backport pull request without rewriting its head commit, and the input is how the commit a release is cut from gets tested (see RELEASE.md); both are read when the run starts. A marker anywhere but at the start of the first line is ignored. The rule follows the default branch: when a new one is promoted, the branches below it stop running tests by default without an edit. The older release branches are kept quiet on purpose: a backport lands as one push to the oldest branch and a merge-up to each branch above it, and its tests belong on the pull request, labelled `run ci`, not on every push after it. Side branches are unreviewed development work (see the review process in CONTRIBUTING.md); their tests run when the branch is proposed to a release branch. In a fork, where the runner time is the fork owner's and not the ASF's, a manual run runs the tests unless the commit message starts with `[skip tests]`. - The jobs that run no tests (dependency validation, the build-without-tests steps, code style and build health) still run on every push to a release branch and on every non-draft pull request; RAT and CodeQL run on every push to a release branch and on every non-draft pull request into one, since their `pull_request` triggers list only release-branch bases. Only the `no ci` label, or a draft without `run ci`, stops them. The snapshot publish runs on every push to a release branch and on a manual run (the docs publish only on a push), never on a pull request. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ac9bf27eeb8..065710ec610 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -316,10 +316,10 @@ Concerning when a review is required for a `protected` branch: An approval covers the changes that were reviewed. When a later push changes a pull request, the approvals given before it are dismissed automatically and the pull request has to be approved again; a rebase, or a merge of the base branch, that leaves the changes of the pull request as they were keeps them. A merge of the base branch that had -conflicts keeps them too, as long as each conflict is resolved by keeping lines of its two sides, in any order, and -nothing outside the conflicts changes. A line written by hand, such as a renumbered heading or a line merged from both -sides, dismisses them like any other change; made in a commit of its own after the merge, it is at least easy to -review again. +conflicts keeps them too, as long as each conflict is resolved by keeping one side, the other, or both one after the +other, and nothing outside the conflicts changes. Any other resolution, such as a renumbered heading, lines picked +from both sides or a line written by hand, dismisses them like any other change; made in a commit of its own after the +merge, it is at least easy to review again. The pull request then gets a comment naming the files whose conflicts were resolved, for the reviewers to look at. A dismissed approval does not block the merge button, so check the review state of a pull request before merging it.