-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathaction.yml
More file actions
95 lines (82 loc) · 3.12 KB
/
action.yml
File metadata and controls
95 lines (82 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
name: Setup CodSpeed
description: Install the pinned CodSpeed runner with retry and hash verification
inputs:
runner-version:
description: CodSpeed runner version to install.
default: '4.13.0'
installer-sha256:
description: Expected SHA-256 for the installer script.
default: '55d150594275efb4a983b2f5626e84646269f42678f72554a26d6ce25b64e2d4'
download-retries:
description: Number of download attempts before failing.
default: '5'
retry-delay-seconds:
description: Delay between download attempts.
default: '3'
runs:
using: composite
steps:
- name: Install CodSpeed runner
shell: bash
run: |
set -euo pipefail
RUNNER_VERSION="${{ inputs.runner-version }}"
EXPECTED_HASH="${{ inputs.installer-sha256 }}"
DOWNLOAD_RETRIES="${{ inputs.download-retries }}"
RETRY_DELAY_SECONDS="${{ inputs.retry-delay-seconds }}"
INSTALLER_URL="https://codspeed.io/v${RUNNER_VERSION}/install.sh"
INSTALLER_TMP="$(mktemp)"
CURL_ERR="$(mktemp)"
trap 'rm -f "$INSTALLER_TMP" "$CURL_ERR"' EXIT
checksum() {
if command -v sha256sum >/dev/null 2>&1; then
sha256sum "$1" | awk '{print $1}'
else
shasum -a 256 "$1" | awk '{print $1}'
fi
}
attempt=1
while true; do
: >"$INSTALLER_TMP"
: >"$CURL_ERR"
CURL_EXIT=0
HTTP_CODE=""
if HTTP_CODE="$(curl -sSL -o "$INSTALLER_TMP" -w "%{http_code}" "$INSTALLER_URL" 2>"$CURL_ERR")"; then
CURL_EXIT=0
else
CURL_EXIT=$?
fi
if [ "$CURL_EXIT" -eq 0 ] && [ "$HTTP_CODE" -lt 400 ]; then
break
fi
if [ "$CURL_EXIT" -eq 0 ] && [ -n "$HTTP_CODE" ] && [ "$HTTP_CODE" -ge 400 ]; then
FAILURE_REASON="HTTP ${HTTP_CODE} - $(cat "$INSTALLER_TMP")"
else
FAILURE_REASON="$(cat "$CURL_ERR")"
fi
RETRYABLE_FAILURE=1
if [ "$CURL_EXIT" -eq 0 ]; then
case "$HTTP_CODE" in
408|429|500|502|503|504)
RETRYABLE_FAILURE=1
;;
*)
RETRYABLE_FAILURE=0
;;
esac
fi
if [ "$RETRYABLE_FAILURE" -eq 0 ] || [ "$attempt" -ge "$DOWNLOAD_RETRIES" ]; then
echo "::error title=Failed to install CodSpeed CLI::Installation of CodSpeed CLI with version ${RUNNER_VERSION} failed after ${DOWNLOAD_RETRIES} attempts.%0AReason: ${FAILURE_REASON}"
exit 1
fi
echo "CodSpeed installer download failed on attempt ${attempt}/${DOWNLOAD_RETRIES}: ${FAILURE_REASON}"
attempt=$((attempt + 1))
sleep "$RETRY_DELAY_SECONDS"
done
ACTUAL_HASH="$(checksum "$INSTALLER_TMP")"
if [ "$ACTUAL_HASH" != "$EXPECTED_HASH" ]; then
echo "::error::Installer hash mismatch for version ${RUNNER_VERSION}. Expected: ${EXPECTED_HASH}, Got: ${ACTUAL_HASH}"
exit 1
fi
echo "Installer hash verified for version ${RUNNER_VERSION}"
bash "$INSTALLER_TMP" --quiet