name: Lint, Test, Release

on:
  release:
    types: [created]

jobs:
  build:

    strategy:
      max-parallel: 3
      matrix:
        os: [macos-latest]
        python-version: [3.8]

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

    steps:
    - uses: actions/checkout@v2
      with:
        # Note that this is a must because pylint is done based on a previous tag.
        fetch-depth: 0
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v2
      with:
        python-version: ${{ matrix.python-version }}
    - name: Install Python dependencies
      run: |
        python -m pip install --upgrade pip
        pip install -r requirements-ci.txt
        pip install -e .
    - name: mypy
      run: |
        mypy monty
    - name: flake8
      run: |
        flake8 --count --show-source --statistics monty
        # exit-zero treats all errors as warnings.
        flake8 --count --exit-zero --max-complexity=20 --statistics monty
    - name: pydocstyle
      run: |
        pydocstyle --count monty
    - name: Lint with pylint
      run: |
        pylint monty
    - name: black
      run: |
        black --version
        black --check --diff --color monty
    - name: pytest
      run: |
        pytest tests --color=yes
    - name: release
      env:
        TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }}
        TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
      run: |
        pip install setuptools wheel twine
        python setup.py sdist bdist_wheel
        twine upload dist/*.whl
        twine upload --skip-existing dist/*.tar.gz