-
Notifications
You must be signed in to change notification settings - Fork 66.9k
Expand file tree
/
Copy pathaction.yml
More file actions
49 lines (45 loc) · 1.39 KB
/
action.yml
File metadata and controls
49 lines (45 loc) · 1.39 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
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
run: |
# Generic retry function: configurable attempts and delay
retry_command() {
local max_attempts=${{ inputs.max_attempts }}
local delay=${{ inputs.delay }}
local attempt=1
local command="${{ inputs.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