name: Coverage
on:
  push:
    branches:
      - main
  pull_request:
  schedule:
    - cron: 0 0 * * *

jobs:
  Coverage:
    runs-on: ubuntu-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 coverage pytest
          pip install -r requirements.txt
          pip install -r test/requirements.txt
          python setup.py install
      - name: Generate Unit Test Coverage
        run: |
          coverage run --rcfile=.coveragerc -m pytest test/unit/test_dropbox_unit.py
          coverage xml
      - name: Publish Coverage
        uses: codecov/codecov-action@v1.3.2
        with:
          flags: unit
          fail_ci_if_error: true
  IntegrationCoverage:
    runs-on: ubuntu-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 coverage pytest
          pip install -r requirements.txt
          pip install -r test/requirements.txt
          python setup.py install
      - name: Generate Unit Test Coverage
        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: |
          coverage run --rcfile=.coveragerc -m pytest test/integration/test_dropbox.py
          coverage xml
      - name: Publish Coverage
        uses: codecov/codecov-action@v1.3.2
        with:
          flags: integration
          fail_ci_if_error: true