name: Miscellaneous checks

# This file runs doctests on the documentation and style checks

on:
  push:
    branches:
      - master
      - maint/*
  pull_request:
    branches:
      - master
      - maint/*

defaults:
  run:
    shell: bash

jobs:
  misc:
    runs-on: 'ubuntu-latest'
    continue-on-error: true
    strategy:
      matrix:
        python-version: ["3.10"]
        install: ['pip']
        check: ['style', 'doctest', 'typing']
        pip-flags: ['']
        depends: ['REQUIREMENTS']
    env:
      DEPENDS: ${{ matrix.depends }}
      OPTIONAL_DEPENDS: ${{ matrix.optional-depends }}
      INSTALL_TYPE: ${{ matrix.install }}
      CHECK_TYPE: ${{ matrix.check }}
      EXTRA_PIP_FLAGS: ${{ matrix.pip-flags }}

    steps:
      - uses: actions/checkout@v3
        with:
          submodules: recursive
          fetch-depth: 0
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.python-version }}
          architecture: ${{ matrix.architecture }}
      - name: Display Python version
        run: python -c "import sys; print(sys.version)"
      - name: Create virtual environment
        run: tools/ci/create_venv.sh
      - name: Build archive
        run: |
          source tools/ci/build_archive.sh
          echo "ARCHIVE=$ARCHIVE" >> $GITHUB_ENV
      - name: Install dependencies
        run: tools/ci/install_dependencies.sh
      - name: Install NiBabel
        run: tools/ci/install.sh
      - name: Run tests
        run: tools/ci/check.sh
        if: ${{ matrix.check != 'skiptests' }}
      - name: Submit coverage
        run: tools/ci/submit_coverage.sh
        if: ${{ always() }}
      - name: Upload pytest test results
        uses: actions/upload-artifact@v3
        with:
          name: pytest-results-${{ matrix.os }}-${{ matrix.python-version }}
          path: for_testing/test-results.xml
        if: ${{ always() && matrix.check == 'test' }}
