name: Test

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

jobs:
  test:
    name: Run tests
    strategy:
      matrix:
        # If changing how many times tests are run, must also change in codecov.yml
        # to ensure test coverage is reported only after all tests have finished
        include:
          - python-version: "3.6.7"
            os: "ubuntu-20.04"
          - python-version: "3.7.1"
            os: "ubuntu-20.04"
          - python-version: "3.8.0"
            os: "ubuntu-20.04"
          - python-version: "3.9.0"
            os: "ubuntu-20.04"
          - python-version: "3.10.0"
            os: "ubuntu-20.04"
          - python-version: "3.11.0"
            os: "ubuntu-20.04"
          - python-version: "3.12.0"
            os: "ubuntu-20.04"
          - python-version: "3.13.0-rc.2"
            os: "ubuntu-20.04"
    runs-on: ${{ matrix.os }}
    steps:
      - name: "Checkout"
        uses: "actions/checkout@v3"
      - uses: "actions/setup-python@v5"
        with:
          python-version: '${{ matrix.python-version }}'
      - name: "Install bsdcpio"
        run: |
          ./install-libarachive.sh
      - name: "Install 7z"
        run: |
          mkdir bin
          (
            cd ./bin
            wget https://www.7-zip.org/a/7z2301-linux-x64.tar.xz
            echo "23babcab045b78016e443f862363e4ab63c77d75bc715c0b3463f6134cbcf318 7z2301-linux-x64.tar.xz" | sha256sum --check
            tar -xJf ./7z2301-linux-x64.tar.xz 7zz
            rm 7z2301-linux-x64.tar.xz
            echo "$PWD" >> $GITHUB_PATH
          )
      - name: "Install python dependencies"
        run: |
          pip install ".[dev,ci]"
      - name: "Run type checking"
        run: |
          mypy stream_zip --strict
      - name: "Run tests"
        run: |
          pytest --cov
      - uses: codecov/codecov-action@v3
