name: Test

on:
  push:
    branches:
    - main

  pull_request:
    branches:
    - main

jobs:
  test:
    runs-on: macos-latest
    strategy:
      matrix:
        python-version: ["3.13", "3.14"]

    steps:
    - uses: actions/checkout@v6

    - name: Set up Python
      uses: actions/setup-python@v6
      with:
        python-version: ${{ matrix.python-version }}
        cache: pip

    - name: Install Python dependencies
      run: pip install -r dev_requirements.txt

    - name: Install create_thumbnail
      env:
        GH_TOKEN: ${{ github.token }}
      run: |
        gh release download \
          --repo alexwlchan/create_thumbnail \
          --pattern create_thumbnail-aarch64-apple-darwin.tar.gz \
          --output create_thumbnail.tar.gz
        tar -xzf create_thumbnail.tar.gz --directory /usr/local/bin
        chmod +x /usr/local/bin/create_thumbnail
        which create_thumbnail

    - name: Install dominant_colours
      env:
        GH_TOKEN: ${{ github.token }}
      run: |
        gh release download \
          --repo alexwlchan/dominant_colours \
          --pattern dominant_colours-aarch64-apple-darwin.tar.gz \
          --output dominant_colours.tar.gz
        tar -xzf dominant_colours.tar.gz --directory /usr/local/bin
        chmod +x /usr/local/bin/dominant_colours
        which dominant_colours

    - name: Install get_live_text
      env:
        GH_TOKEN: ${{ github.token }}
      run: |
        gh release download \
          --repo alexwlchan/get_live_text \
          --pattern get_live_text.aarch64-apple-darwin.zip \
          --output get_live_text.tar.gz
        tar -xzf get_live_text.tar.gz --directory /usr/local/bin
        chmod +x /usr/local/bin/get_live_text
        which get_live_text

    - name: Install ffprobe
      run: |
        curl --location -O https://evermeet.cx/ffmpeg/ffprobe-8.0.1.7z
        tar -xzf ffprobe-8.0.1.7z --directory /usr/local/bin
        chmod +x /usr/local/bin/ffprobe
        which ffprobe

    - name: Install WebKit
      run: playwright install webkit

    - name: Check formatting
      run: |
        ruff check .
        ruff format --check .

    - name: Check types
      run: mypy src tests

    - name: Run tests
      run: |
        coverage run -m pytest tests
        coverage report
