name: Check codebase

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

jobs:
  build:
    name: Build
    runs-on: ubuntu-latest
    steps:
      - name: Check out repository
        uses: actions/checkout@v2

      - name: Setup node
        uses: actions/setup-node@v1
        with:
          node-version: 14

      - name: Install dependencies
        run: yarn install --frozen-lockfile

      - name: Run build
        run: yarn build

  storybook:
    name: Storybook
    runs-on: ubuntu-latest
    steps:
      - name: Check out repository
        uses: actions/checkout@v2

      - name: Setup node
        uses: actions/setup-node@v1
        with:
          node-version: 14

      - name: Install dependencies
        run: yarn install --frozen-lockfile

      - name: Run build:storybook
        run: yarn storybook:build

  lint:
    name: Linting
    runs-on: ubuntu-latest
    steps:
      - name: Check out repository
        uses: actions/checkout@v2

      - name: Setup node
        uses: actions/setup-node@v1
        with:
          node-version: 14

      - name: Install dependencies
        run: yarn install --frozen-lockfile

      - name: Lint with ESLint
        run: yarn lint

      - name: Lint with TSC
        if: ${{ always() }}
        run: yarn lint:types

  unit-tests:
    name: Unit tests
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [macos-latest, ubuntu-latest]
        node: [12, 14, 16]
        exclude:
          - os: macos-latest
            node: 12
    steps:
      - name: Check out repository
        uses: actions/checkout@v2

      - name: Setup node
        uses: actions/setup-node@v1
        with:
          node-version: ${{ matrix.node }}

      - name: Install dependencies
        run: yarn install --frozen-lockfile

      - name: Run unit tests
        run: yarn test
