git-push-all.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. git push --atomic "$@" "$UPSTREAM_REMOTE" $PUSH_BRANCHES
  24. else
  25. PUSH_BRANCHES=`echo "$PUSH_BRANCHES" | tr " " "\n" | sort -V`
  26. MASTER_BRANCH=`echo "$PUSH_BRANCHES" | tr " " "\n" | grep master`
  27. MAINT_BRANCHES=`echo "$PUSH_BRANCHES" | tr " " "\n" | grep maint`
  28. RELEASE_BRANCHES=`echo "$PUSH_BRANCHES" | tr " " "\n" | grep release | \
  29. tr "\n" " "`
  30. printf "Pushing with %ss delays, so CI runs in this order:\n%s\n%s\n%s\n" \
  31. "$PUSH_DELAY" "$MASTER_BRANCH" "$MAINT_BRANCHES" "$RELEASE_BRANCHES"
  32. git push "$@" "$UPSTREAM_REMOTE" $MASTER_BRANCH
  33. sleep "$PUSH_DELAY"
  34. for b in $MAINT_BRANCHES; do
  35. git push "$@" "$UPSTREAM_REMOTE" $b
  36. sleep "$PUSH_DELAY"
  37. done
  38. git push --atomic "$@" "$UPSTREAM_REMOTE" $RELEASE_BRANCHES
  39. fi