|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -e |
| 4 | + |
| 5 | +BUILDPULSE_CACHE_VERSION="v0.11.6" |
| 6 | + |
| 7 | +# Enable double globbing if supported by the shell on the base github runner |
| 8 | +if shopt -s globstar; then |
| 9 | + echo "This bash shell version supports double globbing: '${BASH_VERSION}'." |
| 10 | + |
| 11 | +else |
| 12 | + echo "This bash shell version does not support double globbing: '${BASH_VERSION}'. Please upgrade to bash 4+." |
| 13 | +fi |
| 14 | + |
| 15 | +case "$RUNNER_OS" in |
| 16 | + Linux) |
| 17 | + OS=linux |
| 18 | + ;; |
| 19 | + macOS) |
| 20 | + OS=macos |
| 21 | + ;; |
| 22 | + Windows) |
| 23 | + OS=win.exe |
| 24 | + ;; |
| 25 | + *) |
| 26 | + echo "::error::Unrecognized operating system. Expected RUNNER_OS to be one of \"Linux\", \"macOS\", or \"Windows\", but it was \"$RUNNER_OS\"." |
| 27 | + exit 1 |
| 28 | +esac |
| 29 | + |
| 30 | +ARCH=$(uname -m) |
| 31 | +case "$ARCH" in |
| 32 | + x86_64) ARCH="x64" ;; |
| 33 | + aarch64) ARCH="arm64" ;; |
| 34 | + armv7l) ARCH="armv7" ;; |
| 35 | + *) ARCH="unknown" ;; |
| 36 | +esac |
| 37 | + |
| 38 | +BUILDPULSE_CACHE_BINARY="${BUILDPULSE_CACHE_VERSION}-${ARCH}/cache-${OS}" |
| 39 | + |
| 40 | +BUILDPULSE_CACHE_HOSTS=( |
| 41 | + https://github.com/buildpulse/buildpulse-circleci-orb/releases/download/ |
| 42 | +) |
| 43 | +[ -n "${INPUT_CLI_HOST}" ] && BUILDPULSE_CACHE_HOSTS=("${INPUT_CLI_HOST}" "${BUILDPULSE_CACHE_HOSTS[@]}") |
| 44 | + |
| 45 | +getcli() { |
| 46 | + local rval=-1 |
| 47 | + for host in "${BUILDPULSE_CACHE_HOSTS[@]}"; do |
| 48 | + url="${host}/${BUILDPULSE_CACHE_BINARY}" |
| 49 | + if (set -x; curl -fsSL --retry 3 --retry-connrefused --connect-timeout 5 "$url" > "$1"); then |
| 50 | + return 0 |
| 51 | + else |
| 52 | + rval=$? |
| 53 | + fi |
| 54 | + done; |
| 55 | + |
| 56 | + return $rval |
| 57 | +} |
| 58 | + |
| 59 | +if getcli ./buildpulse-cache; then |
| 60 | + : # Successfully fetched binary. Great! |
| 61 | +else |
| 62 | + msg=$(cat <<-eos |
| 63 | + ::warning::Unable to fetch BuildPulse Cache binary. |
| 64 | +
|
| 65 | + If you continue seeing this problem, please get in touch at |
| 66 | + https://buildpulse.io/contact so we can look into this issue. |
| 67 | + eos |
| 68 | + ) |
| 69 | + |
| 70 | + echo "${msg//$'\n'/%0A}" # Replace newlines with URL-encoded newlines for proper formatting in GitHub Actions annotations (https://github.com/actions/toolkit/issues/193#issuecomment-605394935) |
| 71 | + exit 0 |
| 72 | +fi |
| 73 | + |
| 74 | +chmod +x ./buildpulse-cache |
| 75 | + |
| 76 | +set -x |
| 77 | + |
| 78 | +ACTION=$1 |
| 79 | + |
| 80 | +./builpulse-cache $ACTION |
0 commit comments