Skip to content

Commit a3d250e

Browse files
authored
feat: on fail action (#10)
1 parent 6cbb4a7 commit a3d250e

File tree

5 files changed

+16
-3
lines changed

5 files changed

+16
-3
lines changed

.github/actions/action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ inputs:
1212
attempts:
1313
description: "Max attempts"
1414
required: true
15+
on-fail:
16+
description: "Execute bash command on fail"
17+
required: false
1518
runs:
1619
using: "docker"
1720
image: "Dockerfile"

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ jobs:
1919
uses: ./
2020
with:
2121
url: www.google.com
22-
attempts: 3
22+
attempts: 3
23+
on-fail: "echo 'ping failed'"

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ Simple ping action / script using curl.
66

77
```sh
88
chmod +x ./ping.sh
9-
./ping.sh www.google.com 10
9+
./ping.sh www.google.com 10 "echo 'ping failed'"
1010
```
1111

1212
## Docker
1313

1414
```sh
1515
docker build -t ping .
16-
docker run ping www.google.com 10
16+
docker run ping www.google.com 10 "echo 'ping failed'"
1717
```
1818

1919
## GitHub Action
@@ -28,4 +28,5 @@ jobs:
2828
with:
2929
url: wwww.google.com
3030
attempts: 10
31+
on-fail: "echo 'ping failed'"
3132
```

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ inputs:
1212
attempts:
1313
description: "Max attempts"
1414
required: true
15+
on-fail:
16+
description: "Execute bash command on fail"
17+
required: false
1518
runs:
1619
using: "docker"
1720
image: "docker://ghcr.io/matiasg19/ping:latest"

ping.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ url=$1
66
url="${url//localhost/$hostip}"
77
attempts=$2
88
attempt=1
9+
onfail=$3
910

1011
while [ $attempt -le "$attempts" ]; do
1112
if curl -X GET "$url"; then
@@ -22,4 +23,8 @@ done
2223

2324
echo
2425
echo "Could not reach $url after $attempts attempts."
26+
if [ -z "$onfail" ]; then
27+
exit 1
28+
fi
29+
bash -c "$onfail"
2530
exit 1

0 commit comments

Comments
 (0)