name: CI
on:
  pull_request:

jobs:
  CI:
    continue-on-error: true
    runs-on: ${{ matrix.os }}
    # Supported Versions:
    # https://github.com/actions/python-versions/blob/main/versions-manifest.json
    strategy:
      matrix:
        os: [macos-latest, windows-latest]
        python-version: [2.7, 3.5, 3.6, 3.7, 3.8, pypy-2.7, pypy-3.7]
        exclude:
          - os: windows-latest
            python-version: 3.6
        include:
          - os: ubuntu-latest
            python-version: 3.7
    steps:
      - uses: actions/checkout@v2
      - name: Setup Python environment
        uses: actions/setup-python@v2.2.2
        with:
          python-version: ${{ matrix.python-version }}
      - name: Install Requirements
        run: |
          python -m pip install --upgrade pip
          pip install flake8 pytest
          pip install -r requirements.txt
          pip install -r test/requirements.txt
          python setup.py install
      - name: Run Linter
        run: |
          flake8 setup.py dropbox example test
      - name: Run Unit Tests
        run: |
          pytest test/unit/test_dropbox_unit.py
  Docs:
    runs-on: macos-latest
    steps:
      - uses: actions/checkout@v2
      - name: Setup Python environment
        uses: actions/setup-python@v2.2.2
        with:
          python-version: '3.7'
      - name: Install Requirements
        run: |
          python -m pip install --upgrade pip
          pip install twine sphinx
          pip install -r requirements.txt
          pip install -r test/requirements.txt
          python setup.py install
      - name: Test Doc Generation
        run: |
          sphinx-build -b html docs build/html
      - name: Test Dist Generation
        run: |
          python setup.py sdist bdist_wheel
          twine check dist/*
  Integration:
    continue-on-error: true
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
          os: [macos-latest, windows-latest]
          python-version: [2.7, 3.5, 3.6, 3.7, 3.8, pypy-2.7, pypy-3.7]
          exclude:
            - os: windows-latest
              python-version: 3.6
          include:
            - os: ubuntu-latest
              python-version: 3.7
    steps: 
      - uses: actions/checkout@v2.3.4
      - name: Setup Python environment
        uses: actions/setup-python@v2.2.2
        with:
          python-version: ${{ matrix.python-version }}
      - name: Install Requirements
        run: |
          python -m pip install --upgrade pip
          pip install flake8 pytest
          pip install -r requirements.txt
          pip install -r test/requirements.txt
          python setup.py install
      - name: Run Integration Tests
        env:
          LEGACY_USER_DROPBOX_TOKEN: ${{ secrets.LEGACY_USER_DROPBOX_TOKEN }}
          LEGACY_USER_CLIENT_ID: ${{ secrets.LEGACY_USER_CLIENT_ID }}
          LEGACY_USER_CLIENT_SECRET: ${{ secrets.LEGACY_USER_CLIENT_SECRET }}
          LEGACY_USER_REFRESH_TOKEN: ${{ secrets.LEGACY_USER_REFRESH_TOKEN }}
          SCOPED_USER_DROPBOX_TOKEN: ${{ secrets.SCOPED_USER_DROPBOX_TOKEN }}
          SCOPED_USER_CLIENT_ID: ${{ secrets.SCOPED_USER_CLIENT_ID }}
          SCOPED_USER_CLIENT_SECRET: ${{ secrets.SCOPED_USER_CLIENT_SECRET }}
          SCOPED_USER_REFRESH_TOKEN: ${{ secrets.SCOPED_USER_REFRESH_TOKEN }}
          SCOPED_TEAM_DROPBOX_TOKEN: ${{ secrets.SCOPED_TEAM_DROPBOX_TOKEN }}
          SCOPED_TEAM_CLIENT_ID: ${{ secrets.SCOPED_TEAM_CLIENT_ID }}
          SCOPED_TEAM_CLIENT_SECRET: ${{ secrets.SCOPED_TEAM_CLIENT_SECRET }}
          SCOPED_TEAM_REFRESH_TOKEN: ${{ secrets.SCOPED_TEAM_REFRESH_TOKEN }}
          DROPBOX_SHARED_LINK: ${{ secrets.DROPBOX_SHARED_LINK }}
        run: |
          pytest test/integration/test_dropbox.py