---
name: CI

on:
  pull_request:
    branches: [master]
  push:
    branches: [master]

jobs:
  unit-tests:
    name: "Python ${{ matrix.python-version }} ${{ matrix.tox-env }}"
    runs-on: ubuntu-22.04
    strategy:
      matrix:
        python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
        tox-env: [""]

    steps:
      - name: Step 1 - Checkout repository
        uses: actions/checkout@v4
      - name: Step 2 - Install python
        uses: actions/setup-python@v5
        with:
          python-version: "${{ matrix.python-version }}"
      - name: Step 3 - Do some caching for python packages
        uses: actions/cache@v4
        id: cache-python-packages
        with:
          path: ${{ env.pythonLocation }}
          key: ${{matrix.python-version}}-${{ hashFiles('requirements-tox.txt') }}-${{ env.pythonLocation }}
          restore-keys: |
            ${{matrix.python-version}}-${{ hashFiles('requirements-tox.txt') }}-
      - name: Step 3.5 - Install system deps for extras
        run: |
          sudo apt update && sudo apt-get install libsnappy-dev

          # azure-identity imports ctype, and the ctype version available in the
          # Ubuntu 22.04 runner is referencing libffi.so.7, which is not
          # available. This is a workaround to install the libffi7 package.
          sudo apt-get install libffi7
      - name: Step 4 - Install dependencies to run tox
        if: steps.cache-python-packages.outputs.cache-hit != 'true'
        run: |
          python -m pip install --upgrade pip setuptools wheel
          python -m pip install -r requirements-tox.txt
          python -m pip install --upgrade tox-gh-actions

      - name: Step 5 - Run tox targets for ${{ matrix.python-version }} ${{matrix.tox-env}}
        run: |
          if [[ -z "${{ matrix.tox-env }}" ]]
          then
            python -m tox
          else
            python -m tox -e ${{ matrix.tox-env }}
          fi
