name: tests
on:
  push:
    paths-ignore:
    - 'docs/**'
    - 'mkdocs.yml'
    - '.readthedocs.yaml'
    - 'requirements-mkdocs.txt'
    - 'README.md'
jobs:
  build:
    timeout-minutes: 60
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: [3.8]
    steps:

    - uses: actions/checkout@v2
      with:
        submodules: recursive

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

    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install -r requirements.txt

    - name: Test with pytest
      env:
        CONSUMER_KEY: ${{ secrets.consumer_key }}
        CONSUMER_SECRET: ${{ secrets.consumer_secret }}
        ACCESS_TOKEN: ${{ secrets.access_token }}
        ACCESS_TOKEN_SECRET: ${{ secrets.access_token_secret }}
        BEARER_TOKEN: ${{ secrets.bearer_token }}
        SKIP_ACADEMIC_PRODUCT_TRACK: true
      run: python setup.py test

    - name: Ensure packages can be built
      run: |
        python -m pip install wheel
        python setup.py sdist bdist_wheel

    - name: Publish to PyPI
      if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
      uses: pypa/gh-action-pypi-publish@release/v1
      with:
        user: __token__
        password: ${{ secrets.PYPI_API_TOKEN }}

    - name: Slack Notification
      uses: rtCamp/action-slack-notify@v2
      env:
        SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
        SLACK_USERNAME: docnow-build
        SLACK_ICON_EMOJI: ":test-tube:"
        SLACK_COLOR: "${{ job.status == 'success' && 'good' || 'danger' }}"
        SLACK_MESSAGE: "Tests Results: ${{ job.status }}"


