Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 50 additions & 9 deletions scripts/check-backports.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=""
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 \
Expand Down Expand Up @@ -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(
Expand All @@ -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
Comment thread
rolfbjarne marked this conversation as resolved.
| . + {
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
)
Expand All @@ -146,16 +183,19 @@ 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"
;;
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
Expand All @@ -165,8 +205,9 @@ check_backports ()
.result,
.number,
.url,
(.backport.number // ""),
(.backport.state // "")
(.backport.number // "-"),
(.backport.state // "-"),
(.commit.commit // "-")
] | @tsv
' "$results_file"
)
Expand Down
Loading