wearerequired / lint-action

✨ GitHub Action for detecting and auto-fixing lint errors
MIT License
567 stars 136 forks source link

"Validation failed" creating prettier checks #718

Closed tractorcow closed 1 year ago

tractorcow commented 1 year ago

I have this output in my github actions logs

Run wearerequired/lint-action@v2
Adding auth information to Git remote URL
Fetching remote branch "fix/update-github-actions"
From https://github.com/pixelfusion/pixel-fusion-website
Switching to the "fix/update-github-actions" branch
 * branch            fix/update-github-actions -> FETCH_HEAD
 * [new branch]      fix/update-github-actions -> origin/fix/update-github-actions
Previous HEAD position was 5ee48b0 Merge bd014578fc61895ad36dd762fa84af3b86707a4d into 51e708d45eb4a3a2e3ea44b2486715881f077d5d
Switched to branch 'fix/update-github-actions'
SHA of last commit is "bd014578fc61895ad36dd762fa84af3b86707a4d"
Run Prettier
  Verifying setup for Prettier…
  Verified Prettier setup
  Will use Prettier to check the files with extensions css,html,js,json,jsx,md,sass,scss,ts,tsx,vue,yaml,yml
  Linting files in /home/runner/work/pixel-fusion-website/pixel-fusion-website with Prettier …
  Error:  src/components/Icon/Icon.stories.tsx: SyntaxError: ',' expected. (32:3)
  Error:    30 |     },
  Error:    31 |   },
  Error:  > 32 | } satisfies Meta<typeof Icon>
  Prettier found 1 error (failure)
  Error:       |   ^
  Error:    33 |
  Error:    34 | export default meta
  Error:    35 | type Story = StoryObj<typeof Icon>
Create check runs with commit annotations
  Creating GitHub check with failure conclusion and 1 annotations for Prettier…
  Error: Received status code 422. Validation Failed https://docs.github.com/rest/checks/runs#create-a-check-run
Warning: Some check runs could not be created.

Here is the job for this check

  prettier:
    name: Check prettier
    runs-on: ubuntu-latest
    env:
      GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    steps:
      - name: Check out git repository
        uses: actions/checkout@v3
      - name: Set up Node.js
        uses: actions/setup-node@v3
        with:
          node-version: 18
      - name: Install Node.js dependencies
        run: npm ci
      - name: Code linting
        uses: wearerequired/lint-action@v2
        with:
          prettier: true

Any idea why we are getting Validation Failed on the check creation? It seems to be lint-action is generating a bad api payload, but I'm not sure how to debug this.

tractorcow commented 1 year ago

Another check in the same repo (eslint: true) passes successfully, so it's not a permission issue. It's only an issue for prettier: true check

Create check runs with commit annotations
  Creating GitHub check with success conclusion and 0 annotations for ESLint…
  ESLint check created successfully
tractorcow commented 1 year ago

How can I get the payload for the HTTP post to debug?

tractorcow commented 1 year ago

I managed to extract the payload that was causing the 422 error. The issue is "path" is a required field, but not included.

{
   "name":"Prettier",
   "head_sha":"8926cd754ef3fc50cf4f605b55fa686f4da2630c",
   "conclusion":"failure",
   "output":{
      "title":"1 error",
      "summary":"Prettier found 1 error",
      "annotations":[
         {
            "path":"",
            "start_line":1,
            "end_line":1,
            "annotation_level":"failure",
            "message":"There are issues with this file's formatting, please run Prettier to fix the errors"
         }
      ]
   }
}
tractorcow commented 1 year ago

I've tracked the issue to prettier itself; https://github.com/prettier/prettier/issues/13516

I think this module could respond a bit better to prettier erroring. In linters/prettier.js we have this code.

        const paths = output.stdout.split(/\r?\n/);
        lintResult.error = paths.map((path) => ({
            path,
            firstLine: 1,
            lastLine: 1,
            message:
                "There are issues with this file's formatting, please run Prettier to fix the errors",
        }));

However in this case, output.stdout is blank (hence path being an empty string), with the error being in output.stderr.

tractorcow commented 1 year ago

Updating prettier in my project seemed to solve the issue. I'll close this, sorry for the noise!

tractorcow commented 1 year ago

I've suggested a minor improvement at https://github.com/wearerequired/lint-action/pull/722 to prevent invalid checks being pushed.

tractorcow commented 1 year ago

Checking output.stderror this is that value. Should I bother to parse this?

[error] src/components/Icon/Icon.stories.tsx: SyntaxError: ',' expected. (32:3)
[error]   30 |     },
[error]   31 |   },
[error] > 32 | } satisfies Meta<typeof Icon>
[error]      |   ^
[error]   33 |
[error]   34 | export default meta
[error]   35 | type Story = StoryObj<typeof Icon>

I could regexp the first line and extract path, error, line, character?