codespell-project / actions-codespell

MIT License
74 stars 19 forks source link

Add option to only check changed files? #65

Open Justin-JHG opened 1 year ago

Justin-JHG commented 1 year ago

Hi is it possible to add an option so that this action only checks files changed in the current pull request?

thanks

Justin-JHG commented 1 year ago

update, this is similar to issue #38

so this github action does support only check input list of files, for example only the files changed in the current pull request.

I did make it work and will attach my full workflow below, before that I will list the issues with this Github Action:

hope this helps anyone want to use this action for the same purpose, thanks

workflow for spelling check changed files in the pull request:

name: 🚥 Codespell

# workflow to check spelling errors on the changed files within the current pull request

on:
  pull_request:
    types: [opened, edited, synchronize]

jobs:
  codespell:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: 🔸 Get Changed Files from Pull Request
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          # get file names and seperate them with space ' '
          files=$(gh pr diff ${{ github.event.pull_request.number }} --name-only | xargs -I {} sh -c 'echo "./{}"' | tr '\n' ' ')
          echo "CHANGED_FILES=$files" >> "$GITHUB_ENV"          

      - name: 🔸 Output Changed Files
        run: echo ${{ env.CHANGED_FILES }}

      - name: 🔸 Check for Spelling Errors for Changed Files
        uses: codespell-project/actions-codespell@v1
        with:
          check_filenames: true
          skip: nothing
          path: ${{ env.CHANGED_FILES }}
akien-mga commented 1 year ago

Thanks for documenting your workflow, I came here to suggest the same feature and could use your insights to implement the same in https://github.com/godotengine/godot/pull/76828.