# yamllint disable rule:line-length
name: tox
on:  # yamllint disable-line rule:truthy
  - pull_request
  - push
env:
  TOX_LSR: "git+https://github.com/linux-system-roles/tox-lsr@2.13.1"
  LSR_ANSIBLE_TEST_DOCKER: "true"
  LSR_ANSIBLES: 'ansible==2.9.*'
  LSR_MSCENARIOS: default
  # LSR_EXTRA_PACKAGES: libdbus-1-dev
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
  python:
    strategy:
      matrix:
        pyver_os:
          - ver: '2.7'
            os: ubuntu-20.04
          - ver: '3.6'
            os: ubuntu-20.04
          - ver: '3.8'
            os: ubuntu-latest
          - ver: '3.9'
            os: ubuntu-latest
          - ver: '3.10'
            os: ubuntu-latest
          - ver: '3.11'
            os: ubuntu-latest
    runs-on: ${{ matrix.pyver_os.os }}
    steps:
      - name: checkout PR
        uses: actions/checkout@v3
      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.pyver_os.ver }}
      - name: Install platform dependencies, python, tox, tox-lsr
        run: |
          set -euxo pipefail
          python -m pip install --upgrade pip
          sudo apt-get update
          sudo apt-get install -y git
          pip install "$TOX_LSR"
          lsr_ci_preinstall
      - name: Run tox tests
        run: |
          set -euxo pipefail
          toxpyver=$(echo "${{ matrix.pyver_os.ver }}" | tr -d .)
          toxenvs="py${toxpyver}"
          case "$toxpyver" in
          27) toxenvs="${toxenvs},coveralls,flake8,pylint" ;;
          36) toxenvs="${toxenvs},coveralls,black,yamllint,shellcheck" ;;
          38) toxenvs="${toxenvs},coveralls,ansible-lint,ansible-plugin-scan,collection,ansible-test" ;;
          39) toxenvs="${toxenvs},coveralls,ansible-managed-var-comment" ;;
          310) toxenvs="${toxenvs},coveralls,check-meta-versions" ;;
          311) toxenvs="${toxenvs},coveralls" ;;
          esac
          TOXENV="$toxenvs" lsr_ci_runtox
