Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setup eslint to lint everything between master branch and HEAD

I'm trying to setup GitHub action to check for lint errors and fail the pull request if any error/ warnings detected.

Currently my logic works locally but when I try to run it via GitHub action, I get an error:

fatal: ambiguous argument 'origin/master...HEAD': unknown revision or path not in the working tree.

I believe it's something to do with checkout@v2 not fetching the right amount of data, But I cant get my head around what

Code Sample

name: Initiate PR
on: push
jobs:
  STEPS:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 100
      - name: Set up Node.js
        uses: actions/setup-node@v1
        with:
          node-version: 14.18.0
      - name: Install Node.js dependencies
        run: npm ci --ignore-scripts
      - name: lint-on-PR
        shell: bash
        run: |
          npx eslint --max-warnings 0 $(git diff origin/master...HEAD --name-only --relative --diff-filter=MATR '***.js' '***.jsx' '***.ts' '***.tsx' | xargs)

like image 277
Ash Avatar asked Sep 06 '25 14:09

Ash


1 Answers

You would probably need to do a checkout@v1 as in this example to get all the files.

- uses: actions/checkout@v1
...
- run: git diff ${{ github.event.pull_request.base.sha }} ${{ github.sha }}

v2 by default only fetches the sha that triggered the action.

like image 171
tm243 Avatar answered Sep 08 '25 11:09

tm243