Merge pull request #172098 from risicle/ris-cherry-pick-check

add "check cherry-picks" github action

authored by

Thomas Gerbet and committed by
GitHub
413f0644 f955c923

+116
+24
.github/workflows/check-cherry-picks.yml
··· 1 + name: "Check cherry-picks" 2 + on: 3 + pull_request_target: 4 + branches: 5 + - 'release-*' 6 + - 'staging-*' 7 + 8 + permissions: {} 9 + 10 + jobs: 11 + check: 12 + runs-on: ubuntu-latest 13 + if: github.repository_owner == 'NixOS' 14 + steps: 15 + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 16 + with: 17 + fetch-depth: 0 18 + filter: blob:none 19 + - name: Check cherry-picks 20 + env: 21 + BASE_SHA: ${{ github.event.pull_request.base.sha }} 22 + HEAD_SHA: ${{ github.event.pull_request.head.sha }} 23 + run: | 24 + ./maintainers/scripts/check-cherry-picks.sh "$BASE_SHA" "$HEAD_SHA"
+92
maintainers/scripts/check-cherry-picks.sh
··· 1 + #!/usr/bin/env bash 2 + # Find alleged cherry-picks 3 + 4 + set -e 5 + 6 + if [ $# != "2" ] ; then 7 + echo "usage: check-cherry-picks.sh base_rev head_rev" 8 + exit 2 9 + fi 10 + 11 + PICKABLE_BRANCHES=${PICKABLE_BRANCHES:-master staging release-??.?? staging-??.??} 12 + problem=0 13 + 14 + while read new_commit_sha ; do 15 + if [ "$GITHUB_ACTIONS" = 'true' ] ; then 16 + echo "::group::Commit $new_commit_sha" 17 + else 18 + echo "=================================================" 19 + fi 20 + git rev-list --max-count=1 --format=medium "$new_commit_sha" 21 + echo "-------------------------------------------------" 22 + 23 + original_commit_sha=$( 24 + git rev-list --max-count=1 --format=format:%B "$new_commit_sha" \ 25 + | grep -Ei -m1 "cherry.*[0-9a-f]{40}" \ 26 + | grep -Eoi -m1 '[0-9a-f]{40}' 27 + ) 28 + if [ "$?" != "0" ] ; then 29 + echo " ? Couldn't locate original commit hash in message" 30 + [ "$GITHUB_ACTIONS" = 'true' ] && echo ::endgroup:: 31 + continue 32 + fi 33 + 34 + set -f # prevent pathname expansion of patterns 35 + for branch_pattern in $PICKABLE_BRANCHES ; do 36 + set +f # re-enable pathname expansion 37 + 38 + while read -r picked_branch ; do 39 + if git merge-base --is-ancestor "$original_commit_sha" "$picked_branch" ; then 40 + echo " ✔ $original_commit_sha present in branch $picked_branch" 41 + 42 + range_diff_common='git range-diff 43 + --no-notes 44 + --creation-factor=100 45 + '"$original_commit_sha~..$original_commit_sha"' 46 + '"$new_commit_sha~..$new_commit_sha"' 47 + ' 48 + 49 + if $range_diff_common --no-color | grep -E '^ {4}[+-]{2}' > /dev/null ; then 50 + if [ "$GITHUB_ACTIONS" = 'true' ] ; then 51 + echo ::endgroup:: 52 + echo -n "::warning ::" 53 + else 54 + echo -n " ⚠ " 55 + fi 56 + echo "Difference between $new_commit_sha and original $original_commit_sha may warrant inspection:" 57 + 58 + $range_diff_common --color 59 + 60 + problem=1 61 + else 62 + echo " ✔ $original_commit_sha highly similar to $new_commit_sha" 63 + $range_diff_common --color 64 + [ "$GITHUB_ACTIONS" = 'true' ] && echo ::endgroup:: 65 + fi 66 + 67 + # move on to next commit 68 + continue 3 69 + fi 70 + done <<< "$( 71 + git for-each-ref \ 72 + --format="%(refname)" \ 73 + "refs/remotes/origin/$branch_pattern" 74 + )" 75 + done 76 + 77 + if [ "$GITHUB_ACTIONS" = 'true' ] ; then 78 + echo ::endgroup:: 79 + echo -n "::error ::" 80 + else 81 + echo -n " ✘ " 82 + fi 83 + echo "$original_commit_sha not found in any pickable branch" 84 + 85 + problem=1 86 + done <<< "$( 87 + git rev-list \ 88 + -E -i --grep="cherry.*[0-9a-f]{40}" --reverse \ 89 + "$1..$2" 90 + )" 91 + 92 + exit $problem