-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathaction.yaml
More file actions
54 lines (48 loc) · 1.55 KB
/
action.yaml
File metadata and controls
54 lines (48 loc) · 1.55 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
name: "Retry Command"
description: "Runs a shell command with retry and timeout support"
inputs:
command:
description: "Shell command to run"
required: true
timeout_seconds:
description: "Maximum number of seconds to allow each attempt"
required: true
retry_wait_seconds:
description: "Number of seconds to wait before retrying"
required: true
max_attempts:
description: "Maximum number of attempts before failing"
required: true
runs:
using: "composite"
steps:
- shell: bash
env:
COMMAND: ${{ inputs.command }}
TIMEOUT_SECONDS: ${{ inputs.timeout_seconds }}
RETRY_WAIT_SECONDS: ${{ inputs.retry_wait_seconds }}
MAX_ATTEMPTS: ${{ inputs.max_attempts }}
run: |
set -euo pipefail
attempt=1
while [ "${attempt}" -le "${MAX_ATTEMPTS}" ]; do
set +e
timeout "${TIMEOUT_SECONDS}" bash -eo pipefail -c "${COMMAND}"
exit_code=$?
set -e
if [ "${exit_code}" -eq 0 ]; then
exit 0
fi
if [ "${attempt}" -eq "${MAX_ATTEMPTS}" ]; then
echo "Command failed after ${MAX_ATTEMPTS} attempts."
exit "${exit_code}"
fi
if [ "${exit_code}" -eq 124 ]; then
echo "Command timed out after ${TIMEOUT_SECONDS} seconds."
else
echo "Command failed with exit code ${exit_code}."
fi
echo "Retrying in ${RETRY_WAIT_SECONDS} seconds..."
sleep "${RETRY_WAIT_SECONDS}"
attempt=$((attempt + 1))
done