Skip to content

Restore old dockerfiles for backward compatibility, will be removed i… #3

Restore old dockerfiles for backward compatibility, will be removed i…

Restore old dockerfiles for backward compatibility, will be removed i… #3

Workflow file for this run

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: armv6
distro: bullseye
- arch: armv7
distro: bullseye
- arch: aarch64
distro: bullseye
- arch: s390x
distro: bullseye
- arch: aarch64
distro: fedora_latest
- arch: riscv64
distro: alpine_edge
- arch: ppc64le
distro: alpine_latest
- arch: armv7
distro: ubuntu22.04
- arch: riscv64
distro: ubuntu22.04
# 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|bookworm)
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"