wearerequired / lint-action

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

git checkout of PR branch causes mismatch of installed dependencies vs. code #835

Open skagedal opened 1 month ago

skagedal commented 1 month ago

We run lint-action essentially like the example in the README, with eslint and prettier. However, doing things this way seem to cause a mismatch between which commit dependencies are installed from and which commit the linting is run from, causing confusing build errors.

  1. First, the git repository is checked out using actions/checkout@v4. This, by default, does not check out the commit that the PR branch is pointing to, but the commit that would be result of the pull request branch getting merged into main. It does so by fetching the refs/remotes/pull/NNN/merge reference (see explanation here).
  2. Then, running from that merge commit, dependencies are installed.
  3. But then, the lint-action does its own fetching of the remote branch and checks out the unmerged pull request branch. This is where the lint checks are run.

This mismatch of dependencies and code can cause quite a bit of confusion when you don't realize what's happening. It seems that the reason that the PR branch is checked out is that lint-action needs this to be able to push to the branch. We do not, however, use this functionality.

Would it be possible to disable the checkout unless auto_fix is set to true?