#
# https://docs.github.com/en/actions
# https://github.com/actions
#
# https://formulae.brew.sh/
# https://packages.msys2.org/
#

name: CI

on:
  pull_request: {}
  push: {}

jobs:

  lint:
    name: "Lint - ${{matrix.pick.OS}} / Python ${{matrix.pick.PY}}"
    runs-on: ${{matrix.pick.OS}}
    strategy:
      matrix:
        pick:
          - {OS: "ubuntu-latest", PY: "3.10", TOXENV: "lint,docs"}
    steps:
      - name: "Checkout"
        uses: actions/checkout@v4

      - name: "Setup Python ${{matrix.pick.PY}}"
        uses: actions/setup-python@v5
        with:
          python-version: ${{matrix.pick.PY}}

      - name: "Install build tools"
        run: python -m pip install -r etc/requirements.build.txt --disable-pip-version-check

      - name: "Run tox - ${{matrix.pick.TOXENV}}"
        env:
          TOXENV: ${{matrix.pick.TOXENV}}
        run: |
          python -m tox -r -- --color=yes

  test:
    name: "Test - ${{matrix.pick.OS}} / ${{matrix.pick.PYNAME}}"
    runs-on: ${{matrix.pick.OS}}
    strategy:
      matrix:
        pick:
          - {OS: "ubuntu-latest", PY: "3.8", PYNAME: "Python 3.8", TOXENV: "py38"}
          - {OS: "ubuntu-latest", PY: "3.9", PYNAME: "Python 3.9", TOXENV: "py39-pycryptodome"}
          - {OS: "ubuntu-latest", PY: "3.10", PYNAME: "Python 3.10", TOXENV: "py310-cryptography"}
          - {OS: "ubuntu-latest", PY: "3.11", PYNAME: "Python 3.11", TOXENV: "py311-cryptography"}
          - {OS: "ubuntu-latest", PY: "3.12", PYNAME: "Python 3.12", TOXENV: "py312-cryptography"}
          - {OS: "ubuntu-latest", PY: "pypy3.9", PYNAME: "PyPy3.9", TOXENV: "pypy39-cryptography"}
          - {OS: "ubuntu-latest", PY: "pypy3.10", PYNAME: "PyPy3.10", TOXENV: "pypy310-cryptography"}
          - {OS: "macos-latest", PY: "3.9", PYNAME: "Python 3.9", TOXENV: "py39-pycryptodome"}
          - {OS: "macos-latest", PY: "3.10", PYNAME: "Python 3.10", TOXENV: "py310-cryptography"}
          - {OS: "windows-latest", PY: "3.9", PYNAME: "Python 3.9", TOXENV: "py39-cryptography" }
          - {OS: "windows-latest", PY: "3.10", PYNAME: "Python 3.10", TOXENV: "py310-cryptography" }
    steps:
      - name: "Checkout"
        uses: actions/checkout@v4

      - name: "Setup ${{matrix.pick.PYNAME}}"
        uses: actions/setup-python@v5
        with:
          python-version: ${{matrix.pick.PY}}

      - name: "Install archivers (linux)"
        if: ${{runner.os == 'Linux'}}
        run: |
          sudo -nH apt-get -qqy install unrar unar libarchive-tools p7zip-rar
          unrar
          unar -h
          bsdtar -h
          7z i

      - name: "Install archivers (macos)"
        if: ${{runner.os == 'macOS'}}
        run: |
          brew install rar unar libarchive sevenzip
          unrar
          unar -h
          bsdtar -h
          7z i
          7zz i

      - name: "Install archivers (windows)"
        if: ${{runner.os == 'Windows'}}
        shell: cmd
        run: |
          set "PATH=c:\msys64\usr\bin;%PATH%"
          pacman -S --noconfirm --needed bsdtar p7zip
          curl -sS -o unrarw64.exe https://www.rarlab.com/rar/unrarw64.exe
          7z x unrarw64.exe
          unrar
          bsdtar -h
          7z i

      - name: "Install tools"
        run: python -m pip install -r etc/requirements.build.txt --disable-pip-version-check

      - name: "Run tox - ${{matrix.pick.TOXENV}} - (linux/macos)"
        if: ${{runner.os == 'Linux' || runner.os == 'macOS'}}
        env:
          TOXENV: ${{matrix.pick.TOXENV}}
        run: |
          python -m tox -r -- --color=yes -n auto -v

      - name: "Run tox - ${{matrix.pick.TOXENV}} - (windows)"
        if: ${{runner.os == 'Windows'}}
        env:
          TOXENV: ${{matrix.pick.TOXENV}}
        shell: cmd
        run: |
          set "PATH=%PATH%;c:\msys64\usr\bin"
          python -m tox -r -- --color=yes -n auto -v

