name: CI

on:
  push:

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v1

      - name: Install latest stable
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          override: true
          components: rustfmt, clippy

      - name: Lint with rustfmt
        uses: actions-rs/cargo@v1
        with:
          command: fmt

      - name: Lint with clippy
        uses: actions-rs/cargo@v1
        with:
          command: clippy
          args: --all-targets --all-features

      - name: Test with cargo
        uses: actions-rs/cargo@v1.0.1
        with:
          command: test
          args: --no-default-features
          toolchain: stable

  build:
    runs-on: ${{ matrix.os }}
    needs: lint
    strategy:
      fail-fast: false
      matrix:
        python-version: [3.6, 3.7, 3.8, 3.9]
        os: [ubuntu-latest, macos-latest, windows-latest]

    steps:
      - name: Checkout
        uses: actions/checkout@v1

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

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python

      - name: Add poetry to path
        if:  matrix.os != 'windows-latest'
        run: echo "${HOME}/.poetry/bin" >> $GITHUB_PATH

      - name: Add poetry to path
        if:  matrix.os == 'windows-latest'
        run: echo "${HOME}/.poetry/bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append

      - name: Install package deps
        run: |
          poetry install

      - name: Install latest stable
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          override: true

      - name: Build Python package
        run: poetry run maturin develop --release

      - name: pytest
        run: poetry run pytest tests

#      - name: Benchmark
#        run: poetry run pytest benchmarks --compare
