1

I am trying to implement a python linter using pylint. But I am getting the score of each python file and also displaying the suggestion to improve the score but I am also looking to terminate the GitHub action job if my pylint score is below 6.0 but currently its not failing my job. I have got a way to exit the code but i am unable to set the condition for the same. I want to lint all python files but this code exits after linting a single python file. Is it possible to make a check and if the exit code is something like an error it should terminate else the linting must proceed.

Pylint has different exit codes for error and warning but i am not able to set a condition for this : pylint exit code

This is the workflow which I have used :

--- 

name: Python Notebooks Linting
on:
  push:
    branches:
      - 'main'
  repository_dispatch:
#   types: [python-lint] test

jobs:
  linting:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout the code
        uses: actions/checkout@v2
      - name: Install dependencies
        run: |
         python -m pip install --upgrade pip
            pip install pylint
            pip install umsgpack
            pip install cryptography
            pip install pylint-fail-under
      - name: pylint version
        run: pylint --version
      - name: Analysing the code with pylint
        run: |
              set -e
              for file in **/*.py; do pylint "$file"; done

But this code exits after linting a single file I want to set a condition that the linting should exit if the exit code is a specific number. How do I implement this ?

1 Answers1

-1

I used a different way to implement this requirement. Now the GitHub workflow fails if pylint score is less than 6.0 for a single file which is present in my python repo.By using find command in a for loop its able to terminate the job if its returning an exit code corresponding to an error.

  - name: Lints each python file and fails if pylint score is less than 6.0
    run: |
          for file in $(find -name '*.py')
          do
            pylint --disable=E0401,W0611 "$file" --fail-under=6.0;
          done

Refer : Lint python files using Github Workflows

  • See also [Why is looping over find's output bad practice?](https://unix.stackexchange.com/q/321697) Your previous code looping over `**/*.py` looks better and would handle files and directories with spaces in their names. – Kusalananda Sep 01 '22 at 05:58
  • But there is a drawback it does not lint the sub directories. The link has a better logic to lint even subdirectories – sidharth vijayakumar Sep 01 '22 at 06:14
  • If you properly enable the use of `**` with `shopt -s globstar` (assuming the shell being used is `bash`), then `**` will match down into subdirectories. Without the `globstar` shell option being enabled, `**` works just like `*`. Since the question was not about this in particular, I was just a bit surprised that you switch to using `find`. – Kusalananda Sep 01 '22 at 06:15
  • can u please send a reference to this ? I can try i did not know about issues with using find command in loop – sidharth vijayakumar Sep 01 '22 at 06:16