|
1 | 1 | #!/usr/bin/env bash |
2 | 2 | set -euo pipefail |
3 | 3 |
|
| 4 | +# Retry configuration for downloads |
| 5 | +# Hardcoded values - meant for transient network issues, not hard outages |
| 6 | +max_retries=3 |
| 7 | +retry_delay=5 |
| 8 | + |
4 | 9 | executable="monorepo-diff-buildkite-plugin" |
5 | 10 | executable_version_file="${executable}.version" |
6 | 11 |
|
@@ -66,6 +71,29 @@ downloader() { |
66 | 71 | fi |
67 | 72 | } |
68 | 73 |
|
| 74 | +# Retry wrapper for downloads (SUP-5615) |
| 75 | +download_with_retry() { |
| 76 | + local _url="$1" |
| 77 | + local _dest="$2" |
| 78 | + local _attempt=1 |
| 79 | + |
| 80 | + while [ $_attempt -le "$max_retries" ]; do |
| 81 | + say "Downloading binary (attempt ${_attempt}/${max_retries})..." |
| 82 | + if downloader "$_url" "$_dest"; then |
| 83 | + say "Download successful" |
| 84 | + return 0 |
| 85 | + fi |
| 86 | + |
| 87 | + if [ $_attempt -lt "$max_retries" ]; then |
| 88 | + say "Download failed, retrying in ${retry_delay} seconds..." |
| 89 | + sleep "$retry_delay" |
| 90 | + fi |
| 91 | + _attempt=$((_attempt + 1)) |
| 92 | + done |
| 93 | + |
| 94 | + return 1 |
| 95 | +} |
| 96 | + |
69 | 97 | get_latest_version() { |
70 | 98 | local _repo="https://api.github.com/repos/buildkite-plugins/monorepo-diff-buildkite-plugin" |
71 | 99 | local _version="" |
@@ -143,14 +171,14 @@ download_binary_and_run() { |
143 | 171 | fi |
144 | 172 |
|
145 | 173 | if [ -n "${_url}" ]; then |
146 | | - if ! downloader "$_url" "${executable}"; then |
147 | | - say "failed to download $_url" |
| 174 | + # Use retry wrapper for resilient downloads (SUP-5615) |
| 175 | + if ! download_with_retry "$_url" "${executable}"; then |
| 176 | + say "Failed to download $_url after ${max_retries} attempts" |
148 | 177 | exit 1 |
149 | 178 | fi |
150 | 179 | echo "${_binary_version}" > "${executable_version_file}" |
151 | 180 | fi |
152 | 181 |
|
153 | | - # todo: move it to a more secure place |
154 | 182 | chmod +x "${executable}" |
155 | 183 |
|
156 | 184 | ./"${executable}" |
|
0 commit comments