Skip to content

Commit f08c7d9

Browse files
authored
Merge pull request #7 from cytopia/fail-command
Add fail command
2 parents 5c750d3 + 5ec5a44 commit f08c7d9

File tree

3 files changed

+62
-9
lines changed

3 files changed

+62
-9
lines changed

.github/workflows/test.yml

+39-3
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,53 @@ on:
44
pull_request:
55

66
jobs:
7-
build:
8-
name: test
7+
test-default:
8+
name: test success
99
runs-on: ubuntu-latest
1010
steps:
11+
- name: Checkout repository
12+
uses: actions/checkout@v3
13+
with:
14+
fetch-depth: 0
15+
- name: retry
16+
uses: ./
17+
with:
18+
command: true
1119

20+
test-fail-command-1:
21+
name: test fail command 1
22+
runs-on: ubuntu-latest
23+
steps:
1224
- name: Checkout repository
1325
uses: actions/checkout@v3
1426
with:
1527
fetch-depth: 0
28+
- name: retry
29+
uses: ./
30+
with:
31+
command: false
32+
retries: 2
33+
pause: 1
34+
fail_command: |
35+
echo "This command has failed" \
36+
&& echo "Failed command concatenated"
37+
continue-on-error: true
1638

39+
test-fail-command-2:
40+
name: test fail command 2
41+
runs-on: ubuntu-latest
42+
steps:
43+
- name: Checkout repository
44+
uses: actions/checkout@v3
45+
with:
46+
fetch-depth: 0
1747
- name: retry
1848
uses: ./
1949
with:
20-
command: true
50+
command: false
51+
retries: 2
52+
pause: 1
53+
fail_command: |
54+
sudo sysctl -w net.ipv4.ip_forward=1 \
55+
&& sudo systemctl restart docker
56+
continue-on-error: true

README.md

+13-6
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ This action allows you to retry shell command for a few times in case they fail.
1212

1313
The following inputs can be used to alter the Docker tag name determination:
1414

15-
| Input | Required | Default | Description |
16-
|-----------|----------|----------|-------------------------------------------|
17-
| `retries` | No | `10` | How many times to retry on failure. |
18-
| `pause` | No | `10` | How many seconds to wait between retries. |
19-
| `command` | Yes | `` | Shell command to execute |
20-
| `workdir` | No | `` | Switch to this working directory prior executing the shell command |
15+
| Input | Required | Default | Description |
16+
|----------------|----------|----------|-------------------------------------------|
17+
| `retries` | No | `10` | How many times to retry on failure. |
18+
| `pause` | No | `10` | How many seconds to wait between retries. |
19+
| `command` | Yes | `` | Shell command to execute. |
20+
| `workdir` | No | `` | Switch to this working directory prior executing the shell command. |
21+
| `fail_command` | No | `` | Shell command to execute on every failure of given `command`. |
2122

2223

2324
## :arrow_backward: Outputs
@@ -48,6 +49,12 @@ jobs:
4849
pause: 10
4950
command: |
5051
docker build -t test .
52+
# Builing docker sometimes fails on GH Action runner due to network issues.
53+
# We ensure that forwarding is reenabled and the daemon is restarted
54+
# Before retrying the docker build command
55+
fail_command: |
56+
sudo sysctl -w net.ipv4.ip_forward=1 \
57+
&& sudo systemctl restart docker \
5158
```
5259
5360

action.yml

+10
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ inputs:
1919
description: 'Shell command to execute'
2020
required: true
2121
default: 'true'
22+
fail_command:
23+
description: 'Shell command to execute on every failure of given command (The fail_command will always succeed via: || true)'
24+
required: false
25+
default: ''
2226
workdir:
2327
description: 'Switch to this working directory prior executing shell command'
2428
required: false
@@ -37,6 +41,11 @@ runs:
3741
echo "[SUCC] ${n}/${RETRIES}";
3842
return 0;
3943
fi;
44+
if [ -n "${FAIL_COMMAND}" ]; then
45+
echo "Executing fail command:";
46+
echo "${FAIL_COMMAND}";
47+
eval "${FAIL_COMMAND}" || true;
48+
fi;
4049
sleep ${PAUSE};
4150
echo "[FAIL] ${n}/${RETRIES}";
4251
done;
@@ -51,3 +60,4 @@ runs:
5160
PAUSE: ${{ inputs.pause }}
5261
COMMAND: ${{ inputs.command }}
5362
WORKDIR: ${{ inputs.workdir }}
63+
FAIL_COMMAND: ${{ inputs.fail_command }}

0 commit comments

Comments
 (0)