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

Fix inplace option being always overwritten #22

Closed schra closed 3 years ago

schra commented 3 years ago

Observation

I observed that the following action always passes - even after I added bad indentation on purpose.

name: lint
on: push
jobs:
  clang-format:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout
      uses: actions/checkout@v2

    - name: clang format
      uses: DoozyX/clang-format-lint-action@v0.10
      with:
        extensions: 'h,cpp'
        clangFormatVersion: 10

For example, the following call always returns an exit code of 0:

docker run -it --rm --workdir /src -v $(pwd):/src clang-format-lint \
  "--clang-format-executable" "/clang-format/clang-format10" "-r" \
  "--inplace" "false" "--extensions" "h,cpp" "--exclude" "none" "."

The bug

Turns out that --inplace was parsed wrong and as soon as --inplace is passed (and it is always passed) it essentially actually meant --inplace True. And when --inplace True is passed, then the exit code will be 0 and thus the action always is successful.

See https://stackoverflow.com/questions/15008758/parsing-boolean-values-with-argparse for more information on parsing booleans.

Running the above Docker command with my fix actually returns an exit code of 1 and thus the actions also fails as expected.

Fixes #18. Fixes #19

DoozyX commented 3 years ago

Thank you