name: Linters and Test

on:
  pull_request:
    branches:
      - master
      - develop
    types: [ opened, edited, reopened, synchronize ]
jobs:
  run-linters-tests:
    name: Run Linters and Tests
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repo
        uses: actions/checkout@v2
      - uses: actions/setup-node@v1
        with:
          node-version: '12.x'
          registry-url: 'https://npm.pkg.github.com'
          scope: '@modyo'
      - name: Get yarn cache directory path
        id: yarn-cache-set-path
        run: echo "::set-output name=dir::$(yarn cache dir)"
      - uses: actions/cache@v1
        id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
        with:
          path: ${{ steps.yarn-cache-set-path.outputs.dir }}
          key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
          restore-keys: |
            ${{ runner.os }}-yarn-
      - name: Install packages
        if: steps.yarn-cache-set-path.outputs.cache-hit != 'true'
        run: |
          echo "@fortawesome:registry=https://npm.fontawesome.com/" >> .npmrc
          echo "//npm.fontawesome.com/:_authToken=$FORTAWESOME_TOKEN" >> .npmrc
          yarn
        env:
          FORTAWESOME_TOKEN: ${{secrets.FORTAWESOME_TOKEN}}
          NODE_AUTH_TOKEN: ${{ secrets.TOKEN_REG }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - name: Lint JS
        run: yarn lint
      - name: Lint Styles
        run: yarn lint:style
      - name: Unit Tests
        run: yarn test:unit --passWithNoTests
