| 1 | #!/usr/bin/env bash |
| 2 | set -euo pipefail |
| 3 | |
| 4 | if [ "$#" -lt 3 ]; then |
| 5 | echo "usage: mirror-push.sh <remote> <label> <git push args...>" >&2 |
| 6 | exit 2 |
| 7 | fi |
| 8 | |
| 9 | remote="$1" |
| 10 | label="$2" |
| 11 | shift 2 |
| 12 | |
| 13 | for attempt in 1 2 3; do |
| 14 | echo "Attempt ${attempt}: pushing ${label} to ${remote}" |
| 15 | if git push "${remote}" "$@" 2>&1; then |
| 16 | echo "Successfully pushed ${label} to ${remote}" |
| 17 | exit 0 |
| 18 | fi |
| 19 | if [ "${attempt}" -lt 3 ]; then |
| 20 | sleep $((attempt * 5)) |
| 21 | fi |
| 22 | done |
| 23 | echo "::error::Failed to push ${label} to ${remote} after 3 attempts" >&2 |
| 24 | exit 1 |
| 25 |