phpcs-action icon indicating copy to clipboard operation
phpcs-action copied to clipboard

Add ability to check only files that have changed during a PR

Open navarr opened this issue 4 years ago • 3 comments

If merged, these changes will limit the scope of phpcs checks to only the files changed in a pull request (limit 3000)

This functionality would be added at the expense of requiring a github token to access the github api to find a list of files changed. I have tried variations using just the repository and relying on the diff of the merge commit to determine what has changed but have found this method unreliable.

These changes would only work during a PR. This does not support processing files changed in a single commit

navarr avatar May 12 '20 13:05 navarr

Would resolve #4

navarr avatar May 12 '20 13:05 navarr

Why not rather working with --cache flag like mentioned in #13 ? Would be much simpler to implement probably and no need for token and you pretty much get same speed...

dakorpar avatar Jan 28 '21 11:01 dakorpar

I discovered this only after implementing our own version, but this seems to work for us without the token. Maybe it will be useful to someone:

yml file:

     - name: Run code sniff
        continue-on-error: true
        run: ./tests/bin/phpcs.sh "${{ github.event.pull_request.base.sha }}" "${{ github.event.after }}"

phpcs.sh

CHANGED_FILES=`git diff --name-only --diff-filter=ACMR "${1}..${2}" | grep \\\\.php`
./vendor/bin/phpcs --ignore=$IGNORE --encoding=utf-8 -s -n -p --report-full --report-checkstyle=./phpcs-report.xml ${CHANGED_FILES}

We need to clone the repo in full, though, so fetch-depth needs to be set before running the PHPCS, otherwise the base SHA is not in the repo.

- name: Checkout code
        uses: actions/checkout@v2
        with:
          fetch-depth: 0

Let's see if we discover any bugs.

peterfabian avatar Mar 01 '21 17:03 peterfabian