name: Tests

on:
  push:
    branches: [main]
  pull_request:
    branches:
      - "*"
  schedule:
    - cron: "0 0 * * 1,4"

jobs:
  Test:
    name: ${{ matrix.os }}, ${{ matrix.environment-file }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest]
        environment-file:
          - ci/38-minimal.yaml
          - ci/39.yaml
          - ci/310.yaml
          - ci/311.yaml
          - ci/311-dev.yaml
          - ci/311-no-optional.yaml
        include:
          - environment-file: ci/310.yaml
            os: macos-latest
          - environment-file: ci/310.yaml
            os: windows-latest
    defaults:
      run:
        shell: bash -l {0}

    steps:
      - uses: actions/checkout@v4

      - name: setup micromamba
        uses: mamba-org/setup-micromamba@v1
        with:
          environment-file: ${{ matrix.environment-file }}
          micromamba-version: "latest"

      - name: Install libpysal
        run: pip install .; python -c 'import libpysal; libpysal.examples.fetch_all()'

      - name: Test libpysal
        run: |
          pytest -v --color yes --cov libpysal --cov-append --cov-report term-missing --cov-report xml .

      - uses: codecov/codecov-action@v3

      - name: Generate and publish the report
        if: |
          failure()
          && steps.status.outcome == 'failure'
          && github.event_name == 'schedule'
          && github.repository_owner == 'pysal'
        uses: xarray-contrib/issue-from-pytest-log@v1
        with:
          log-path: pytest-log.jsonl
