name: Checks

on:
  push:
    branches:
    - master
  pull_request:
    branches:
    - master

jobs:
  tests:
    timeout-minutes: 40
    runs-on: ubuntu-latest

    steps:
    - name: Checkout
      uses: actions/checkout@v2

    - name: Setup path
      run: sed -i -e "s,../..:,$PWD:," dist/ci/docker-compose.yml

    - name: Run tests
      run: docker-compose -f dist/ci/docker-compose.yml run test

    - name: Submit coverage report to Codecov
      uses: codecov/codecov-action@v1.5.2
      with:
        fail_ci_if_error: true

    - name: Stop containers
      if: always()
      run: docker-compose -f dist/ci/docker-compose.yml down

  linters:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout
      uses: actions/checkout@v2

    - name: Validate gocd config
      run: cd gocd && sh generate.sh && git diff --exit-code

    - name: Setup path
      run: sed -i -e "s,../..:,$PWD:," dist/ci/docker-compose.yml

    - name: Run Flaker
      run: docker-compose -f dist/ci/docker-compose.yml run flaker

    - name: Stop containers
      if: always()
      run: docker-compose -f dist/ci/docker-compose.yml down

