name: Test

on:
  push:
    branches:
      - develop
      - master
  pull_request:
    types:
      - opened
      - synchronize

jobs:
  OS:
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [macos-latest, windows-latest, ubuntu-latest]
    steps:
      - name: Checkout branch
        uses: actions/checkout@v1
      - name: Read Node version from .nvmrc
        run: echo "##[set-output name=NVMRC;]$(cat .nvmrc)"
        id: nvm
      - uses: actions/setup-node@v1
        with:
          node-version: ${{ steps.nvm.outputs.NVMRC }}
      - name: Bootstrap packages
        run: npm run bootstrap
      - name: Lint
        run: npm run lint
      - name: Run tests
        run: npm test
      - name: Build for smoke tests
        run: npm run app-build:smoke
      - name: Run smoke tests
        timeout-minutes: 10 # sometimes jest fails to exit - https://github.com/facebook/jest/issues/6423#issuecomment-620407580
        run: npm run test:smoke:build
      - name: Upload smoke test screenshots
        uses: actions/upload-artifact@v2
        if: always()
        with:
          if-no-files-found: ignore
          name: ${{ matrix.os }}-smoke-test-screenshots-${{ github.run_number }}
          path: packages/insomnia-smoke-test/screenshots
      - name: Run CLI smoke tests
        run: npm run test:smoke:cli
