DoozyX / clang-format-lint-action

This action checks if the source code matches the .clang-format file.
MIT License
129 stars 46 forks source link

File extension filtering is not working if arg.files list is full paths to files #23

Open electronjoe opened 3 years ago

electronjoe commented 3 years ago

I am using the following configuration of the GH Action.

        name: "Clang Format Linting"
        uses: DoozyX/clang-format-lint-action@v0.11
        with:
          source: ${{ steps.changed_files.outputs.all }}
          extensions: 'c,h,cpp,hpp'
          clangFormatVersion: 11

Where steps.changed_files.outputs.all is a space delineated list of all changed files in the Pull Request.

For my simple test PR, this equals: source: '.github/workflows/clang-format.yml lte/gateway/c/oai/tasks/nas/emm/msg/DetachAccept.c'

I am observing that Clang-Format is being applied to two files in this PR, which is unexpected. It is analyzing (and failing) on clang-format.yml.

The root cause appears to be within this line of list_files. In my usage (which seems reasonable?) a full file path is being passed for all potential Clang-Tidy targets. Yet this line and the subsequent extension filtering only apply if the arg.files is in fact a directory. Since my arg.files are not directories, no filtering is applied and we skip down to the else clause which appends all arg.files to the set of outputs for analysis.

It seems to me that the filtering logic (exclude and extension based) needs to be replicated for both branches of this if statement. I'll explore doing this and submit a Pull Request.