name: CI

on:
  pull_request:

jobs:
    install:
      runs-on: ubuntu-latest
      steps:
        - uses: actions/checkout@v2
        - uses: actions/setup-node@v4
          with:
            node-version: 20
        - name: Cache
          uses: actions/cache@v3
          with:
            path: node_modules
            key: ${{ runner.os }}-node-client-${{ hashFiles('yarn.lock') }}
        - name: Install
          run: yarn install --frozen-lockfile

    lint:
      needs: install
      runs-on: ubuntu-latest
      steps:
        - uses: actions/checkout@v2
        - uses: actions/setup-node@v4
          with:
            node-version: 20
        - name: Restore cache
          uses: actions/cache@v3
          with:
            path: node_modules
            key: ${{ runner.os }}-node-client-${{ hashFiles('yarn.lock') }}
        - name: Lint
          run: yarn lint

    build:
      needs: install
      runs-on: ubuntu-latest
      steps:
        - uses: actions/checkout@v2
        - uses: actions/setup-node@v4
          with:
            node-version: 20
        - name: Restore cache
          uses: actions/cache@v3
          with:
            path: node_modules
            key: ${{ runner.os }}-node-client-${{ hashFiles('yarn.lock') }}
        - name: Build
          run: yarn build

    test:
      needs: install
      runs-on: ubuntu-latest
      steps:
        - uses: actions/checkout@v2
        - uses: actions/setup-node@v4
          with:
            node-version: 20
        - name: Restore cache
          uses: actions/cache@v3
          with:
            path: node_modules
            key: ${{ runner.os }}-node-client-${{ hashFiles('yarn.lock') }}
        - name: Test
          run: yarn test:coverage:ci
        - name: Coveralls
          uses: coverallsapp/github-action@master
          with:
            github-token: ${{ secrets.GITHUB_TOKEN }}
            base-path: .
        - name: Test Report
          uses: dorny/test-reporter@v1
          if: success() || failure()
          with:
            name: JEST Tests
            path: reports/jest-*.xml
            reporter: jest-junit
