nuclei: 3.3.5 -> 3.3.6 (#358083)
[NixPkgs.git] / maintainers / scripts / check-cherry-picks.sh
blobe7ffe2bf4c73da62557bc5812e4d9ca2198a8ace
1 #!/usr/bin/env bash
2 # Find alleged cherry-picks
4 set -e
6 if [ $# != "2" ] ; then
7 echo "usage: check-cherry-picks.sh base_rev head_rev"
8 exit 2
9 fi
11 PICKABLE_BRANCHES=${PICKABLE_BRANCHES:-master staging release-??.?? staging-??.??}
12 problem=0
14 while read new_commit_sha ; do
15 if [ -z "$new_commit_sha" ] ; then
16 continue # skip empty lines
18 if [ "$GITHUB_ACTIONS" = 'true' ] ; then
19 echo "::group::Commit $new_commit_sha"
20 else
21 echo "================================================="
23 git rev-list --max-count=1 --format=medium "$new_commit_sha"
24 echo "-------------------------------------------------"
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}'
31 if [ "$?" != "0" ] ; then
32 echo " ? Couldn't locate original commit hash in message"
33 [ "$GITHUB_ACTIONS" = 'true' ] && echo ::endgroup::
34 continue
37 set -f # prevent pathname expansion of patterns
38 for branch_pattern in $PICKABLE_BRANCHES ; do
39 set +f # re-enable pathname expansion
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"
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"'
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 " ⚠ "
59 echo "Difference between $new_commit_sha and original $original_commit_sha may warrant inspection:"
61 $range_diff_common --color
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::
72 # move on to next commit
73 continue 3
75 done <<< "$(
76 git for-each-ref \
77 --format="%(refname)" \
78 "refs/remotes/origin/$branch_pattern"
80 done
82 if [ "$GITHUB_ACTIONS" = 'true' ] ; then
83 echo ::endgroup::
84 echo -n "::error ::"
85 else
86 echo -n " ✘ "
88 echo "$original_commit_sha not found in any pickable branch"
90 problem=1
91 done <<< "$(
92 git rev-list \
93 -E -i --grep="cherry.*[0-9a-f]{40}" --reverse \
94 "$1..$2"
97 exit $problem