diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a104659..17b96ea 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