Skip to content

Commit 1ef259f

Browse files
authored
Add ability to pass options to shell parameter (fix #41) (#50)
1 parent 745e82d commit 1ef259f

3 files changed

Lines changed: 109 additions & 70 deletions

File tree

.github/workflows/test-shell.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
workflow_dispatch:
99

1010
jobs:
11-
build:
11+
build_ksh93:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- uses: actions/checkout@v2
@@ -19,3 +19,21 @@ jobs:
1919
exit_on_fail: false
2020
commands: |
2121
dpkg -l ksh | grep ^ii
22+
build_options_full_path:
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@v2
26+
- uses: ./ # pguyot/arm-runner-action@HEAD
27+
with:
28+
shell: /bin/bash -o pipefail
29+
commands: |
30+
[[ "$SHELLOPTS" =~ "pipefail" ]] || exit 1
31+
build_options_not_full_path:
32+
runs-on: ubuntu-latest
33+
steps:
34+
- uses: actions/checkout@v2
35+
- uses: ./ # pguyot/arm-runner-action@HEAD
36+
with:
37+
shell: bash -o pipefail
38+
commands: |
39+
[[ "$SHELLOPTS" =~ "pipefail" ]] || exit 1

README.md

Lines changed: 74 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,44 @@ This action works with both 32 bits (arm) and 64 bits (aarch64) images.
1717

1818
Minimal usage is as follows:
1919

20-
jobs:
21-
build:
22-
runs-on: ubuntu-latest
23-
steps:
24-
- uses: actions/checkout@v2
25-
- uses: pguyot/arm-runner-action@v2
26-
with:
27-
commands: |
28-
commands to run tests
20+
```yaml
21+
jobs:
22+
build:
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@v2
26+
- uses: pguyot/arm-runner-action@v2
27+
with:
28+
commands: |
29+
commands to run tests
30+
```
2931
3032
Typical usage to upload an image as an artifact:
3133
32-
jobs:
33-
build:
34-
runs-on: ubuntu-latest
35-
steps:
36-
- uses: actions/checkout@v2
37-
- uses: pguyot/arm-runner-action@v2
38-
id: build_image
39-
with:
40-
base_image: raspios_lite:2022-04-04
41-
commands: |
42-
commands to build image
43-
- name: Compress the release image
44-
if: github.ref == 'refs/heads/releng' || startsWith(github.ref, 'refs/tags/')
45-
run: |
46-
mv ${{ steps.build_image.outputs.image }} my-release-image.img
47-
xz -0 -T 0 -v my-release-image.img
48-
- name: Upload release image
49-
uses: actions/upload-artifact@v2
50-
if: github.ref == 'refs/heads/releng' || startsWith(github.ref, 'refs/tags/')
51-
with:
52-
name: Release image
53-
path: my-release-image.img.xz
34+
```yaml
35+
jobs:
36+
build:
37+
runs-on: ubuntu-latest
38+
steps:
39+
- uses: actions/checkout@v2
40+
- uses: pguyot/arm-runner-action@v2
41+
id: build_image
42+
with:
43+
base_image: raspios_lite:2022-04-04
44+
commands: |
45+
commands to build image
46+
- name: Compress the release image
47+
if: github.ref == 'refs/heads/releng' || startsWith(github.ref, 'refs/tags/')
48+
run: |
49+
mv ${{ steps.build_image.outputs.image }} my-release-image.img
50+
xz -0 -T 0 -v my-release-image.img
51+
- name: Upload release image
52+
uses: actions/upload-artifact@v2
53+
if: github.ref == 'refs/heads/releng' || startsWith(github.ref, 'refs/tags/')
54+
with:
55+
name: Release image
56+
path: my-release-image.img.xz
57+
```
5458
5559
Several scenarios are actually implemented as [tests](/.github/workflows).
5660
@@ -211,6 +215,11 @@ If missing, it will be installed. See `shell_package`.
211215
If defined as basename filename, it will be used as long as the shell binary
212216
exists under PATH after the package is installed.
213217

218+
The option include options, e.g.:
219+
```yaml
220+
shell: /bin/bash -eo pipefail
221+
```
222+
214223
#### `shell_package`
215224

216225
The shell package to install, if different from shell. It may be handy
@@ -222,7 +231,8 @@ For example, to use `ksh93` as shell, set `shell` to `ksh93` and
222231
#### `exit_on_fail`
223232

224233
Exit immediately if a command exits with a non-zero status. Default is to exit.
225-
Set to `no` or `false` to disable exiting on command failure.
234+
Set to `no` or `false` to disable exiting on command failure. This only works
235+
with `sh`, `bash` and `ksh` shells.
226236

227237
#### `debug`
228238

@@ -266,36 +276,38 @@ base image should match.
266276
The following matrix will build on armv6l, armv7l and aarch64 using the latest
267277
RaspberryPi OS images.
268278

269-
name: Test architecture matrix
270-
on: [push, pull_request, workflow_dispatch]
271-
jobs:
272-
build:
273-
runs-on: ubuntu-latest
274-
strategy:
275-
matrix:
276-
arch: [armv6l, armv7l, aarch64]
277-
include:
278-
- arch: armv6l
279-
cpu: arm1176
280-
base_image: raspios_lite:latest
281-
cpu_info: raspberrypi_zero_w
282-
- arch: armv7l
283-
cpu: cortex-a7
284-
base_image: raspios_lite:latest
285-
cpu_info: raspberrypi_3b
286-
- arch: aarch64
287-
cpu: cortex-a53
288-
base_image: raspios_lite_arm64:latest
289-
cpu_info: raspberrypi_zero2_w_arm64_w
290-
steps:
291-
- uses: pguyot/arm-runner-action@v2
292-
with:
293-
base_image: ${{ matrix.base_image }}
294-
cpu: ${{ matrix.cpu }}
295-
cpu_info: ${{ matrix.cpu_info }}
296-
commands: |
297-
test `uname -m` = ${{ matrix.arch }}
298-
grep Model /proc/cpuinfo
279+
```yaml
280+
name: Test architecture matrix
281+
on: [push, pull_request, workflow_dispatch]
282+
jobs:
283+
build:
284+
runs-on: ubuntu-latest
285+
strategy:
286+
matrix:
287+
arch: [armv6l, armv7l, aarch64]
288+
include:
289+
- arch: armv6l
290+
cpu: arm1176
291+
base_image: raspios_lite:latest
292+
cpu_info: raspberrypi_zero_w
293+
- arch: armv7l
294+
cpu: cortex-a7
295+
base_image: raspios_lite:latest
296+
cpu_info: raspberrypi_3b
297+
- arch: aarch64
298+
cpu: cortex-a53
299+
base_image: raspios_lite_arm64:latest
300+
cpu_info: raspberrypi_zero2_w_arm64_w
301+
steps:
302+
- uses: pguyot/arm-runner-action@v2
303+
with:
304+
base_image: ${{ matrix.base_image }}
305+
cpu: ${{ matrix.cpu }}
306+
cpu_info: ${{ matrix.cpu_info }}
307+
commands: |
308+
test `uname -m` = ${{ matrix.arch }}
309+
grep Model /proc/cpuinfo
310+
```
299311

300312
Internally, the `cpu` value is embedded in a wrapper for `qemu-arm-static` and
301313
`qemu-aarch64-static`. The actual qemu invoked depends on executables within

action.yml

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,13 @@ runs:
163163
exit_on_fail=''
164164
;;
165165
esac
166-
shell=${{ inputs.shell }}
166+
shell_with_opts="${{ inputs.shell }}"
167+
shell=${shell_with_opts%% *}
168+
if [ "${shell}" != "${shell_with_opts}" ]; then
169+
shell_opts=${shell_with_opts#* }
170+
else
171+
shell_opts=""
172+
fi
167173
shell_package=${{ inputs.shell_package }}
168174
[ -x ${{ steps.mount_image.outputs.mount }}/${shell} ] || \
169175
shell_path=$(sudo chroot ${{ steps.mount_image.outputs.mount }} which ${shell}) || \
@@ -195,10 +201,13 @@ runs:
195201
fi
196202
mkdir -p ${script_dir}
197203
script_path=${script_dir}/commands.sh
198-
sudo touch ${script_path}
199-
sudo chmod o+wx ${script_path}
200-
echo "#!${shell_path}" > ${script_path}
201-
echo "set -${debug}${exit_on_fail}" >> ${script_path}
204+
touch ${script_path}
205+
if [ "${debug}${exit_on_fail}" != "" ]; then
206+
shell_basename=`basename ${shell_path}`
207+
if [ "${shell_basename}" = "sh" -o "${shell_basename}" = "bash" -o "${shell_basename}" = "ksh" -o "${shell_package}" = "ksh" ]; then
208+
echo "set -${debug}${exit_on_fail}" >> ${script_path}
209+
fi
210+
fi
202211
case "${{ inputs.import_github_env }}" in
203212
yes|true)
204213
export | sed -e 's/^declare -x //g;s/^[^=]*$/\0=""/g;s/='\''\(.*\)'\''$/=\1/g' >> ${script_dir}/environment.sh
@@ -216,9 +225,9 @@ runs:
216225
ARM_RUNNER_INPUT_COMMANDS_EOF
217226
if [ "${{ inputs.use_systemd_nspawn }}x" != "x" -a "${{ inputs.use_systemd_nspawn }}x" != "nox" ]; then
218227
sudo apt-get install -y systemd-container
219-
sudo systemd-nspawn -q -a --bind=${script_dir}:${chroot_script_dir} -D ${{ steps.mount_image.outputs.mount }} ${shell_path} ${chroot_script_dir}/commands.sh
228+
sudo systemd-nspawn -q -a --bind=${script_dir}:${chroot_script_dir} -D ${{ steps.mount_image.outputs.mount }} ${shell_path} ${shell_opts} ${chroot_script_dir}/commands.sh
220229
else
221-
sudo chroot ${{ steps.mount_image.outputs.mount }} ${chroot_script_dir}/commands.sh
230+
sudo chroot ${{ steps.mount_image.outputs.mount }} ${shell_path} ${shell_opts} ${chroot_script_dir}/commands.sh
222231
fi
223232
rc=$?
224233
[ -f ${script_dir}/github_env.sh ] && \

0 commit comments

Comments
 (0)