norio-nomura / action-swiftlint

GitHub Action for SwiftLint
MIT License
370 stars 58 forks source link

Add option to run swiftlint only on changed files #22

Closed axelguilmin closed 4 years ago

axelguilmin commented 4 years ago

Hello, I am not really good with bash but I found this solution to check only the files changed in the current pull request. This would help https://github.com/norio-nomura/action-swiftlint/issues/11

axelguilmin commented 4 years ago

Right, that is not the behavior I expected, I fixed that ;)

koenpunt commented 4 years ago

While I like the idea of only linting changed files, passing filenames to swiftlint makes it ignore the excluded configuration, causing it to lint also files that normally would be ignored. Another thing I noticed; github.base_ref resolves to a branch name, but that branch isn't necessarily available. To get that to work you have to alter the checkout action behavior;

- uses: actions/checkout@v2
- run: |
    git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/*

Edit; running the additional git fetch doesn't solve it.

norio-nomura commented 4 years ago

it ignore the excluded configuration

--force-exclude option will resolve it: https://github.com/norio-nomura/action-swiftlint/issues/23#issuecomment-581006372

Another thing I noticed; github.base_ref resolves to a branch name, but that branch isn't necessarily available.

Hm, It seems that happens on pull_request against non default branch. 🤔 Could you please try fetching base_ref like following?

      - uses: actions/checkout@v1
      - run: |
          git fetch origin +refs/heads/${{ github.base_ref }}:refs/heads/${{ github.base_ref }}
        continue-on-error: true # ignore fail if base_ref points default branch.
koenpunt commented 4 years ago

Hm, It seems that happens on pull_request against non default branch.

It actually is a PR against master, but I'll try your suggestion.