name: Tests

on:
  pull_request:
  push:
    branches: [master]

jobs:
  lint:
    name: Run linters
    runs-on: ubuntu-latest

    steps:
      - name: Git checkout
        uses: actions/checkout@v3

      - name: Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version: 14
          cache: yarn

      - name: Install dependencies
        run: yarn --frozen-lockfile --non-interactive --prefer-offline

      - name: Run linter
        run: yarn xo

  test:
    name: Run tests
    runs-on: ubuntu-latest

    steps:
      - name: Git checkout
        uses: actions/checkout@v3

      - name: Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version: 14
          cache: yarn

      - name: Install dependencies
        run: yarn --frozen-lockfile --non-interactive --prefer-offline

      - name: Run tests
        run: yarn test --ci --forceExit --reporters=default --reporters=github-actions

      - name: Upload code coverage to codecov
        uses: codecov/codecov-action@v3
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
