Skip to content

Commit 7cc5f83

Browse files
committed
Convert to Github Action
1 parent 81b1373 commit 7cc5f83

File tree

4 files changed

+85
-66
lines changed

4 files changed

+85
-66
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
on:
2+
pull_request:
3+
branches:
4+
- main
5+
6+
jobs:
7+
wait_for_it:
8+
runs-on: ubuntu-latest
9+
name: Ensure action works
10+
steps:
11+
- name: Start local server on port 80
12+
run: python -m SimpleHTTPServer 80
13+
- name: Start local server on port 3000
14+
run: python -m SimpleHTTPServer 80
15+
- name: Defaults
16+
uses: actions/wait-for-it@v1
17+
with:
18+
host: localhost
19+
- name: Non-default port
20+
uses: actions/wait-for-it@v1
21+
with:
22+
host: localhost
23+
port: 3000

Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Container image that runs your code
2+
FROM alpine:3.15
3+
4+
# Copies your code file from your action repository to the filesystem path `/` of the container
5+
COPY wait-for-it.sh /wait-for-it.sh
6+
7+
# Code file to execute when the docker container starts up (`entrypoint.sh`)
8+
ENTRYPOINT ["/wait-for-it.sh"]

README.md

Lines changed: 19 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,28 @@
1-
# wait-for-it
1+
# wait-for-it.sh Github Action
22

3-
`wait-for-it.sh` is a pure bash script that will wait on the availability of a
4-
host and TCP port. It is useful for synchronizing the spin-up of
5-
interdependent services, such as linked docker containers. Since it is a pure
6-
bash script, it does not have any external dependencies.
7-
8-
## Usage
3+
`wait-for-it.sh` is a pure bash script to wait on the availability of a host and TCP port.
94

10-
```text
11-
wait-for-it.sh host:port [-s] [-t timeout] [-- command args]
12-
-h HOST | --host=HOST Host or IP under test
13-
-p PORT | --port=PORT TCP port under test
14-
Alternatively, you specify the host and port as host:port
15-
-s | --strict Only execute subcommand if the test succeeds
16-
-q | --quiet Don't output any status messages
17-
-t TIMEOUT | --timeout=TIMEOUT
18-
Timeout in seconds, zero for no timeout
19-
-- COMMAND ARGS Execute command with args after the test finishes
20-
```
21-
22-
## Examples
5+
Since it is a pure
6+
bash script, it does not have any external dependencies.
237

24-
For example, let's test to see if we can access port 80 on `www.google.com`,
25-
and if it is available, echo the message `google is up`.
8+
This Github Action is based on a fork of the original [wait-for-it.sh](https://github.com/vishnubob/wait-for-it), and simply adds the `Dockerfile` and `action.yaml` needed to configure the shell script for use.
269

27-
```text
28-
$ ./wait-for-it.sh www.google.com:80 -- echo "google is up"
29-
wait-for-it.sh: waiting 15 seconds for www.google.com:80
30-
wait-for-it.sh: www.google.com:80 is available after 0 seconds
31-
google is up
10+
## Usage
3211
```
33-
34-
You can set your own timeout with the `-t` or `--timeout=` option. Setting
35-
the timeout value to 0 will disable the timeout:
36-
37-
```text
38-
$ ./wait-for-it.sh -t 0 www.google.com:80 -- echo "google is up"
39-
wait-for-it.sh: waiting for www.google.com:80 without a timeout
40-
wait-for-it.sh: www.google.com:80 is available after 0 seconds
41-
google is up
12+
- id: wait-for-it
13+
runs: elijahboston/wait-for-it
14+
with:
15+
host: localhost
16+
port: 80
17+
timeout: 60
18+
strict: false
19+
quiet: false
4220
```
4321

44-
The subcommand will be executed regardless if the service is up or not. If you
45-
wish to execute the subcommand only if the service is up, add the `--strict`
46-
argument. In this example, we will test port 81 on `www.google.com` which will
47-
fail:
48-
49-
```text
50-
$ ./wait-for-it.sh www.google.com:81 --timeout=1 --strict -- echo "google is up"
51-
wait-for-it.sh: waiting 1 seconds for www.google.com:81
52-
wait-for-it.sh: timeout occurred after waiting 1 seconds for www.google.com:81
53-
wait-for-it.sh: strict mode, refusing to execute subprocess
22+
Most parameters are optional, only the host is required:
5423
```
55-
56-
If you don't want to execute a subcommand, leave off the `--` argument. This
57-
way, you can test the exit condition of `wait-for-it.sh` in your own scripts,
58-
and determine how to proceed:
59-
60-
```text
61-
$ ./wait-for-it.sh www.google.com:80
62-
wait-for-it.sh: waiting 15 seconds for www.google.com:80
63-
wait-for-it.sh: www.google.com:80 is available after 0 seconds
64-
$ echo $?
65-
0
66-
$ ./wait-for-it.sh www.google.com:81
67-
wait-for-it.sh: waiting 15 seconds for www.google.com:81
68-
wait-for-it.sh: timeout occurred after waiting 15 seconds for www.google.com:81
69-
$ echo $?
70-
124
24+
- id: wait-for-it
25+
runs: elijahboston/wait-for-it
26+
with:
27+
host: localhost
7128
```
72-
73-
## Community
74-
75-
*Debian*: There is a [Debian package](https://tracker.debian.org/pkg/wait-for-it).

action.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: 'wait-for-it'
2+
description: 'Wait for a response'
3+
inputs:
4+
host:
5+
description: 'Host or IP under test'
6+
required: true
7+
port:
8+
description: 'TCP port under test, default: 80'
9+
required: false
10+
default: '80'
11+
strict:
12+
description: 'Only execute subcommand if the test succeeds'
13+
required: false
14+
default: 'false'
15+
timeout:
16+
description: 'Timeout in seconds, zero for no timeout'
17+
required: true
18+
default: '60'
19+
command:
20+
description: 'Execute command after the test has completed'
21+
required: false
22+
quiet:
23+
description: "Don't output any status messages"
24+
required: false
25+
default: 'false'
26+
runs:
27+
using: 'docker'
28+
image: 'Dockerfile'
29+
args:
30+
- --host ${{ inputs.host }}
31+
- --port ${{ inputs.port }}
32+
- --strict ${{ inputs.strict }}
33+
- --timeout ${{ inputs.timeout }}
34+
- --quiet ${{ inputs.quiet }}
35+
- -- ${{ inputs.command }}

0 commit comments

Comments
 (0)