name: Yarn
on:
  pull_request:
    paths:
      - "**.json"
      - "**.md"
      - "**.yml"
      - "packages/**"
jobs:
  yarn:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          token: ${{ secrets.ACCESS_TOKEN }}
          ref: ${{ github.head_ref }}
          fetch-depth: 0
      - uses: actions/setup-node@v2.1.0
        with:
          node-version: "14.4.0"
      - id: yarn-cache-path
        run: echo "::set-output name=dir::$(yarn cache dir)"
      - id: cache
        uses: actions/cache@master
        with:
          path: |
            node_modules
            */*/node_modules
            ${{ steps.yarn-cache-path.outputs.dir }}
          key: |
            yarn-v1-${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}
          restore-keys: |
            yarn-v1-${{ runner.os }}-
      - run: |
          yarn install --frozen-lockfile
      - run: |
          yarn run typescript
      - run: |
          yarn run test
      - if: failure()
        run: |
          yarn run fix
          git config --local user.name 'github-actions[bot]'
          git config --local user.email 'github-actions[bot]@users.noreply.github.com'
          git commit -am "[sentrei-auto-fix]"
          git push
      - run: |
          yarn run build
