Merge branch 'tor-github/pr/1451'

This commit is contained in:
David Goulet 2019-10-23 09:11:43 -04:00
commit 9586ae178a
2 changed files with 64 additions and 19 deletions

9
changes/ticket32216 Normal file
View File

@ -0,0 +1,9 @@
o Minor features (git scripts):
- Make git-push-all.sh skip unchanged branches when pushing to upstream.
The script already skipped unchanged test branches.
Closes ticket 32216.
o Minor bugfixes (git scripts):
- Avoid sleeping before the last push in git-push-all.sh.
Closes ticket 32216.
- Forward all unrecognised arguments in git-push-all.sh to git push.
Closes ticket 32216.

View File

@ -29,6 +29,8 @@ function usage()
echo " CI environment failures, using code that previously passed CI."
echo " (default: skip; current: $CURRENT_PUSH_SAME matching branches)"
echo " --: pass further arguments to git push."
echo " All unrecognised arguments are passed to git push, but complex"
echo " arguments before -- may be mangled by getopt."
echo " (default: git push --atomic, current: $GIT_PUSH)"
echo
echo " env vars:"
@ -127,9 +129,11 @@ while getopts ":hr:st:" opt; do
OPTIND=$((OPTIND - 2))
;;
*)
# Assume we're done with script arguments,
# and git push will handle the option
break
# Make git push handle the option
# This might mangle options with spaces, use -- for complex options
GIT_PUSH="$GIT_PUSH $1"
shift
OPTIND=$((OPTIND - 1))
;;
esac
done
@ -229,20 +233,31 @@ fi
# Entry point #
###############
# Skip the test branches that are the same as the upstream branches
if [ "$PUSH_SAME" -eq 0 ] && [ "$TEST_BRANCH_PREFIX" ]; then
if [ "$TEST_BRANCH_PREFIX" ]; then
# Skip the test branches that are the same as the default or current
# upstream branches (they have already been tested)
UPSTREAM_SKIP_SAME_AS="$UPSTREAM_BRANCHES $DEFAULT_UPSTREAM_BRANCHES"
else
# Skip the local maint-*, release-*, master branches that are the same as the
# current upstream branches, but ignore the default upstream
# (we want to update a non-default remote, even if it matches the default)
UPSTREAM_SKIP_SAME_AS="$UPSTREAM_BRANCHES"
fi
# Skip branches that match the relevant upstream(s)
if [ "$PUSH_SAME" -eq 0 ]; then
NEW_PUSH_BRANCHES=
for b in $PUSH_BRANCHES; do
PUSH_COMMIT=$(git rev-parse "$b")
SKIP_UPSTREAM=
for u in $DEFAULT_UPSTREAM_BRANCHES $UPSTREAM_BRANCHES; do
for u in $UPSTREAM_SKIP_SAME_AS; do
UPSTREAM_COMMIT=$(git rev-parse "$u")
if [ "$PUSH_COMMIT" = "$UPSTREAM_COMMIT" ]; then
SKIP_UPSTREAM="$u"
fi
done
if [ "$SKIP_UPSTREAM" ]; then
printf "Skipping unchanged: %s remote: %s\n" \
printf "Skipping unchanged: %s matching remote: %s\n" \
"$b" "$SKIP_UPSTREAM"
else
if [ "$NEW_PUSH_BRANCHES" ]; then
@ -255,6 +270,12 @@ if [ "$PUSH_SAME" -eq 0 ] && [ "$TEST_BRANCH_PREFIX" ]; then
PUSH_BRANCHES=${NEW_PUSH_BRANCHES}
fi
if [ ! "$PUSH_BRANCHES" ]; then
echo "No branches to push!"
# We expect the rest of the script to run without errors, even if there
# are no branches
fi
if [ "$PUSH_DELAY" -le 0 ]; then
echo "Pushing $PUSH_BRANCHES"
# We know that there are no spaces in any branch within $PUSH_BRANCHES, so
@ -267,27 +288,42 @@ if [ "$PUSH_DELAY" -le 0 ]; then
else
# Push the branches in optimal CI order, with a delay between each push
PUSH_BRANCHES=$(echo "$PUSH_BRANCHES" | tr " " "\n" | sort -V)
MASTER_BRANCH=$(echo "$PUSH_BRANCHES" | tr " " "\n" | grep master)
MASTER_BRANCH=$(echo "$PUSH_BRANCHES" | tr " " "\n" | grep master) \
|| true # Skipped master branch
if [ -z "$TEST_BRANCH_PREFIX" ]; then
MAINT_BRANCHES=$(echo "$PUSH_BRANCHES" | tr " " "\n" | grep maint)
MAINT_BRANCHES=$(echo "$PUSH_BRANCHES" | tr " " "\n" | grep maint) \
|| true # Skipped all maint branches
RELEASE_BRANCHES=$(echo "$PUSH_BRANCHES" | tr " " "\n" | grep release | \
tr "\n" " ")
printf "Pushing with %ss delays, so CI runs in this order:\n%s\n%s\n%s\n" \
"$PUSH_DELAY" "$MASTER_BRANCH" "$MAINT_BRANCHES" "$RELEASE_BRANCHES"
tr "\n" " ") || true # Skipped all release branches
else
# Actually test branches based on maint branches
MAINT_BRANCHES=$(echo "$PUSH_BRANCHES" | tr " " "\n" | grep -v master)
printf "Pushing with %ss delays, so CI runs in this order:\n%s\n%s\n" \
"$PUSH_DELAY" "$MASTER_BRANCH" "$MAINT_BRANCHES"
MAINT_BRANCHES=$(echo "$PUSH_BRANCHES" | tr " " "\n" | grep -v master) \
|| true # Skipped all maint test branches
# No release branches
RELEASE_BRANCHES=
fi
$GIT_PUSH "$@" "$UPSTREAM_REMOTE" "$MASTER_BRANCH"
sleep "$PUSH_DELAY"
if [ "$MASTER_BRANCH" ] || [ "$MAINT_BRANCHES" ] \
|| [ "$RELEASE_BRANCHES" ]; then
printf "Pushing with %ss delays, so CI runs in this order:\n" "$PUSH_DELAY"
if [ "$MASTER_BRANCH" ]; then
printf "%s\n" "$MASTER_BRANCH"
fi
if [ "$MAINT_BRANCHES" ]; then
printf "%s\n" "$MAINT_BRANCHES"
fi
if [ "$RELEASE_BRANCHES" ]; then
printf "%s\n" "$RELEASE_BRANCHES"
fi
fi
# shellcheck disable=SC2086
for b in $MAINT_BRANCHES; do
for b in $MASTER_BRANCH $MAINT_BRANCHES; do
$GIT_PUSH "$@" "$UPSTREAM_REMOTE" "$b"
sleep "$PUSH_DELAY"
# If we are pushing more than one branch, delay.
# In the unlikely scenario where we are pushing maint without master,
# or maint without release, there may be an extra delay
if [ "$MAINT_BRANCHES" ] || [ "$RELEASE_BRANCHES" ]; then
sleep "$PUSH_DELAY"
fi
done
if [ "$RELEASE_BRANCHES" ]; then
# shellcheck disable=SC2086