name: Check JS

on:
  push:
    branches:
      - master
    paths:
      - '.github/workflows/check-js.yml'
      - 'src/**'
      - '*.json'
      - '*.js'
      - '*.jsx'
      - '*.ts'
      - '*.tsx'
      - '*.lock'
  pull_request:
    paths:
      - '.github/workflows/check-js.yml'
      - 'src/**'
      - '*.json'
      - '*.js'
      - '*.jsx'
      - '*.ts'
      - '*.tsx'
      - '*.lock'

jobs:
  TypeScript-Check:
    name: Check TS (tsc)
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Install node_modules
        uses: ./.github/actions/setup-node

      - name: Install reviewdog
        uses: reviewdog/action-setup@v1

      - name: Check TypeScript
        run: |
          yarn tsc | reviewdog -name="tsc" -efm="%f(%l,%c): error TS%n: %m" -reporter="github-pr-review" -filter-mode="nofilter" -fail-on-error -tee
        env:
          REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}

  JS-Lint:
    name: Lint JS (eslint, prettier)
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4

    - name: Install node_modules
      uses: ./.github/actions/setup-node

    - name: Run ESLint
      run: yarn lint -f @jamesacarr/github-actions

    - name: Run ESLint with auto-fix
      run: yarn lint --fix

    - name: Verify no files have changed after auto-fix
      run: git diff --exit-code HEAD
