From 78c818b28e45bf1d44082ae14468864cbfc2c6f0 Mon Sep 17 00:00:00 2001 From: Benjamin Leggett Date: Fri, 20 Nov 2026 14:03:47 -0500 Subject: [PATCH] fix(ci): automation incorrectly reports squashed prs as "not needed" and skips them --- .automation/skills/lts-audit/SKILL.md | 3 +- .github/scripts/backport-blockers.sh | 30 +++++++++-- .github/scripts/pending-backports.sh | 40 +++++++++++---- .github/scripts/tests/backport.test.sh | 71 ++++++++++++++++++++++++-- .github/workflows/lts-backport.yml | 10 +++- 5 files changed, 135 insertions(+), 19 deletions(-) diff --git a/.automation/skills/lts-audit/SKILL.md b/.automation/skills/lts-audit/SKILL.md index f772251e277860..72875f275b0061 100644 --- a/.automation/skills/lts-audit/SKILL.md +++ b/.automation/skills/lts-audit/SKILL.md @@ -15,7 +15,8 @@ rest. The list comes from `pending-backports.sh`, which counts a mainline commit as present on the LTS tree only when the LTS series has a commit with the same -subject (ignoring a trailing version tag such as ` (6.18)`) or the same +subject (ignoring a trailing version tag such as ` (6.18)`, and a trailing +pull request number such as ` (#122)` when both change the same files) or the same patch-id. So a commit can be listed although it is there: ported under a reworded subject and with a changed diff, folded into another commit, or already in `linux-6.18.y` upstream. And a commit can be listed because it diff --git a/.github/scripts/backport-blockers.sh b/.github/scripts/backport-blockers.sh index 6588478a0fcf96..8f8d9760765e6f 100755 --- a/.github/scripts/backport-blockers.sh +++ b/.github/scripts/backport-blockers.sh @@ -9,7 +9,7 @@ # commits could be applied on top of code they were never written against. # # Usage: -# backport-blockers.sh +# backport-blockers.sh [ []] # # is what pending-backports.sh prints for the whole of # edera/mainline: the mainline commits the LTS tree lacks, oldest first. @@ -24,13 +24,20 @@ # commit that is already on the LTS tree from claiming a different # pending commit that happens to share its subject. # +# A squash merge puts none of the request's commits on mainline, only one +# commit: as GitHub reports it, or a rebased copy with its +# patch-id, with a subject ending in " (#)" unless it was edited. +# So when no request commit matches and is given, the pending +# commits with that patch-id or that subject suffix are written to . +# # Prints the pending commits the pull request has to wait for, oldest first, # and nothing when it can go ahead. set -euo pipefail -if [ $# -ne 5 ] || [ ! -r "$1" ] || [ ! -r "$2" ]; then - echo "usage: $0 " >&2 +if [ $# -lt 5 ] || [ $# -gt 7 ] || [ ! -r "$1" ] || [ ! -r "$2" ] || + ! [[ ${6:-0} =~ ^[0-9]+$ ]] || ! [[ ${7:-0} =~ ^([0-9a-f]{40}|0)$ ]]; then + echo "usage: $0 [ []]" >&2 exit 2 fi pending=$1 @@ -38,6 +45,8 @@ request=$2 l_tip=$(git rev-parse --verify "$3^{commit}") l_base=$(git merge-base "$l_tip" "$(git rev-parse --verify "$4^{commit}")") todo=$5 +pr=${6:-} +merge=${7:-} work=$(mktemp -d) trap 'rm -rf "$work"' EXIT @@ -78,6 +87,21 @@ while IFS=$'\t' read -r sha subject; do files "$sha" >>"$work/files" fi done <"$request" +if [ ! -s "$todo" ] && [ -n "$pr" ]; then + mp= + if [ -n "$merge" ] && git cat-file -e "$merge^{commit}" 2>/dev/null; then + mp=$(pid "$merge") + fi + while IFS=$'\t' read -r n sha subject; do + echo "$n" >>"$work/claimed" + printf '%s\t%s\n' "$sha" "$subject" >>"$todo" + files "$sha" >>"$work/files" + done < <(awk -F'\t' -v t=" (#$pr)" -v p="$mp" ' + (p != "" && $4 == p) || + (length($3) > length(t) && substr($3, length($3) - length(t) + 1) == t) { + print $1 "\t" $2 "\t" $3 + }' "$work/pending") +fi [ -s "$todo" ] || exit 0 sort -u -o "$work/files" "$work/files" first=$(sort -n "$work/claimed" | head -n1) diff --git a/.github/scripts/pending-backports.sh b/.github/scripts/pending-backports.sh index c6ae95a0669378..68983700160ff7 100755 --- a/.github/scripts/pending-backports.sh +++ b/.github/scripts/pending-backports.sh @@ -9,7 +9,9 @@ # - a commit with the same subject, ignoring a trailing version tag such as # " (6.18)" that a port may add (the k-th mainline commit with a subject # pairs with the k-th LTS one, so repeated subjects are counted, not -# merged); or +# merged), and also ignoring each trailing " (#)" that a squash merge +# on either tree adds with its own pull request's number when both +# commits change the same files; or # - a commit with the same patch-id, which catches a port whose subject was # reworded but whose change was not. # @@ -44,17 +46,26 @@ skip=${5:-/dev/null} work=$(mktemp -d) trap 'rm -rf "$work"' EXIT -# TAB TAB , oldest first. +# TAB TAB TAB TAB , oldest first. series() { git log --no-merges --reverse --format='commit %H' --patch "$1" | git patch-id --stable | awk '{ print $2 "\t" $1 }' >"$work/pid.map" + git log --no-merges --format='commit %H' --name-only "$1" | + awk '/^commit / { if (c != "") print c "\t" f; c = $2; f = ""; next } + NF { f = f (f == "" ? "" : " ") $0 } + END { if (c != "") print c "\t" f }' >"$work/files.map" git log --no-merges --reverse --format='%H%x09%s' "$1" | - awk -F'\t' 'NR == FNR { pid[$1] = $2; next } + awk -F'\t' 'FILENAME == ARGV[1] { pid[$1] = $2; next } + FILENAME == ARGV[2] { files[$1] = $2; next } { s = $2 sub(/[ \t]*\((v?[0-9]+\.[0-9]+(\.[0-9y]+)?(-lts)?)\)$/, "", s) - print $1 "\t" s "\t" ($1 in pid ? pid[$1] : "-") - }' "$work/pid.map" - + k = s + while (sub(/ \(#[0-9]+\)$/, "", k)) + ; + print $1 "\t" s "\t" ($1 in pid ? pid[$1] : "-") "\t" k "\t" files[$1] + }' "$work/pid.map" "$work/files.map" - } series "$m_base..$m_tip" >"$work/mainline" series "$l_base..$l_tip" >"$work/lts" @@ -68,13 +79,22 @@ grep -vE '^[[:space:]]*(#|$)' "$skip" | sed -E 's/^[[:space:]]+|[[:space:]]+$//g awk -F'\t' ' FILENAME == ARGV[1] { auto[$0] = 1; next } FILENAME == ARGV[2] { skip[$0] = 1; next } - FILENAME == ARGV[3] { have[$2]++; if ($3 != "-") bypid[$3] = $2; next } + FILENAME == ARGV[3] { + n++; subj[n] = $2; key[n] = $4; files[n] = $5 + if ($3 != "-") bypid[$3] = n + next + } { if (($1 in auto) || ($2 in skip)) next - # A patch-id match uses up the LTS commit it matched, under the - # subject that commit has there, so it cannot also pair with another. - if ($3 in bypid) { have[bypid[$3]]--; delete bypid[$3]; next } - if (have[$2] > 0) { have[$2]--; next } + # A patch-id match uses up the LTS commit it matched, so it cannot + # also pair with another. + if ($3 in bypid) { used[bypid[$3]] = 1; delete bypid[$3]; next } + m = 0 + for (i = 1; i <= n && !m; i++) + if (!used[i] && subj[i] == $2) m = i + for (i = 1; i <= n && !m; i++) + if (!used[i] && key[i] == $4 && files[i] == $5) m = i + if (m) { used[m] = 1; next } print $1 "\t" $2 } ' "$work/automation" "$work/skip" "$work/lts" "$work/mainline" diff --git a/.github/scripts/tests/backport.test.sh b/.github/scripts/tests/backport.test.sh index 9c650aba454d5b..31086e1d451f2d 100755 --- a/.github/scripts/tests/backport.test.sh +++ b/.github/scripts/tests/backport.test.sh @@ -45,8 +45,8 @@ echo "upstream main" >u.c commit "upstream: mainline moves on" # Edera on LTS: one commit both trees share, one ported with a version tag, -# one reworded but identical in content, one LTS-only, and a repeated subject -# once. +# one reworded but identical in content, one LTS-only, a repeated subject +# once, and #11 adapted and then squash-merged as pull request #22. git switch -q -c lts lts-up sed -i 's/^5$/5 shared/' a.c commit "xen: shared fix" @@ -56,6 +56,8 @@ sed -i 's/^25$/25 reworded/' a.c commit "xen: lts wording of a fix" echo lts-only >l.c commit "drm: lts only" +sed -i 's/^45$/45 adapted for lts/' a.c +commit "xen: fixed by a squash merge (#11) (#22)" sed -i 's/^30$/30 dep one/' b.c commit "apply dep patch" lts_tip=$(git rev-parse HEAD) @@ -70,6 +72,8 @@ sed -i 's/^15$/15 ported/' a.c commit "9p/xen: share one frontend" sed -i 's/^25$/25 reworded/' a.c commit "xen: mainline wording of a fix" +sed -i 's/^35$/35 as on mainline/' a.c +commit "xen: fixed by a squash merge (#11)" sed -i 's/^30$/30 dep one/' b.c commit "apply dep patch" git switch -q -c side @@ -105,7 +109,7 @@ if [ -z "$got" ]; then ok "a tree against itself has nothing pending"; else bash "$PENDING" "$main_tip" mainline-up "$lts_tip" lts-up >"$WORK/pending-all" nth() { git log --reverse --format=%H --grep="^$1\$" "$main_tip" | sed -n "${2:-1}p"; } pr() { for c in "$@"; do printf '%s\t%s\n' "$c" "$(git log -1 --format=%s "$c")"; done >"$WORK/pr"; } -blockers() { bash "$BLOCKERS" "$WORK/pending-all" "$WORK/pr" "$lts_tip" lts-up "$WORK/todo" | cut -f2; } +blockers() { bash "$BLOCKERS" "$WORK/pending-all" "$WORK/pr" "$lts_tip" lts-up "$WORK/todo" ${prnum:+"$prnum"} ${mergesha:+"$mergesha"} | cut -f2; } check() { # check local got got=$(blockers) @@ -141,6 +145,67 @@ bash "$PENDING" "$main_tip" mainline-up "$lts_tip" lts-up "$WORK/skip2" >"$WORK/ pr "$(nth 'apply dep patch' 2)" check "a skipped commit does not block" "" 1 +# A squash merge of pull request #7: its two commits stay off mainline, one +# commit titled "... (#7)" lands there. #17 lands the same way on another file, +# and #9 with its title edited at merge. +git switch -q -c pr7 "$main_tip" +sed -i 's/^45$/45 part one/' b.c +commit "xen: part one" +sed -i 's/^55$/55 part two/' b.c +commit "xen: part two" +mapfile -t pr7_commits < <(git log --reverse --format=%H "$main_tip..pr7") +git switch -q -c squashed "$main_tip" +echo other >c.c +commit "xen: other feature (#17)" +git merge -q --squash pr7 >/dev/null 2>&1 +commit "xen: two part feature (#7)" +git switch -q -c pr9 squashed +echo one >d.c +commit "xen: nine part one" +echo two >>d.c +commit "xen: nine part two" +mapfile -t pr9_commits < <(git log --reverse --format=%H "squashed..pr9") +git switch -q squashed +git merge -q --squash pr9 >/dev/null 2>&1 +commit "xen: title edited at merge" +pr9_merge=$(git rev-parse HEAD) +bash "$PENDING" squashed mainline-up "$lts_tip" lts-up "$WORK/skip" >"$WORK/pending-all" +git switch -q main + +pr "${pr7_commits[@]}" +prnum=7 +check "a squashed pull request waits for earlier pending commits on its files" \ + "$(printf '%s\n' "xen: new on mainline" "apply dep patch")" 1 +if [ "$(cut -f2 "$WORK/todo")" = "xen: two part feature (#7)" ]; then + ok "a squashed pull request requests its squash commit" +else + bad "a squashed pull request requests its squash commit" "todo: $(cat "$WORK/todo")" +fi +pr "$(nth 'xen: new on mainline')" +check "a request that matches does not also take the squash commit" "" 1 +pr "${pr9_commits[@]}" +prnum=9 mergesha=$pr9_merge +check "a squash commit with an edited title is matched by its merge commit" "" 1 +if [ "$(cut -f2 "$WORK/todo")" = "xen: title edited at merge" ]; then + ok "the merge commit's match requests the squash commit" +else + bad "the merge commit's match requests the squash commit" "todo: $(cat "$WORK/todo")" +fi +prnum='' mergesha='' + +# A pull request number does not pair two commits with one title that change +# different files. +git switch -q -c lts-other "$lts_tip" +echo lts >o.c +commit "drm: one title (#31)" +git switch -q -c main-other "$main_tip" +echo main >p.c +commit "drm: one title (#30)" +git switch -q main +got=$(bash "$PENDING" main-other mainline-up lts-other lts-up "$WORK/skip" | cut -f2 | tail -n1) +if [ "$got" = "drm: one title (#30)" ]; then ok "one title on different files stays pending"; else + bad "one title on different files stays pending" "got: $got"; fi + bash "$PENDING" "$main_tip" mainline-up "$lts_tip" lts-up "$WORK/skip" >"$WORK/request" expect() { diff --git a/.github/workflows/lts-backport.yml b/.github/workflows/lts-backport.yml index c3f12d4be33791..dcd2e549f669fe 100644 --- a/.github/workflows/lts-backport.yml +++ b/.github/workflows/lts-backport.yml @@ -155,10 +155,16 @@ jobs: done >>"$out/skip" bash "$tools/scripts/pending-backports.sh" "$src" "$src_up" "$old" "$tgt_up" "$out/skip" >"$out/pending" - bash "$tools/scripts/backport-blockers.sh" "$out/pending" "$out/request" "$old" "$tgt_up" "$out/todo" >"$out/blockers" + # A squash merge's commit, for backport-blockers.sh to match by + # patch-id. Without it, the subject suffix " (#N)" still matches. + merge=$(jq -r '.merge_commit_sha // ""' <<<"$pr") + if ! [[ $merge =~ ^[0-9a-f]{40}$ ]] || ! git fetch --no-tags --filter=blob:none origin "$merge"; then + merge= + fi + bash "$tools/scripts/backport-blockers.sh" "$out/pending" "$out/request" "$old" "$tgt_up" "$out/todo" "$PR" ${merge:+"$merge"} >"$out/blockers" if [ ! -s "$out/todo" ]; then - finish skipped "Nothing to backport: every commit of #$PR is already on \`$TARGET\` (\`${old:0:12}\`), changes only automation, or is no longer an Edera commit on \`$SOURCE\`." + finish skipped "Nothing to backport: every commit of #$PR is already on \`$TARGET\` (tip \`${old:0:12}\`), changes only automation, or is no longer an Edera commit on \`$SOURCE\`." fi if [ -s "$out/blockers" ]; then {