at 25.11-pre 2.9 kB view raw
1#!/usr/bin/env bash 2# Find alleged cherry-picks 3 4set -e 5 6if [ $# != "2" ] ; then 7 echo "usage: check-cherry-picks.sh base_rev head_rev" 8 exit 2 9fi 10 11PICKABLE_BRANCHES=${PICKABLE_BRANCHES:-master staging release-??.?? staging-??.??} 12problem=0 13 14while read new_commit_sha ; do 15 if [ -z "$new_commit_sha" ] ; then 16 continue # skip empty lines 17 fi 18 if [ "$GITHUB_ACTIONS" = 'true' ] ; then 19 echo "::group::Commit $new_commit_sha" 20 else 21 echo "=================================================" 22 fi 23 git rev-list --max-count=1 --format=medium "$new_commit_sha" 24 echo "-------------------------------------------------" 25 26 original_commit_sha=$( 27 git rev-list --max-count=1 --format=format:%B "$new_commit_sha" \ 28 | grep -Ei -m1 "cherry.*[0-9a-f]{40}" \ 29 | grep -Eoi -m1 '[0-9a-f]{40}' 30 ) 31 if [ "$?" != "0" ] ; then 32 echo " ? Couldn't locate original commit hash in message" 33 [ "$GITHUB_ACTIONS" = 'true' ] && echo ::endgroup:: 34 continue 35 fi 36 37 set -f # prevent pathname expansion of patterns 38 for branch_pattern in $PICKABLE_BRANCHES ; do 39 set +f # re-enable pathname expansion 40 41 while read -r picked_branch ; do 42 if git merge-base --is-ancestor "$original_commit_sha" "$picked_branch" ; then 43 echo "$original_commit_sha present in branch $picked_branch" 44 45 range_diff_common='git range-diff 46 --no-notes 47 --creation-factor=100 48 '"$original_commit_sha~..$original_commit_sha"' 49 '"$new_commit_sha~..$new_commit_sha"' 50 ' 51 52 if $range_diff_common --no-color | grep -E '^ {4}[+-]{2}' > /dev/null ; then 53 if [ "$GITHUB_ACTIONS" = 'true' ] ; then 54 echo ::endgroup:: 55 echo -n "::warning ::" 56 else 57 echo -n " ⚠ " 58 fi 59 echo "Difference between $new_commit_sha and original $original_commit_sha may warrant inspection:" 60 61 $range_diff_common --color 62 63 echo "Note this should not necessarily be treated as a hard fail, but a reviewer's attention should" \ 64 "be drawn to it and github actions have no way of doing that but to raise a 'failure'" 65 problem=1 66 else 67 echo "$original_commit_sha highly similar to $new_commit_sha" 68 $range_diff_common --color 69 [ "$GITHUB_ACTIONS" = 'true' ] && echo ::endgroup:: 70 fi 71 72 # move on to next commit 73 continue 3 74 fi 75 done <<< "$( 76 git for-each-ref \ 77 --format="%(refname)" \ 78 "refs/remotes/origin/$branch_pattern" 79 )" 80 done 81 82 if [ "$GITHUB_ACTIONS" = 'true' ] ; then 83 echo ::endgroup:: 84 echo -n "::error ::" 85 else 86 echo -n " ✘ " 87 fi 88 echo "$original_commit_sha not found in any pickable branch" 89 90 problem=1 91done <<< "$( 92 git rev-list \ 93 -E -i --grep="cherry.*[0-9a-f]{40}" --reverse \ 94 "$1..$2" 95)" 96 97exit $problem