name: tests
on:
  push:
  pull_request:
  schedule:
    - cron: 2 4 * * MON
jobs:
  OS:
    runs-on: ubuntu-latest
    permissions: {}
    strategy:
      fail-fast: false
      matrix:
        container:
          - docker.io/debian:stable
          - docker.io/debian:unstable
          - docker.io/ubuntu:devel
          - docker.io/ubuntu:rolling
          - docker.io/ubuntu:latest
          - registry.fedoraproject.org/fedora:rawhide
          - quay.io/centos/centos:stream8
          - quay.io/centos/centos:stream9

    container:
      image: ${{ matrix.container }}

    timeout-minutes: 10
    steps:
      - name: Clone repository
        uses: actions/checkout@v3

      - name: Install build and test dependencies
        run: |
          if type apt >/dev/null 2>&1; then
              apt-get update
              DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
                  flit \
                  libsystemd0 \
                  python3-dbusmock \
                  python3-pytest \
                  python3-pytest-cov \
                  tox
          elif grep -q platform:el /etc/os-release; then
              dnf install -y \
                  python3-pip \
                  python3-dbus \
                  dbus-daemon \
                  systemd-libs
              pip3 install \
                  flit \
                  pytest \
                  pytest-cov \
                  python-dbusmock \
                  tox
          else
              dnf install -y \
                  python3-dbusmock \
                  python3-flit \
                  python3-pytest \
                  python3-pytest-cov \
                  systemd-libs \
                  tox
          fi

      - name: Run unit tests
        run: tox -e pytest -- -vv --cov

  arch:
    runs-on: ubuntu-latest
    permissions: {}
    strategy:
      fail-fast: false
      matrix:
        arch:
          # 32 bit
          - armv7
          # big-endian
          - s390x

    timeout-minutes: 10
    steps:
      - name: Clone repository
        uses: actions/checkout@v3

      - name: Run unit tests
        uses: uraimo/run-on-arch-action@v2
        with:
          distro: ubuntu_latest
          arch: ${{ matrix.arch }}
          install: |
            apt-get update
            DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
                flit \
                libsystemd0 \
                python3-dbusmock \
                python3-pytest-cov \
                tox
          run: tox -e pytest -- -vv --cov

  venv:
    runs-on: ubuntu-latest
    permissions: {}
    container:
      image: registry.fedoraproject.org/fedora:38
    timeout-minutes: 10
    steps:
      - name: Install system dependencies
        run: sudo dnf install -y dbus-daemon dbus-devel gcc glib2-devel tox

      - name: Clone repository
        uses: actions/checkout@v3

      - name: Run unit tests
        run: tox -e py36-pytest,py37-pytest,py38-pytest,py39-pytest,py310-pytest,py311-pytest,py312-pytest

  lint:
    runs-on: ubuntu-latest
    permissions: {}
    steps:
      - name: Set up Python 3.11
        uses: actions/setup-python@v4
        with:
          python-version: 3.11

      - name: Install system dependencies
        run: sudo apt install libdbus-1-dev

      - name: Install tox
        run: sudo apt-get install -y tox

      - name: Clone repository
        uses: actions/checkout@v3

      - name: Run code checks
        run: tox -e py311-mypy,py311-pycodestyle,py311-ruff
