# SPDX-FileCopyrightText: 2020 Ole Martin Bjorndalen <ombdalen@gmail.com>
#
# SPDX-License-Identifier: CC0-1.0

name: Tests

on:
  pull_request:
    branches:
      - main
  push:
    branches-ignore:
      - gh-pages
  workflow_dispatch:

jobs:

  style:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version-file: 'pyproject.toml'
          cache: 'pip'
      - name: Upgrade pip
        run: python3 -m pip install --upgrade pip setuptools wheel
      - name: Install mido in dev mode
        run: python3 -m pip install --quiet .[lint-code]
      - name: Lint code with ruff
        run: ruff check .
        env:
          RUFF_OUTPUT_FORMAT: github

  reuse:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version-file: 'pyproject.toml'
          cache: 'pip'
      - name: Upgrade pip
        run: python3 -m pip install --upgrade pip setuptools wheel
      - name: Install mido in dev mode
        run: python3 -m pip install --quiet .[lint-reuse]
      - name: Lint reuse
        run: reuse lint

  manifest:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version-file: 'pyproject.toml'
          cache: 'pip'
      - name: Upgrade pip
        run: python3 -m pip install --upgrade pip setuptools wheel
      - name: Install mido in dev mode
        run: python3 -m pip install --quiet .[check-manifest]
      - name: Check manifest is complete
        run: check-manifest --verbose

  docs:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version-file: 'pyproject.toml'
          cache: 'pip'
      - name: Upgrade pip
        run: python3 -m pip install --upgrade pip setuptools wheel
      - name: Install mido in dev mode
        run: python3 -m pip install --quiet .[build-docs]
      - name: Check documentation
        run: sphinx-build -b linkcheck -j auto -q -W -E --keep-going docs docs/_build

  test:
    needs:
      - docs
      - manifest
      - reuse
      - style
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os:
          - macOS-latest
          - ubuntu-latest
          - windows-latest
        python-version:
            - '3.7'
            - '3.8'
            - '3.9'
            - '3.10'
            - '3.11'
            - '3.12'
            - '3.13'
        exclude:  # Python < v3.8 does not support Apple Silicon ARM64.
          - python-version: "3.7"
            os: macOS-latest
        include: # So run those legacy versions on Intel CPUs.
          - python-version: "3.7"
            os: macOS-13
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.python-version }}
          cache: 'pip'
      - name: Upgrade pip
        run: python3 -m pip install --upgrade pip setuptools wheel
      - name: Install mido in dev mode
        run: python3 -m pip install --quiet .[test-code]
      - name: Test with pytest
        run: pytest
