name: CI

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

jobs:
  lint:
    name: Lint
    runs-on: ubuntu-18.04
    timeout-minutes: 10
    steps:
      - uses: actions/checkout@v1
      - name: Setup Node
        uses: actions/setup-node@v1
        with:
          node-version: '12'
      - name: Restore Dependencies and VS Code test instance
        uses: actions/cache@v2
        with:
          path: |
            node_modules
            */*/node_modules
            packages/foam-vscode/.vscode-test
          key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock', 'packages/foam-vscode/src/test/run-tests.ts') }}-${{ secrets.CACHE_VERSION }}
      - name: Install Dependencies
        run: yarn
      - name: Check Lint Rules
        run: yarn lint

  test:
    name: Build and Test
    strategy:
      matrix:
        os: [macos-10.15, ubuntu-18.04, windows-2019]
    runs-on: ${{ matrix.os }}
    env:
      OS: ${{ matrix.os }}
    timeout-minutes: 15
    steps:
      - uses: actions/checkout@v1
      - name: Setup Node
        uses: actions/setup-node@v1
        with:
          node-version: '12'
      - name: Restore Dependencies and VS Code test instance
        uses: actions/cache@v2
        with:
          path: |
            node_modules
            */*/node_modules
            packages/foam-vscode/.vscode-test
          key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock', 'packages/foam-vscode/src/test/run-tests.ts') }}-${{ secrets.CACHE_VERSION }}
      - name: Install Dependencies
        run: yarn
      - name: Build Packages
        run: yarn build
      - name: Run Tests
        uses: GabrielBB/xvfb-action@v1.4
        with:
          run: yarn test --stream
