-
Notifications
You must be signed in to change notification settings - Fork 66.8k
Expand file tree
/
Copy pathaction.yml
More file actions
53 lines (49 loc) · 1.52 KB
/
action.yml
File metadata and controls
53 lines (49 loc) · 1.52 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
name: 'Retry command'
description: 'Retries any command with configurable attempts and delay'
inputs:
command:
description: 'The command to retry'
required: true
max_attempts:
description: 'Maximum number of retry attempts'
required: false
default: '12'
delay:
description: 'Delay between attempts in seconds'
required: false
default: '30'
runs:
using: 'composite'
steps:
- name: Retry command
shell: bash
env:
INPUT_MAX_ATTEMPTS: ${{ inputs.max_attempts }}
INPUT_DELAY: ${{ inputs.delay }}
INPUT_COMMAND: ${{ inputs.command }}
run: |
# Generic retry function: configurable attempts and delay
retry_command() {
local max_attempts=${INPUT_MAX_ATTEMPTS}
local delay=${INPUT_DELAY}
local attempt=1
local command="${INPUT_COMMAND}"
while [ $attempt -le $max_attempts ]; do
echo "Attempt $attempt/$max_attempts: Running command..."
echo "Command: $command"
if eval "$command"; then
echo "Command succeeded on attempt $attempt"
return 0
else
echo "Attempt $attempt failed"
if [ $attempt -lt $max_attempts ]; then
echo "Waiting $delay seconds before retry..."
sleep $delay
fi
fi
attempt=$((attempt + 1))
done
echo "Command failed after $max_attempts attempts"
return 1
}
retry_command