# based on https://github.com/joerick/cibuildwheel/blob/master/examples/github-minimal.yml

name: Build

on:
  push:
    branches: [master]
    # Sequence of patterns matched against refs/tags
    tags:
      - 'v*'  # Push events to matching v*, i.e. v1.0, v20.15.10
  pull_request:
    branches: [master]

jobs:
  build:
    name: Build wheels on ${{ matrix.os }}
    if: "!contains(github.event.head_commit.message, '[skip ci]')"
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]

    steps:
    - uses: actions/checkout@v2
      with:
        fetch-depth: 0  # unshallow fetch for setuptools-scm

    - name: Use MSBuild (Windows)
      uses: microsoft/setup-msbuild@v1.0.0
      if: matrix.os == 'windows-latest'

    - uses: actions/setup-python@v1
      name: Install Python
      with:
        python-version: '3.6'

    - name: Install cibuildwheel
      run: |
        python -m pip install cibuildwheel==1.5.2

    - name: Build wheel
      run: |
        python -m cibuildwheel --output-dir dist
      env:
        # The packaged FreeType library is independent of the Python ABI so we only
        # need to build it once.
        CIBW_BUILD: "cp36-*x86_64 cp36-*amd64"
        CIBW_ENVIRONMENT: "FREETYPEPY_BUNDLE_FT=yes PYTHON_ARCH=64"
        CIBW_MANYLINUX_X86_64_IMAGE: manylinux1
        CIBW_TEST_COMMAND: "pytest {project}/tests"
        CIBW_TEST_REQUIRES: "pytest"

    - uses: actions/upload-artifact@v2
      with:
        name: freetype-py-dist
        path: dist/*.whl

    # Build sdist on one platform, and only on tagged commits.
    - name: Build sdist
      run: |
        python setup.py sdist
      if: matrix.os == 'ubuntu-latest' && github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')

    - name: Publish package to PyPI
      run: |
        pip install twine
        twine upload dist/*
      env:
        TWINE_USERNAME: ${{ secrets.pypi_username }}
        TWINE_PASSWORD: ${{ secrets.pypi_password }}
      if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
