name: Wand CI

on:
  push:
    branches:
    - master
    tags:
    - '!*'
  pull_request:
    branches:
    - master

jobs:
  build_linux:
    name: Build Linux
    runs-on: ubuntu-latest
    strategy:
      max-parallel: 2
      matrix:
        python-version: ["3.9", "3.10", "3.11", "3.12"]
    steps:
    - uses: actions/checkout@v4
      with:
        fetch-depth: 1
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v5
      with:
        python-version: ${{ matrix.python-version }}
        cache: 'pip'
    - name: Install dependencies
      run: |
        sudo apt-get update -y
        sudo apt-get install -y imagemagick
        python -m pip install --upgrade pip
        pip install --upgrade pytest pytest-cov coveralls
    - name: Run PyTest
      run: pytest --skip-pdf --cov wand
  build_macos:
    name: Build MacOS
    runs-on: macos-latest
    strategy:
      max-parallel: 2
      matrix:
        python-version: ["3.9", "3.10", "3.11"]
    steps:
    - uses: actions/checkout@v4
      with:
        fetch-depth: 1
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v5
      with:
        python-version: ${{ matrix.python-version }}
        cache: 'pip'
    - name: Install dependencies
      run: |
        export HOMEBREW_NO_AUTO_UPDATE=1
        brew install imagemagick
        python -m pip install --upgrade pip
        pip install --upgrade pytest pytest-cov coveralls
    - name: Run PyTest
      run: pytest --skip-pdf --skip-fft --cov wand
      env:
        MAGICK_HOME: /opt/homebrew
    - name: Generate coverage report
      run: coveralls --service=github
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        COVERALLS_FLAG_NAME: ${{ matrix.test-name }}
        COVERALLS_PARALLEL: true
  coveralls:
    name: Indicate completion to coveralls.io
    needs: [build_linux, build_macos]
    runs-on: ubuntu-latest
    container: python:3-slim
    steps:
    - name: Finished
      run: |
        pip3 install --upgrade coveralls
        coveralls --service=github --finish
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
