ci/check-cherry-picks: refactor output / logging

This way it's a bit more centralized and easier to extend.
This commit is contained in:
Wolfgang Walther 2025-05-28 20:03:54 +02:00
parent 30600ac6d1
commit 6054a8f217
No known key found for this signature in database
GPG key ID: B39893FA5F65CAE1

View file

@ -19,6 +19,29 @@ remote="$(git remote -v | grep -i 'NixOS/nixpkgs' | head -n1 | cut -f1 || true)"
commits="$(git rev-list --reverse "$1..$2")" commits="$(git rev-list --reverse "$1..$2")"
log() {
type="$1"
shift 1
local -A prefix
prefix[success]=" ✔ "
if [ -v GITHUB_ACTIONS ]; then
prefix[warning]="::warning::"
prefix[error]="::error::"
else
prefix[warning]=" ⚠ "
prefix[error]=" ✘ "
fi
echo "${prefix[$type]}$@"
}
endgroup() {
if [ -v GITHUB_ACTIONS ] ; then
echo ::endgroup::
fi
}
while read -r new_commit_sha ; do while read -r new_commit_sha ; do
if [ -v GITHUB_ACTIONS ] ; then if [ -v GITHUB_ACTIONS ] ; then
echo "::group::Commit $new_commit_sha" echo "::group::Commit $new_commit_sha"
@ -34,13 +57,8 @@ while read -r new_commit_sha ; do
| grep -Eoi -m1 '[0-9a-f]{40}' || true | grep -Eoi -m1 '[0-9a-f]{40}' || true
) )
if [ -z "$original_commit_sha" ] ; then if [ -z "$original_commit_sha" ] ; then
if [ -v GITHUB_ACTIONS ] ; then endgroup
echo ::endgroup:: log error "Couldn't locate original commit hash in message"
echo -n "::error ::"
else
echo -n " ✘ "
fi
echo "Couldn't locate original commit hash in message"
echo "Note this should not necessarily be treated as a hard fail, but a reviewer's attention should" \ echo "Note this should not necessarily be treated as a hard fail, but a reviewer's attention should" \
"be drawn to it and github actions have no way of doing that but to raise a 'failure'" "be drawn to it and github actions have no way of doing that but to raise a 'failure'"
problem=1 problem=1
@ -62,8 +80,6 @@ while read -r new_commit_sha ; do
while read -r picked_branch ; do while read -r picked_branch ; do
if git merge-base --is-ancestor "$original_commit_sha" "$picked_branch" ; then if git merge-base --is-ancestor "$original_commit_sha" "$picked_branch" ; then
echo "$original_commit_sha present in branch $picked_branch"
range_diff_common='git --no-pager range-diff range_diff_common='git --no-pager range-diff
--no-notes --no-notes
--creation-factor=100 --creation-factor=100
@ -72,13 +88,9 @@ while read -r new_commit_sha ; do
' '
if $range_diff_common --no-color 2> /dev/null | grep -E '^ {4}[+-]{2}' > /dev/null ; then if $range_diff_common --no-color 2> /dev/null | grep -E '^ {4}[+-]{2}' > /dev/null ; then
if [ -v GITHUB_ACTIONS ] ; then log success "$original_commit_sha present in branch $picked_branch"
echo ::endgroup:: endgroup
echo -n "::warning ::" log warning "Difference between $new_commit_sha and original $original_commit_sha may warrant inspection:"
else
echo -n " ⚠ "
fi
echo "Difference between $new_commit_sha and original $original_commit_sha may warrant inspection:"
$range_diff_common --color $range_diff_common --color
@ -86,9 +98,10 @@ while read -r new_commit_sha ; do
"be drawn to it and github actions have no way of doing that but to raise a 'failure'" "be drawn to it and github actions have no way of doing that but to raise a 'failure'"
problem=1 problem=1
else else
echo "$original_commit_sha highly similar to $new_commit_sha" log success "$original_commit_sha present in branch $picked_branch"
log success "$original_commit_sha highly similar to $new_commit_sha"
$range_diff_common --color $range_diff_common --color
[ -v GITHUB_ACTIONS ] && echo ::endgroup:: endgroup
fi fi
# move on to next commit # move on to next commit
@ -97,13 +110,8 @@ while read -r new_commit_sha ; do
done <<< "$branches" done <<< "$branches"
done done
if [ -v GITHUB_ACTIONS ] ; then endgroup
echo ::endgroup:: log error "$original_commit_sha not found in any pickable branch"
echo -n "::error ::"
else
echo -n " ✘ "
fi
echo "$original_commit_sha not found in any pickable branch"
problem=1 problem=1
done <<< "$commits" done <<< "$commits"