git-push-all.sh 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/usr/bin/env bash
  2. # Usage: git-push-all.sh
  3. # env vars: TOR_UPSTREAM_REMOTE_NAME=upstream TOR_PUSH_DELAY=0
  4. # options: --no-atomic --dry-run (any other git push option)
  5. #
  6. # TOR_PUSH_DELAY pushes the master and maint branches separately, so that CI
  7. # runs in a sensible order.
  8. # push --atomic is the default when TOR_PUSH_DELAY=0, and for release branches.
  9. set -e
  10. # The upstream remote which git.torproject.org/tor.git points to.
  11. UPSTREAM_REMOTE=${TOR_UPSTREAM_REMOTE_NAME:-"upstream"}
  12. # Add a delay between pushes, so CI runs on the most important branches first
  13. PUSH_DELAY=${TOR_PUSH_DELAY:-0}
  14. PUSH_BRANCHES=$(echo \
  15. master \
  16. {release,maint}-0.4.1 \
  17. {release,maint}-0.4.0 \
  18. {release,maint}-0.3.5 \
  19. {release,maint}-0.2.9 \
  20. )
  21. if [ "$PUSH_DELAY" -le 0 ]; then
  22. echo "Pushing $PUSH_BRANCHES"
  23. # We know that there are no spaces in any branch within $PUSH_BRANCHES, so
  24. # it is safe to use it unquoted. (This also applies to the other shellcheck
  25. # exceptions below.)
  26. #
  27. # shellcheck disable=SC2086
  28. git push --atomic "$@" "$UPSTREAM_REMOTE" $PUSH_BRANCHES
  29. else
  30. PUSH_BRANCHES=$(echo "$PUSH_BRANCHES" | tr " " "\n" | sort -V)
  31. MASTER_BRANCH=$(echo "$PUSH_BRANCHES" | tr " " "\n" | grep master)
  32. MAINT_BRANCHES=$(echo "$PUSH_BRANCHES" | tr " " "\n" | grep maint)
  33. RELEASE_BRANCHES=$(echo "$PUSH_BRANCHES" | tr " " "\n" | grep release | \
  34. tr "\n" " ")
  35. printf "Pushing with %ss delays, so CI runs in this order:\n%s\n%s\n%s\n" \
  36. "$PUSH_DELAY" "$MASTER_BRANCH" "$MAINT_BRANCHES" "$RELEASE_BRANCHES"
  37. git push "$@" "$UPSTREAM_REMOTE" "$MASTER_BRANCH"
  38. sleep "$PUSH_DELAY"
  39. # shellcheck disable=SC2086
  40. for b in $MAINT_BRANCHES; do
  41. git push "$@" "$UPSTREAM_REMOTE" $b
  42. sleep "$PUSH_DELAY"
  43. done
  44. # shellcheck disable=SC2086
  45. git push --atomic "$@" "$UPSTREAM_REMOTE" $RELEASE_BRANCHES
  46. fi