forked from uraimo/run-on-arch-action
-
Notifications
You must be signed in to change notification settings - Fork 2
270 lines (224 loc) · 9.26 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
name: Unit Tests
on: [push, pull_request]
jobs:
testactions_job:
runs-on: ubuntu-latest
name: Test
strategy:
matrix:
include:
# The full matrix of Dockerfiles would be extensive, so just
# cover each arch and OS at least once.
- arch: aarch64
distro: archarm_latest
- arch: aarch64
distro: fedora_latest
- arch: ppc64le
distro: alpine_latest
- arch: armv6
distro: buster
- arch: armv7
distro: jessie
- arch: riscv64
distro: alpine_edge
- arch: riscv64
distro: ubuntu20.04
- arch: s390x
distro: stretch
- arch: armv7
distro: fedora_latest
- arch: armv7
distro: ubuntu18.04
- arch: aarch64
distro: bullseye
# Run tests that only need to be run on one matrix node
run_extra_tests: true
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Build and run container
id: build
uses: ./
with:
githubToken: ${{ github.token }}
arch: ${{ matrix.arch }}
distro: ${{ matrix.distro }}
env: |
env_arch: ${{ matrix.arch }}
env_distro: ${{ matrix.distro }}
# Test multiple argument formats
dockerRunArgs: |
-v "${PWD}/volume_1:/volume_1"
--volume=${PWD}/volume_2:/volume_2
"-v${PWD}/volume_3:/volume_3"
-v "${PWD}/volume_4:/volume_4" -v "${PWD}/volume_5:/volume_5"
# Sourced on host, after container build, before container run
setup: |
distro_info=$(cat /etc/*-release | tr '[:upper:]' '[:lower:]' | tr '"' ' ' | tr '\n' ' ')
echo ::set-output name=host_arch::"$(uname -m)"
echo ::set-output name=host_distro_info::"$distro_info"
echo ::set-output name=host_env_arch::"$env_arch"
echo ::set-output name=host_env_distro::"$env_distro"
echo ::set-output name=host_shell_options::"$-"
# Setup volumes
mkdir "${PWD}/volume_1"
touch "${PWD}/volume_1/file_1"
mkdir "${PWD}/volume_2"
touch "${PWD}/volume_2/file_2"
mkdir "${PWD}/volume_3"
touch "${PWD}/volume_3/file_3"
mkdir "${PWD}/volume_4"
touch "${PWD}/volume_4/file_4"
mkdir "${PWD}/volume_5"
touch "${PWD}/volume_5/file_5"
# Install some dependencies in the container, to be cached in a docker
# image layer.
install: |
case "${{ matrix.distro }}" in
ubuntu*|jessie|stretch|buster|bullseye)
apt-get update -q -y --force-yes
apt-get install -q -y --force-yes git
;;
fedora*)
dnf -y update
dnf -y install git which
;;
alpine*)
apk update
apk add git
;;
archarm*)
pacman -Syyu --noconfirm
pacman -S git which --noconfirm
ln -s /usr/lib/os-release /etc/os-release
;;
esac
# Run on container
run: |
distro_info=$(cat /etc/*-release | tr '[:upper:]' '[:lower:]' | sed 's/"//g' | tr '\n' ';')
echo ::set-output name=arch::"$(uname -m)"
echo ::set-output name=distro_info::"$distro_info"
echo ::set-output name=shebang::"$(head -n 1 "$0")"
echo ::set-output name=env_arch::"$env_arch"
echo ::set-output name=env_distro::"$env_distro"
echo ::set-output name=volume_1_ls::"$(ls /volume_1 || true)"
echo ::set-output name=volume_2_ls::"$(ls /volume_2 || true)"
echo ::set-output name=volume_3_ls::"$(ls /volume_3 || true)"
echo ::set-output name=volume_4_ls::"$(ls /volume_4 || true)"
echo ::set-output name=volume_5_ls::"$(ls /volume_5 || true)"
echo ::set-output name=git_path::"$(which git)"
echo ::set-output name=shell_options::"$-"
- name: Assert setup script runs on host (check arch info)
run: |
arch="${{ steps.build.outputs.host_arch }}"
echo "Assert host_arch: '$arch' == 'x86_64'"
test "$arch" == "x86_64"
- name: Assert setup script runs on host (check distro info)
run: |
distro_info="${{ steps.build.outputs.host_distro_info }}"
echo "Assert distro: 'ubuntu' in '$distro_info'"
[[ "$distro_info" == *"$distro_key"* ]] || exit 1
- name: Assert setup script receives environment variables
run: |
arch="${{ steps.build.outputs.host_env_arch }}"
distro="${{ steps.build.outputs.host_env_distro }}"
echo "Assert env_arch: '$arch' == '${{ matrix.arch }}'"
test "$arch" == "${{ matrix.arch }}"
echo "Assert env_distro: '$distro' == '${{ matrix.distro }}'"
test "$distro" == "${{ matrix.distro }}"
- name: Assert install script runs
run: |
git_path="${{ steps.build.outputs.git_path }}"
case "${{ matrix.distro }}" in
archarm*) expected_git_path="/usr/sbin/git" ;;
*) expected_git_path="/usr/bin/git" ;;
esac
echo "Assert git path: '$git_path' == '$expected_git_path'"
test "$git_path" == "$expected_git_path"
- name: Assert job would fail on setup script error
run: |
# The `setup:` script should have `set -eu`, otherwise failures
# in the script won't propagate as job failures.
shell_options="${{ steps.build.outputs.host_shell_options }}"
echo "Assert bash options: 'e' and 'u' in '$shell_options'"
[[ "$shell_options" == *e* && "$shell_options" == *u* ]] || exit 1
- name: Assert container runs on arch
run: |
arch="${{ steps.build.outputs.arch }}"
case "${{ matrix.arch }}" in
armv6) expected_arch="armv6l" ;;
armv7) expected_arch="armv7l" ;;
*) expected_arch="${{ matrix.arch }}" ;;
esac
echo "Assert arch: '$arch' == '$expected_arch'"
test "$arch" == "$expected_arch"
- name: Assert container uses distro
run: |
distro_info="${{ steps.build.outputs.distro_info }}"
case "${{ matrix.distro }}" in
alpine*) distro_key="alpine" ;;
ubuntu*) distro_key="ubuntu" ;;
fedora*) distro_key="fedora" ;;
archarm*) distro_key="archarm" ;;
*) distro_key="${{ matrix.distro }}" ;;
esac
echo "Assert distro: '$distro_key' in '$distro_info'"
[[ "$distro_info" == *"$distro_key"* ]] || exit 1
- name: Assert container receives environment variables
run: |
arch="${{ steps.build.outputs.env_arch }}"
distro="${{ steps.build.outputs.env_distro }}"
echo "Assert env_arch: '$arch' == '${{ matrix.arch }}'"
test "$arch" == "${{ matrix.arch }}"
echo "Assert env_distro: '$distro' == '${{ matrix.distro }}'"
test "$distro" == "${{ matrix.distro }}"
- name: Assert job would fail on run script error
run: |
# The `run:` script should have `set -ue`, otherwise failures
# in the script won't propagate as job failures.
shell_options="${{ steps.build.outputs.shell_options }}"
echo "Assert bash options: 'e' and 'u' in '$shell_options'"
[[ "$shell_options" == *e* && "$shell_options" == *u* ]] || exit 1
- name: Assert dockerRunArgs are used
run: |
volume_1_ls="${{ steps.build.outputs.volume_1_ls }}"
volume_2_ls="${{ steps.build.outputs.volume_2_ls }}"
volume_3_ls="${{ steps.build.outputs.volume_3_ls }}"
volume_4_ls="${{ steps.build.outputs.volume_4_ls }}"
volume_5_ls="${{ steps.build.outputs.volume_5_ls }}"
echo "Assert volume_1_ls: '$volume_1_ls' == 'file_1'"
test "$volume_1_ls" == "file_1"
echo "Assert volume_2_ls: '$volume_2_ls' == 'file_2'"
test "$volume_2_ls" == "file_2"
echo "Assert volume_3_ls: '$volume_3_ls' == 'file_3'"
test "$volume_3_ls" == "file_3"
echo "Assert volume_4_ls: '$volume_4_ls' == 'file_4'"
test "$volume_4_ls" == "file_4"
echo "Assert volume_5_ls: '$volume_5_ls' == 'file_5'"
test "$volume_5_ls" == "file_5"
- name: Assert container determines correct default shell for distro
run: |
shebang="${{ steps.build.outputs.shebang }}"
case "${{ matrix.distro }}" in
alpine*) expected_shebang="#!/bin/sh" ;;
*) expected_shebang="#!/bin/bash" ;;
esac
echo "Assert shebang: '$shebang' == '$expected_shebang'"
test "$shebang" == "$expected_shebang"
- name: Build and run other container (custom shell, no githubToken)
if: ${{ matrix.run_extra_tests }}
id: build_custom_shell
uses: ./
with:
arch: ${{ matrix.arch }}
distro: ${{ matrix.distro }}
shell: /bin/dash
run: |
# Run on container
echo ::set-output name=shebang::$(head -n 1 "$0")
- name: Assert container uses custom shell
if: ${{ matrix.run_extra_tests }}
run: |
shebang="${{ steps.build_custom_shell.outputs.shebang }}"
echo "Assert shebang: '$shebang' == '#!/bin/dash'"
test "$shebang" == "#!/bin/dash"