From acd3e4fb1a62a73e0007782489c2f58ddd706a60 Mon Sep 17 00:00:00 2001 From: Mehdi ABAAKOUK Date: Fri, 27 Nov 2026 13:14:36 +0100 Subject: [PATCH] fix: retry the install.sh download on timeouts and server errors The action downloaded mergify-cli's install.sh from raw.githubusercontent.com in a single try, so one 503 or 504 from GitHub failed the step, and the job with it, although install.sh retries its own downloads. The download now retries the way install.sh does: `curl --retry 8`, which retries timeouts and 408, 429, 500, 502, 503 and 504 answers, the wait doubling from one second (about four minutes of waits). A 10-second connect timeout and a 30-second cap per attempt make a connection or an answer that stalls a retried timeout, where it used to hang until the kernel or the job gave up. `--retry-max-time 300` stops retrying after five minutes, and at once when a Retry-After header asks for a longer wait. A 404 still fails at once. When the retries run out, the step fails naming the URL it could not download, below curl's own error. A 404 on a pinned version says that `mergify_cli_version` is not a mergify-cli release that ships install.sh. The step checks the status code as well as curl's exit code: curl 8.14 exits 0 on an error it does not retry, so a 404 would otherwise reach `sh` as a missing file. Like in install.sh, a refused or reset connection and a TLS error are not retried. Retrying every error (`--retry-all-errors`) would make a mistyped version wait five minutes before failing, and the curl of RHEL 8 (7.61), where mergify-cli runs, does not have it. The new test-install-retry job points raw.githubusercontent.com at 192.0.2.1, an address that never answers, restores it once curl is seen connecting there, and checks that the install succeeds on a later attempt. Nothing is released on merge: release.yaml releases on its own only when the default mergify-cli version changes, so this ships in the release that the next mergify-cli bump cuts. Fixes MRGFY-13647 Co-Authored-By: Claude Opus 5.5 Change-Id: I5e5d02c22cb56bf26e1aebbc375a12f989087ab5 --- .github/workflows/ci.yaml | 34 ++++++++++++++++++++++++++++++++++ README.md | 3 ++- action.yml | 18 ++++++++++++++++-- 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f713089..b69633b 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -116,12 +116,46 @@ jobs: test -n "$VERSION" test "$(mergify --version | awk '{print $NF}')" = "$VERSION" + test-install-retry: + timeout-minutes: 5 + runs-on: ubuntu-26.04 + steps: + - name: Checkout 🛎️ + uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0 + + - name: Point raw.githubusercontent.com at an address that never answers + run: | + # 192.0.2.1 is reserved for documentation (RFC 5737): a connection + # to it hangs, so the first download of install.sh times out. + echo "192.0.2.1 raw.githubusercontent.com" | sudo tee -a /etc/hosts + # Restore the name once curl is seen connecting to the dead address, + # so the install can only succeed on a later attempt. + restore_after_first_attempt() { + until ss -tnH state syn-sent dst 192.0.2.1 | grep -q .; do sleep 0.2; done + sudo sed -i "/raw.githubusercontent.com/d" /etc/hosts + date -u +%T > "$RUNNER_TEMP/first-attempt-hung" + } + restore_after_first_attempt > /dev/null 2>&1 & + + - name: Install mergify-cli + id: install + uses: ./ + + - name: Assert the install succeeded on a retry + env: + VERSION: ${{ steps.install.outputs.mergify_cli_version }} + run: | + test -f "$RUNNER_TEMP/first-attempt-hung" + echo "First attempt hung on 192.0.2.1, name restored at $(cat "$RUNNER_TEMP/first-attempt-hung") UTC" + test "$(mergify --version | awk '{print $NF}')" = "$VERSION" + all-greens: if: ${{ !cancelled() }} needs: - linters - autodoc - test-install + - test-install-retry runs-on: ubuntu-26.04 steps: - name: Verify all jobs succeeded diff --git a/README.md b/README.md index 5ef165f..3e3a7ac 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,8 @@ GitHub Action to install the [Mergify CLI](https://github.com/Mergifyio/mergify- It installs the prebuilt `mergify` binary via the mergify-cli `install.sh` installer, which downloads the binary from the GitHub release and verifies it against the release `SHA256SUMS`. For a pinned version the installer is fetched -from that release tag; `latest` uses `main`. The action then puts the binary on +from that release tag; `latest` uses `main`. The action retries that fetch on +timeouts and server errors for up to five minutes. It then puts the binary on `PATH` and exposes the installed version as an output. Pinned by default, `latest` supported. No Python or toolchain is required; Linux and macOS are supported. diff --git a/action.yml b/action.yml index 5d96b03..9e3ff7f 100644 --- a/action.yml +++ b/action.yml @@ -51,8 +51,22 @@ runs: # install.sh supports Linux and macOS only. tmp=$(mktemp -d) trap 'rm -rf "${tmp}"' EXIT - curl -fsSL "https://raw.githubusercontent.com/${REPO}/${ref}/install.sh" -o "${tmp}/install.sh" \ - || die "failed to fetch install.sh (ref ${ref})" + url="https://raw.githubusercontent.com/${REPO}/${ref}/install.sh" + # raw.githubusercontent.com answers a 503 or a 504 now and then: retry + # those and timeouts the way install.sh retries its own downloads, the + # wait doubling from one second. The two timeouts make a stalled + # connection or answer a retried timeout, and --retry-max-time stops + # the retries after five minutes, even when a Retry-After header asks + # for longer. A 404 fails at once. curl 8.14 exits 0 on an error it + # does not retry, such as that 404, so the status code is checked too. + if ! status=$(curl -fsSL --retry 8 --retry-max-time 300 --connect-timeout 10 --max-time 30 \ + -w '%{http_code}' -o "${tmp}/install.sh" "${url}") || [ "${status}" != 200 ]; then + # On main, a 404 is not the input's fault. + if [ "${status}" = 404 ] && [ "${ref}" != main ]; then + die "${url} does not exist: mergify_cli_version ${ref} is not a mergify-cli release that ships install.sh" + fi + die "could not download ${url}, see the curl error above" + fi MERGIFY_VERSION="${MERGIFY_CLI_VERSION}" MERGIFY_INSTALL_DIR="${bindir}" sh "${tmp}/install.sh" # Expose the binary to later steps and read the version back from it