name: CI

on:
  push:
    branches:
      - master
  pull_request:
    branches_ignore:
      - docs/*

jobs:
  formatting:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - name: Setup black environment
        run: conda create --quiet --name black pyflakes

      - name: Check formatting with black
        run: |
          export PATH="/usr/share/miniconda/bin:$PATH"
          source activate black
          pip install black==20.8b1
          black --check rse

      - name: Check imports with pyflakes
        run: |
          export PATH="/usr/share/miniconda/bin:$PATH"
          source activate black
          pyflakes rse/client || true
          pyflakes rse/*.py rse/main rse/utils


  testing:
    needs: formatting
    runs-on: ubuntu-latest
    env:
      RSE_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    steps:
      - uses: actions/checkout@v2
      - name: Setup testing environment
        run: conda create --quiet --name testing pytest

      - name: Test rse
        run: |
          export PATH="/usr/share/miniconda/bin:$PATH"
          source activate testing
          pip install -e .[all]
          pytest -sv tests/*.py
          /bin/bash tests/test_client.sh

  build:
    needs: testing
    runs-on: ubuntu-latest
    env:
      CONTAINER: quay.io/vanessa/rse
    steps:
      - uses: actions/checkout@v2
      - name: Build Docker Image
        run: docker build -t "${CONTAINER}" .
      - name: Tag and Preview Container
        run: |
          DOCKER_TAG=$(docker run "${CONTAINER}:latest" --version)
          echo "Docker tag is: ${DOCKER_TAG}"
          docker run ${CONTAINER} --help
