name: CI

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  test:
    strategy:
      matrix:
        python-version: [
          "2.7",
          "3.5",
          "3.6",
          "3.7",
          "3.8",
          "3.9",
          "3.10",
          "3.11",
          "3.12",
          "3.13",
          "pypy-2.7",
          "pypy-3.8",
        ]
        os: [ubuntu-latest, windows-latest, macos-latest]
        exclude:
          - python-version: "2.7"
            os: "ubuntu-latest"
          - python-version: "2.7"
            os: "windows-latest"
          - python-version: "2.7"
            os: "macos-latest"
          - python-version: "3.5"
            os: "macos-latest"
          - python-version: "3.6"
            os: "macos-latest"
          - python-version: "3.7"
            os: "macos-latest"
          - python-version: "3.5"
            os: "ubuntu-latest"
          - python-version: "3.6"
            os: "ubuntu-latest"
        include:
          - python-version: "3.5"
            os: "macos-12"
          - python-version: "3.6"
            os: "macos-12"
          - python-version: "3.7"
            os: "macos-12"
          - python-version: "2.7"
            os: "ubuntu-20.04"
          - python-version: "3.5"
            os: "ubuntu-20.04"
          - python-version: "3.6"
            os: "ubuntu-20.04"
    runs-on: ${{ matrix.os }}
    env:
      TOXENV: py
    steps:
      - uses: actions/checkout@v3
      - if: ${{ matrix.python-version == '2.7' }}
        run: |
          sudo apt-get install python-is-python2
          curl -sSL https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py
          python get-pip.py
        name: Set up Python ${{ matrix.python-version }} on ${{ matrix.os }}
      - if: ${{ matrix.python-version != '2.7' }}
        name: Set up Python ${{ matrix.python-version }} on ${{ matrix.os }}
        uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python-version }}
          allow-prereleases: true
        env:
          PIP_TRUSTED_HOST: ${{ contains(fromJson('["3.5"]'), matrix.python-version) && 'pypi.python.org pypi.org files.pythonhosted.org' || '' }}
      - name: Install dependencies
        run: python -m pip install -U tox
      - name: Run tox
        run: python -m tox
