From 92533bee736f8f489f407ecd0c5bbf3ab6487603 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Fri, 2 Oct 2026 19:37:37 +0200 Subject: [PATCH] [scripts] Recognize inherited backport commits Target the current release/11.0.1xx branch while retaining support for open and closed backport pull requests. Fetch each release branch and fall back to its commit history so backports merged into the ancestral RC2 branch are still recognized. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 331659ad-a2d8-42b0-a566-9f272f142c42 --- scripts/check-backports.sh | 59 ++++++++++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 9 deletions(-) diff --git a/scripts/check-backports.sh b/scripts/check-backports.sh index aaa0ff7b3f62..4212171137dc 100755 --- a/scripts/check-backports.sh +++ b/scripts/check-backports.sh @@ -6,8 +6,9 @@ set -euo pipefail repository=${REPOSITORY:-dotnet/macios} +remote=${REMOTE:-origin} net10_branch=${NET10_BRANCH:-release/10.0.1xx} -net11_branch=${NET11_BRANCH:-release/11.0.1xx-rc.2} +net11_branch=${NET11_BRANCH:-release/11.0.1xx} red="" green="" @@ -28,11 +29,13 @@ usage () Usage: $(basename "$0") Verify that every merged pull request with a backport label has a pull request -targeting the corresponding release branch. Open, closed, and merged backport -pull requests all count. +targeting the corresponding release branch, or a matching backport commit in +that branch's history. Open, closed, and merged backport pull requests all +count. Environment variables: REPOSITORY GitHub repository (default: $repository) + REMOTE Git remote to fetch release branches from (default: $remote) NET10_BRANCH .NET 10 target branch (default: $net10_branch) NET11_BRANCH .NET 11 target branch (default: $net11_branch) NO_COLOR Disable colored output when set @@ -49,7 +52,7 @@ if [[ $# -ne 0 ]]; then exit 2 fi -for command in gh jq; do +for command in gh git jq; do if ! command -v "$command" > /dev/null; then echo "error: '$command' is required." >&2 exit 2 @@ -65,12 +68,17 @@ check_backports () { local label=$1 local target_branch=$2 + local target_ref local source_issues_file="$temporary_directory/source-issues.json" local source_details_file="$temporary_directory/source-details.json" local sources_file="$temporary_directory/sources.json" local backports_file="$temporary_directory/backports.json" + local history_file="$temporary_directory/history.json" local results_file="$temporary_directory/results.json" + git fetch "$remote" "$target_branch" --quiet + target_ref=FETCH_HEAD + gh api \ --paginate \ --slurp \ @@ -115,9 +123,24 @@ check_backports () body })' > "$backports_file" + git log --format='%H%x1f%B%x1e' "$target_ref" | + jq -Rs ' + split("\u001e") | + map( + ltrimstr("\n") | + select(length > 0) | + split("\u001f") | + { + commit: .[0], + message: (.[1:] | join("\u001f")) + } + ) + ' > "$history_file" + jq \ --arg branch "$target_branch" \ --slurpfile backports "$backports_file" \ + --slurpfile history "$history_file" \ ' def references_source($source): (.body // "") | test( @@ -126,15 +149,29 @@ check_backports () + "(?:[^0-9]|$)" ); + def commit_references_source($source): + (.message // "") | test( + "(?i)backport of (?:https://github\\.com/[^/\\s]+/[^/\\s]+/pull/)?#?" + + ($source.number | tostring) + + "(?:[^0-9]|$)" + ); + map( . as $source | if .baseRefName == $branch then . + { backport: ., result: "already-targets-branch" } else ([ $backports [0][] | select(references_source($source)) ] | first) as $backport + | ([ $history [0][] | select(commit_references_source($source)) ] | first) as $commit | . + { backport: $backport, - result: (if $backport == null then "missing" else "found" end) + commit: $commit, + result: ( + if $backport != null then "found" + elif $commit != null then "found-in-history" + else "missing" + end + ) } end ) @@ -146,7 +183,7 @@ check_backports () return fi - while IFS=$'\t' read -r result source_number source_url backport_number backport_state; do + while IFS=$'\t' read -r result source_number source_url backport_number backport_state history_commit; do case "$result" in already-targets-branch) printf ' %s[OK]%s #%s already targets %s\n' "$green" "$reset" "$source_number" "$target_branch" @@ -154,8 +191,11 @@ check_backports () found) printf ' %s[OK]%s #%s -> #%s (%s)\n' "$green" "$reset" "$source_number" "$backport_number" "$backport_state" ;; + found-in-history) + printf ' %s[OK]%s #%s -> commit %.12s (in %s history)\n' "$green" "$reset" "$source_number" "$history_commit" "$target_branch" + ;; missing) - printf ' %s[MISSING]%s #%s has no backport PR: %s\n' "$red" "$reset" "$source_number" "$source_url" + printf ' %s[MISSING]%s #%s has no backport PR or commit: %s\n' "$red" "$reset" "$source_number" "$source_url" missing=1 ;; esac @@ -165,8 +205,9 @@ check_backports () .result, .number, .url, - (.backport.number // ""), - (.backport.state // "") + (.backport.number // "-"), + (.backport.state // "-"), + (.commit.commit // "-") ] | @tsv ' "$results_file" )