name: Lint & test

on:
  pull_request:
    branches:
      - '*'

jobs:
  cancel-previous:
    name: 'Cancel Previous Runs'
    runs-on: ubuntu-latest
    timeout-minutes: 3
    steps:
      - uses: styfle/cancel-workflow-action@0.9.1
        with:
          access_token: ${{ github.token }}

  run-tests:
    services:
      postgres:
        image: postgres
        env:
          POSTGRES_DB: 'origin'
          POSTGRES_PASSWORD: 'postgres'
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 10s
          --health-retries 10
        ports:
          - 5432:5432
    runs-on: ubuntu-latest
    needs: cancel-previous
    steps:
    - uses: actions/checkout@v2
      with:
        fetch-depth: 0

    - uses: actions/setup-node@v2-beta
      with:
        node-version: '14'

    - name: Restore timestamp
      run: |
        sh scripts/restore-original-timestamps.sh

    - name: Check dependency versions
      run: node common/scripts/install-run-rush.js check

    - name: Install application
      run: |
        node common/scripts/install-run-rush.js update

    - name: Build application
      run: node common/scripts/install-run-rush.js rebuild --verbose

    - name: Run all test:e2e in packages
      run: node common/scripts/install-run-rush.js test:e2e

    - name: Run all test:ci:contracts
      run: node common/scripts/install-run-rush.js test:ci:contracts
