name: test

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

jobs:
  check-install:
    strategy:
      matrix:
        os: [ ubuntu-latest ]
        python-version: [ "3.8", "3.9", "3.10", "3.11" ]
    runs-on: ${{ matrix.os }}
    steps:
      - name: Check out OQpy
        uses: actions/checkout@v3

      - name: Set up Python ${{ matrix.python-version }}
        id: setup-python
        uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.python-version }}

      - name: Install OQpy using pip
        run: pip install .

      - name: Import OQpy and print version
        run: python -c "import oqpy; print(oqpy.__version__)"

  check-style:
    strategy:
      matrix:
        os: [ ubuntu-latest ]
        python-version: [ "3.11" ]
    runs-on: ${{ matrix.os }}
    steps:
      - name: Check out OQpy
        uses: actions/checkout@v3

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

      - name: Install poetry
        run: |
          make install-poetry
          poetry --version
          poetry config virtualenvs.in-project true

      - name: Install dependencies
        run: poetry install --no-root

      - name: Run black
        run: poetry run make check-format

      - name: Run mypy
        run: poetry run make check-mypy

      - name: Run pylint
        run: poetry run make check-pylint

      - name: Run pydocstyle
        run: poetry run make check-pydocstyle

      - name: Run cffconvert
        run: poetry run make check-citation

      - name: Install OQpy using pip
        run: poetry run pip install .

      - name: Build and check docs
        run: poetry run make docs

  check-tests:
    strategy:
      matrix:
        os: [ ubuntu-latest ]
        python-version: [ "3.8", "3.9", "3.10", "3.11" ]
    runs-on: ${{ matrix.os }}
    steps:
      - name: Check out OQpy
        uses: actions/checkout@v3

      - name: Set up Python ${{ matrix.python-version }}
        id: setup-python
        uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.python-version }}

      - name: Install poetry
        run: |
          make install-poetry poetry_version=1.5.1
          poetry --version
          poetry config virtualenvs.in-project true

      - name: Install dependencies
        run: poetry install --no-root

      - name: Install OQpy using pip
        run: poetry run pip install .

      - name: Run pytest
        run: poetry run make check-tests
