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

Swiftlint is still checking unchanged files

Open stefangerard opened this issue 4 years ago • 15 comments

SwiftLint is still checking unchanged files in my pull-requests even though I'm using the following swiftlint.yml config

name: SwiftLint

on:
  pull_request:
    paths:
      - '.github/workflows/swiftlint.yml'
      - '.swiftlint.yml'
      - '**/*.swift'
      - '!Pods/**'

jobs:
  SwiftLint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - name: GitHub Action for SwiftLint (Only files changed in the PR)
        uses: norio-nomura/[email protected]
        env:
          DIFF_BASE: ${{ github.base_ref }}

stefangerard avatar Mar 04 '20 23:03 stefangerard

I have the same issue.
I get this error message

fatal: Not a valid object name dev

dev is the value in ${{ github.base_ref }}

Anyway to fix that?

samh-depop avatar Mar 10 '20 13:03 samh-depop

Same issue here!

kerrmarin avatar Mar 13 '20 10:03 kerrmarin

@samh-depop @kerrmarin I've solved this problem with following action configs:

      - name: Fetch base ref
        run: git fetch --no-tags --prune --depth=1 origin ${{ github.base_ref }}
      - name: Run SwiftLint
        uses: norio-nomura/[email protected]
        with:
          args: --force-exclude
        env:
          DIFF_BASE: origin/${{ github.base_ref }}

dlackty avatar Apr 22 '20 14:04 dlackty

I get the same issue with fatal: Not a valid object name dev. Has anyone managed to find a fix for this? I've tried what @dlackty has suggested but it doesn't review any files. It's saying no files changed. :(

tudorsirbu avatar Jun 02 '20 22:06 tudorsirbu

@stefangerard Do you add additional git fetch step to fetch base ref?

Could you share the whole workflow yml? I would like to help.

dlackty avatar Jun 03 '20 10:06 dlackty

I have the same problem. using DIFF_BASE: ${{ gitHub.base_ref }} just results in:

no object master in the console log.

BrentMifsud avatar Jun 10 '20 22:06 BrentMifsud

base_ref is only available for forked repo I think -

https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables

akashnimare avatar Jun 13 '20 08:06 akashnimare

I too have noticed that github.base_ref isn't actually working like we'd expect.

Though I am getting a PR lint successfully when new commits are pushed, but when run locally linting fails. It seems that it is only linting against the changes that were pushed and not the entire PR? The pushed commits didn't have linting issues but also didn't fix the previous linting issues. Has anyone else experienced this issue while using github.base_ref? Should we be using github.ref instead? 🤔

@akashnimare it comes from the github context not env vars (look at github.base_ref docs)

theoriginalbit avatar Jun 20 '20 04:06 theoriginalbit

I have tried out github_ref as well doesn't work as expected.

image

What's the best way to test out GitHub actions locally?

akashnimare avatar Jun 20 '20 07:06 akashnimare

What's the best way to test out GitHub actions locally?

I haven't found a way. I just have a private repo that I do lots of commits on.

theoriginalbit avatar Jun 20 '20 07:06 theoriginalbit

Internet says this tool could be used for testing actions locally.

akashnimare avatar Jun 20 '20 11:06 akashnimare

Same issue here. Will opt-out changed file only till it works.

yo1995 avatar Jul 06 '20 06:07 yo1995

having the same issue. Any clue?

rvilardo avatar Feb 05 '21 15:02 rvilardo

Facing same issue, any solution suggested?

shrutis826 avatar Feb 15 '22 09:02 shrutis826

The root cause is that the action cannot perform a diff against base branch, because the base branch has not been checked out by the workflow (hence fatal: Not a valid object: dev/main/master errors). If you fetch its most recent commit, then it's known to git locally and diff works.

- name: Fetch PR's target branch
  run: git fetch --no-tags --prune --depth=1 origin ${{ github.base_ref }}
- name: Run SwiftLint on files changed in the PR
  uses: norio-nomura/[email protected]
  with:
    args: --force-exclude
  env:
    DIFF_BASE: ${{ github.base_ref }}

It's similar to what @dlackty posted, although in my case origin/ doesn't seem to be needed (in fact it doesn't work that way). Works here, however it still prints that error 🤷

ayoy avatar Apr 15 '22 05:04 ayoy