name: unit-tests
on:
  push:
  pull_request:
  schedule:
  - cron: 0 4 * * MON,FRI
jobs:
  OS:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        scenario:
          - apt-docker.io/amd64/ubuntu:devel
          - apt-docker.io/amd64/ubuntu:latest
          - apt-docker.io/amd64/ubuntu:rolling
          - apt-docker.io/i386/debian:testing
          - apt-docker.io/amd64/debian:testing
          - dnf-registry.fedoraproject.org/fedora:latest
          - dnf-registry.fedoraproject.org/fedora:rawhide
          - dnf-quay.io/centos/centos:stream
          - alpine-alpine
          - alpine@gudev-alpine
          - nix-docker.io/nixos/nix
        include:
          - scenario: alpine@gudev-alpine
            env: EXTRA_PACKAGES=libgudev-dev

    timeout-minutes: 30
    steps:
      - name: Clone repository
        uses: actions/checkout@v2

      - name: Run unit tests
        run: |
          set -eux
          scenario=${{ matrix.scenario }}
          script=${scenario%-*}
          script=${script%@*}
          image=${scenario#*-}

          # HACK: i386 podman container fails apt signature verification
          [ "${image#%i386}" = "$image" ] || sudo dpkg -P podman
          # run as root; current Ubuntu podman breaks user networking ("could not find slirp4netns")
          # Fedora-on-Ubuntu has seccomp profile incompatibilities
          sudo ${{ matrix.env }} RUNC_OPTIONS=--security-opt=seccomp=unconfined tests/run-${script} $image
