git-push-all.sh 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/usr/bin/env bash
  2. # Usage: git-push-all.sh <git-opts>
  3. # env vars: TOR_UPSTREAM_REMOTE_NAME=upstream TOR_PUSH_DELAY=0
  4. # git-opts: --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. #################
  11. # Configuration #
  12. #################
  13. # Don't change this configuration - set the env vars in your .profile
  14. #
  15. # The upstream remote which git.torproject.org/tor.git points to.
  16. UPSTREAM_REMOTE=${TOR_UPSTREAM_REMOTE_NAME:-"upstream"}
  17. # Add a delay between pushes, so CI runs on the most important branches first
  18. PUSH_DELAY=${TOR_PUSH_DELAY:-0}
  19. ########################
  20. # Git branches to push #
  21. ########################
  22. PUSH_BRANCHES=$(echo \
  23. master \
  24. {release,maint}-0.4.1 \
  25. {release,maint}-0.4.0 \
  26. {release,maint}-0.3.5 \
  27. {release,maint}-0.2.9 \
  28. )
  29. ###############
  30. # Entry point #
  31. ###############
  32. if [ "$PUSH_DELAY" -le 0 ]; then
  33. echo "Pushing $PUSH_BRANCHES"
  34. # We know that there are no spaces in any branch within $PUSH_BRANCHES, so
  35. # it is safe to use it unquoted. (This also applies to the other shellcheck
  36. # exceptions below.)
  37. #
  38. # shellcheck disable=SC2086
  39. git push --atomic "$@" "$UPSTREAM_REMOTE" $PUSH_BRANCHES
  40. else
  41. PUSH_BRANCHES=$(echo "$PUSH_BRANCHES" | tr " " "\n" | sort -V)
  42. MASTER_BRANCH=$(echo "$PUSH_BRANCHES" | tr " " "\n" | grep master)
  43. MAINT_BRANCHES=$(echo "$PUSH_BRANCHES" | tr " " "\n" | grep maint)
  44. RELEASE_BRANCHES=$(echo "$PUSH_BRANCHES" | tr " " "\n" | grep release | \
  45. tr "\n" " ")
  46. printf "Pushing with %ss delays, so CI runs in this order:\n%s\n%s\n%s\n" \
  47. "$PUSH_DELAY" "$MASTER_BRANCH" "$MAINT_BRANCHES" "$RELEASE_BRANCHES"
  48. git push "$@" "$UPSTREAM_REMOTE" "$MASTER_BRANCH"
  49. sleep "$PUSH_DELAY"
  50. # shellcheck disable=SC2086
  51. for b in $MAINT_BRANCHES; do
  52. git push "$@" "$UPSTREAM_REMOTE" $b
  53. sleep "$PUSH_DELAY"
  54. done
  55. # shellcheck disable=SC2086
  56. git push --atomic "$@" "$UPSTREAM_REMOTE" $RELEASE_BRANCHES
  57. fi