-
Notifications
You must be signed in to change notification settings - Fork 0
182 lines (169 loc) · 6.23 KB
/
test.yml
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
name: All Tests
on: # rebuild any PRs and main branch changes
pull_request:
push:
branches:
- main
- 'releases/*'
jobs:
code-format:
name: Test code format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: |
npm install
- run: |
npm run all
test:
name: Test Functionality
runs-on: ubuntu-latest
services:
nginx:
image: nginxdemos/hello:plain-text
steps:
- uses: actions/checkout@v4
- name: Copy test.sh to executable path
run: |
mkdir -p ~/.local/bin
cp ./tests/test.sh ~/.local/bin/test.sh
- run: |
ls -la /home/runner/work/_temp/
ls -la /home/runner/work/_temp/_runner_file_commands/
- name: "Test: Run a command in a public image"
id: test-simple
uses: ./
with:
image: ubuntu:latest
run: |
echo "list temp: -----"
ls -la /tmp
echo "var output: [$GITHUB_OUTPUT]"
echo "ls of output: ----"
ls -la $GITHUB_OUTPUT
echo "success=true" >> $GITHUB_OUTPUT
- name: "Validate Test: Run a command in a public image"
run: test.sh equal "${{ steps.test-simple.outputs.success }}" "true"
- name: "Test: Setting Environment Files (env, output, summary, path)"
id: test-runner-env
uses: ./
with:
image: ubuntu:latest
run: |
echo "test_env=IsSet" >> "$GITHUB_ENV"
echo "test_path=/IsSet" >> "$GITHUB_PATH"
echo "test_output=IsSet" >> "$GITHUB_OUTPUT"
echo "test_state=IsSet" >> "$GITHUB_STATE"
echo "test_step_summary=IsSet" >> "$GITHUB_STEP_SUMMARY"
- name: "Validate Test: Run a command in a public image"
run: |
test.sh equal "$test_env" "IsSet"
test.sh contains "$PATH" "IsSet"
test.sh equal "${{ steps.test-runner-env.outputs.test_output }}" "IsSet"
test.sh equal "$STATE_test_state" "IsSet"
test.sh contains "$(echo $GITHUB_STEP_SUMMARY)" "IsSet"
- name: "Test: Multline script with defaults settings"
id: test-defaults
uses: ./
with:
image: ubuntu:latest
run: |
# prepare...
apt-get update && apt-get install -y iputils-ping
# check if the script is running in default "sh" (which is dash in ubuntu)
[ ! -z "${BASH_VERSION}" ] && echo "ERROR: Shell is not sh" && exit 1
# check if the default workdir ("/") is used
echo "Workdir is: ${PWD}"
[ "${PWD}" != "/" ] && echo "ERROR: Workdir is not /" && exit 1
# check if the container is attached to the local docker network:
ping -c 1 nginx
- name: "Test: Multiline run fails on error (should have error)"
continue-on-error: true
id: test-multiline-with-error
uses: ./
with:
image: ubuntu:latest
run: |
echo "start"
echo "beforeError=true" >> $GITHUB_OUTPUT
cat non-existing-file
echo "afterError=true" >> $GITHUB_OUTPUT
echo "end"
- name: "Validate Test: Multiline run fails on error"
run: |
test.sh equal "${{ steps.test-multiline-with-error.outputs.beforeError }}" "true"
test.sh empty "${{ steps.test-multiline-with-error.outputs.afterError }}"
- name: "Test: Shell input"
id: test-shell-input
uses: ./
with:
image: ubuntu:latest
shell: /bin/bash
run: echo "bash-version=${BASH_VERSION}" >> $GITHUB_OUTPUT
- name: "Validate Test: Shell input"
run: test.sh not-empty "${{ steps.test-shell-input.outputs.bash-version }}"
- name: "Test: Env input"
id: test-env-input
uses: ./
with:
image: ubuntu:latest
environment: |
GITHUB_JOB
CUSTOM_VAR=foo
run: |
echo "github-job=${GITHUB_JOB}" >> $GITHUB_OUTPUT
echo "custom-var=${CUSTOM_VAR}" >> $GITHUB_OUTPUT
- name: "Validate Test: Env input"
run: |
test.sh equal "${{ steps.test-env-input.outputs.github-job }}" "${GITHUB_JOB}"
test.sh equal "${{ steps.test-env-input.outputs.custom-var }}" "foo"
- name: "Test: Volume input"
id: test-volume-input
uses: ./
with:
image: ubuntu:latest
volumes: |
/home/runner/volume-test:/home-volume-test
${{ github.workspace }}:/workspace
run: |
echo "present" > /home-volume-test/file1
echo "present" > /workspace/file2
- name: "Validate Test: Volume input"
run: |
test.sh equal $(cat ~/volume-test/file1) "present"
test.sh equal $(cat ${GITHUB_WORKSPACE}/file2) "present"
- name: "Test: Workdir input"
id: test-workdir-input
uses: ./
with:
image: ubuntu:latest
workdir: "/var/mywork"
run: |
echo "present" > /var/mywork/test-file
echo "file-content=$(cat ./test-file)" >> $GITHUB_OUTPUT
- name: "Validate Test: Workdir input"
run: test.sh equal "${{ steps.test-workdir-input.outputs.file-content }}" "present"
- name: "Test: Options input"
id: test-options-input
uses: ./
with:
image: ubuntu:latest
options: |
--name=TestContainer
--label test
-e TEST_VAR=bar
run: echo "test-var=${TEST_VAR}" >> $GITHUB_OUTPUT
- name: "Validate Test: Options input"
run: test.sh equal "${{ steps.test-options-input.outputs.test-var }}" "bar"
- name: Authorize docker for private image
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: "Test: Can access private image after authorization"
id: test-private-image
uses: ./
with:
image: ghcr.io/${{ github.repository }}/private-image:latest
run: cat /var/mywork/private-image-test