name: Continuous Integration

on:
  push:
    branches:
      - master
  pull_request:

jobs:
  Linting:
    name: Linting
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Project
        uses: actions/checkout@v2
      - name: Add problem matcher
        run: echo "::add-matcher::.github/problemMatchers/eslint.json"
      - name: Use Node.js v14
        uses: actions/setup-node@v2
        with:
          node-version: 14
      - name: Restore CI Cache
        uses: actions/cache@v2.1.6
        id: cache-restore
        with:
          path: node_modules
          key: ${{ runner.os }}-14-${{ hashFiles('**/yarn.lock') }}
      - name: Install Dependencies if Cache Miss
        if: ${{ !steps.cache-restore.outputs.cache-hit }}
        run: yarn --frozen-lockfile
      - name: Run ESLint
        run: yarn lint --fix=false

  Testing:
    name: Unit Tests
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Project
        uses: actions/checkout@v2
      - name: Use Node.js v14
        uses: actions/setup-node@v2
        with:
          node-version: 14
      - name: Restore CI Cache
        uses: actions/cache@v2.1.6
        id: cache-restore
        with:
          path: node_modules
          key: ${{ runner.os }}-14-${{ hashFiles('**/yarn.lock') }}
      - name: Install Dependencies if Cache Miss
        if: ${{ !steps.cache-restore.outputs.cache-hit }}
        run: yarn --frozen-lockfile
      - name: Run tests
        run: yarn test --coverage
      - name: Store code coverage report
        uses: actions/upload-artifact@v2
        with:
          name: coverage
          path: coverage/

  Building:
    name: Compile source code
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Project
        uses: actions/checkout@v2
      - name: Add problem matcher
        run: echo "::add-matcher::.github/problemMatchers/tsc.json"
      - name: Use Node.js v14
        uses: actions/setup-node@v2
        with:
          node-version: 14
      - name: Restore CI Cache
        uses: actions/cache@v2.1.6
        id: cache-restore
        with:
          path: node_modules
          key: ${{ runner.os }}-14-${{ hashFiles('**/yarn.lock') }}
      - name: Install Dependencies if Cache Miss
        if: ${{ !steps.cache-restore.outputs.cache-hit }}
        run: yarn --frozen-lockfile
      - name: Build Code
        run: yarn build
