Skip to content

Commit e7a9a2b

Browse files
authored
Merge pull request #7 from addnab/tests
tests: setup tests
2 parents 6f0804d + 8279676 commit e7a9a2b

File tree

3 files changed

+78
-3
lines changed

3 files changed

+78
-3
lines changed

.github/workflows/tests.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Docker Run Action Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
smoke-test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
- name: Run docker action and set output for testing
15+
uses: ./
16+
id: run-docker
17+
with:
18+
image: docker:20.10.3
19+
run: |
20+
echo "::set-output name=docker-version::`echo $DOCKER_VERSION`"
21+
- name: Test the output
22+
uses: actions/github-script@v3
23+
with:
24+
script: |
25+
const dockerVersion = '${{ steps.run-docker.outputs.docker-version }}';
26+
if (dockerVersion !== '20.10.3') {
27+
core.setFailed(`Smoke Test Failed`);
28+
}
29+
volume-mount-test:
30+
runs-on: ubuntu-latest
31+
steps:
32+
- uses: actions/checkout@v2
33+
- name: Create File to be mounted
34+
run: echo "some text" > someFile
35+
- name: Run docker action with mounted workspace
36+
uses: ./
37+
id: run-docker
38+
with:
39+
image: docker
40+
options: -v ${{ github.workspace }}:/work
41+
run: |
42+
echo "::set-output name=file-contents::`cat /work/someFile`"
43+
- name: Check if file contents match
44+
uses: actions/github-script@v3
45+
with:
46+
script: |
47+
const fileContents = '${{ steps.run-docker.outputs.file-contents }}';
48+
if (fileContents !== 'some text') {
49+
core.setFailed(`Unable to mount workspace volume`);
50+
}
51+
container-network-test:
52+
runs-on: ubuntu-latest
53+
services:
54+
postgres:
55+
image: postgres
56+
env:
57+
POSTGRES_PASSWORD: test
58+
POSTGRES_USER: test
59+
POSTGRES_DB: test
60+
ports:
61+
- 5432:5432
62+
options: --health-cmd pg_isready --health-interval 5s --health-timeout 5s --health-retries 10
63+
steps:
64+
- uses: actions/checkout@v2
65+
- name: Run docker action and test network connection
66+
uses: ./
67+
with:
68+
image: postgres
69+
run: >
70+
pg_isready -d test -U test -h postgres -p ${{ job.services.postgres.ports[5432] }}
71+
options: >
72+
-e PGPASSWORD=test

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# Docker Run Action
22

3-
- run a privately-owned image.
4-
- run an image built by a previous step.
53
- run a specific step in docker.
4+
- run an image built by a previous step.
65
- See https://github.com/addnab/docker-run-action/blob/main/action.yml for all the available inputs.
76

87
#### Typical Use Case

entrypoint.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@ fi
66

77
echo "$INPUT_RUN" | sed -e 's/\\n/;/g' > semicolon_delimited_script
88

9-
exec docker run -v "/var/run/docker.sock":"/var/run/docker.sock" --network=$INPUT_DOCKER_NETWORK $INPUT_OPTIONS --entrypoint=$INPUT_SHELL $INPUT_IMAGE -c "`cat semicolon_delimited_script`"
9+
if [ ! -z $INPUT_DOCKER_NETWORK ];
10+
then INPUT_OPTIONS="$INPUT_OPTIONS --network $INPUT_DOCKER_NETWORK"
11+
fi
12+
13+
exec docker run -v "/var/run/docker.sock":"/var/run/docker.sock" $INPUT_OPTIONS --entrypoint=$INPUT_SHELL $INPUT_IMAGE -c "`cat semicolon_delimited_script`"

0 commit comments

Comments
 (0)