name: "Pip"

on:
  workflow_dispatch:
  pull_request:
  push:
    branches:
      - master

jobs:
  make_dist:
    name: Make distributions
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
      with:
        repository: pybind/pybind11

    - uses: actions/setup-python@v2

    - name: Download requirements
      run: python -m pip install build

    - name: Build files
      run: |
        python -m build
        PYBIND11_GLOBAL_SDIST=ON python -m build

    - uses: actions/upload-artifact@v2
      with:
        path: dist/*

  build:
    name: Build with Pip
    needs: [make_dist]
    strategy:
      fail-fast: false
      matrix:
        platform: [windows-latest, macos-latest, ubuntu-latest]
        python-version: ["2.7", "3.5", "3.8"]

        exclude:
          # Not supported by scikit-build
        - platform: windows-latest
          python-version: "2.7"

    runs-on: ${{ matrix.platform }}

    steps:
    - uses: actions/checkout@v2

    - uses: actions/download-artifact@v2
      with:
        name: artifact
        path: dist

    - uses: actions/setup-python@v2
      with:
        python-version: ${{ matrix.python-version }}

    - name: Add requirements
      run: python -m pip install --upgrade wheel setuptools

    # Eventually Microsoft might have an action for setting up
    # MSVC, but for now, this action works:
    - name: Prepare compiler environment for Windows 🐍 2.7
      if: runner.os == 'Windows'
      uses: ilammy/msvc-dev-cmd@v1.9.0
      with:
        arch: x64

    - name: Build and install
      run: pip install --verbose . --find-links ${{ github.workspace }}/dist

    - name: Test
      run: python tests/test.py
