Skip to content

Commit

Permalink
Add ability to pass options to shell parameter (fix #41) (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
pguyot authored Oct 8, 2022
1 parent 745e82d commit 1ef259f
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 70 deletions.
20 changes: 19 additions & 1 deletion .github/workflows/test-shell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
workflow_dispatch:

jobs:
build:
build_ksh93:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -19,3 +19,21 @@ jobs:
exit_on_fail: false
commands: |
dpkg -l ksh | grep ^ii
build_options_full_path:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./ # pguyot/arm-runner-action@HEAD
with:
shell: /bin/bash -o pipefail
commands: |
[[ "$SHELLOPTS" =~ "pipefail" ]] || exit 1
build_options_not_full_path:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./ # pguyot/arm-runner-action@HEAD
with:
shell: bash -o pipefail
commands: |
[[ "$SHELLOPTS" =~ "pipefail" ]] || exit 1
136 changes: 74 additions & 62 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,44 @@ This action works with both 32 bits (arm) and 64 bits (aarch64) images.

Minimal usage is as follows:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: pguyot/arm-runner-action@v2
with:
commands: |
commands to run tests
```yaml
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: pguyot/arm-runner-action@v2
with:
commands: |
commands to run tests
```
Typical usage to upload an image as an artifact:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: pguyot/arm-runner-action@v2
id: build_image
with:
base_image: raspios_lite:2022-04-04
commands: |
commands to build image
- name: Compress the release image
if: github.ref == 'refs/heads/releng' || startsWith(github.ref, 'refs/tags/')
run: |
mv ${{ steps.build_image.outputs.image }} my-release-image.img
xz -0 -T 0 -v my-release-image.img
- name: Upload release image
uses: actions/upload-artifact@v2
if: github.ref == 'refs/heads/releng' || startsWith(github.ref, 'refs/tags/')
with:
name: Release image
path: my-release-image.img.xz
```yaml
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: pguyot/arm-runner-action@v2
id: build_image
with:
base_image: raspios_lite:2022-04-04
commands: |
commands to build image
- name: Compress the release image
if: github.ref == 'refs/heads/releng' || startsWith(github.ref, 'refs/tags/')
run: |
mv ${{ steps.build_image.outputs.image }} my-release-image.img
xz -0 -T 0 -v my-release-image.img
- name: Upload release image
uses: actions/upload-artifact@v2
if: github.ref == 'refs/heads/releng' || startsWith(github.ref, 'refs/tags/')
with:
name: Release image
path: my-release-image.img.xz
```
Several scenarios are actually implemented as [tests](/.github/workflows).
Expand Down Expand Up @@ -211,6 +215,11 @@ If missing, it will be installed. See `shell_package`.
If defined as basename filename, it will be used as long as the shell binary
exists under PATH after the package is installed.

The option include options, e.g.:
```yaml
shell: /bin/bash -eo pipefail
```

#### `shell_package`

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

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

#### `debug`

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

name: Test architecture matrix
on: [push, pull_request, workflow_dispatch]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
arch: [armv6l, armv7l, aarch64]
include:
- arch: armv6l
cpu: arm1176
base_image: raspios_lite:latest
cpu_info: raspberrypi_zero_w
- arch: armv7l
cpu: cortex-a7
base_image: raspios_lite:latest
cpu_info: raspberrypi_3b
- arch: aarch64
cpu: cortex-a53
base_image: raspios_lite_arm64:latest
cpu_info: raspberrypi_zero2_w_arm64_w
steps:
- uses: pguyot/arm-runner-action@v2
with:
base_image: ${{ matrix.base_image }}
cpu: ${{ matrix.cpu }}
cpu_info: ${{ matrix.cpu_info }}
commands: |
test `uname -m` = ${{ matrix.arch }}
grep Model /proc/cpuinfo
```yaml
name: Test architecture matrix
on: [push, pull_request, workflow_dispatch]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
arch: [armv6l, armv7l, aarch64]
include:
- arch: armv6l
cpu: arm1176
base_image: raspios_lite:latest
cpu_info: raspberrypi_zero_w
- arch: armv7l
cpu: cortex-a7
base_image: raspios_lite:latest
cpu_info: raspberrypi_3b
- arch: aarch64
cpu: cortex-a53
base_image: raspios_lite_arm64:latest
cpu_info: raspberrypi_zero2_w_arm64_w
steps:
- uses: pguyot/arm-runner-action@v2
with:
base_image: ${{ matrix.base_image }}
cpu: ${{ matrix.cpu }}
cpu_info: ${{ matrix.cpu_info }}
commands: |
test `uname -m` = ${{ matrix.arch }}
grep Model /proc/cpuinfo
```

Internally, the `cpu` value is embedded in a wrapper for `qemu-arm-static` and
`qemu-aarch64-static`. The actual qemu invoked depends on executables within
Expand Down
23 changes: 16 additions & 7 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,13 @@ runs:
exit_on_fail=''
;;
esac
shell=${{ inputs.shell }}
shell_with_opts="${{ inputs.shell }}"
shell=${shell_with_opts%% *}
if [ "${shell}" != "${shell_with_opts}" ]; then
shell_opts=${shell_with_opts#* }
else
shell_opts=""
fi
shell_package=${{ inputs.shell_package }}
[ -x ${{ steps.mount_image.outputs.mount }}/${shell} ] || \
shell_path=$(sudo chroot ${{ steps.mount_image.outputs.mount }} which ${shell}) || \
Expand Down Expand Up @@ -195,10 +201,13 @@ runs:
fi
mkdir -p ${script_dir}
script_path=${script_dir}/commands.sh
sudo touch ${script_path}
sudo chmod o+wx ${script_path}
echo "#!${shell_path}" > ${script_path}
echo "set -${debug}${exit_on_fail}" >> ${script_path}
touch ${script_path}
if [ "${debug}${exit_on_fail}" != "" ]; then
shell_basename=`basename ${shell_path}`
if [ "${shell_basename}" = "sh" -o "${shell_basename}" = "bash" -o "${shell_basename}" = "ksh" -o "${shell_package}" = "ksh" ]; then
echo "set -${debug}${exit_on_fail}" >> ${script_path}
fi
fi
case "${{ inputs.import_github_env }}" in
yes|true)
export | sed -e 's/^declare -x //g;s/^[^=]*$/\0=""/g;s/='\''\(.*\)'\''$/=\1/g' >> ${script_dir}/environment.sh
Expand All @@ -216,9 +225,9 @@ runs:
ARM_RUNNER_INPUT_COMMANDS_EOF
if [ "${{ inputs.use_systemd_nspawn }}x" != "x" -a "${{ inputs.use_systemd_nspawn }}x" != "nox" ]; then
sudo apt-get install -y systemd-container
sudo systemd-nspawn -q -a --bind=${script_dir}:${chroot_script_dir} -D ${{ steps.mount_image.outputs.mount }} ${shell_path} ${chroot_script_dir}/commands.sh
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
else
sudo chroot ${{ steps.mount_image.outputs.mount }} ${chroot_script_dir}/commands.sh
sudo chroot ${{ steps.mount_image.outputs.mount }} ${shell_path} ${shell_opts} ${chroot_script_dir}/commands.sh
fi
rc=$?
[ -f ${script_dir}/github_env.sh ] && \
Expand Down

0 comments on commit 1ef259f

Please sign in to comment.