skip to Main Content

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.

This is the workflow which I have used :

name: Python Linting
on:
  push:
    branches:
      - '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: Analysing the code with pylint
        run: find . -name '*.py' -print -exec pylint-fail-under --fail-under=7.0 --enable=W {} ;

My goal is the show that pylint has failed for a file and then terminate Git-hub action job. But i am not able to implement it using this can someone help ?

3

Answers


  1. Chosen as BEST ANSWER

    I have finally able to fail the build when pylint score is below 7.0

    This is the workflow which i have used

    name: Python Linting on: push: branches: - '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
            #lists pyling suggestions to improve the score & pylint score of the file
          - name: code review 
            run: find . -name '*.py' -print -exec pylint {} ;
            #fails the build if one file has pylint score below 7.0
          - name: Analyse code
            run: |
                  for file in */*.py; do pylint "$file" --fail-under=7.0; done
    

    Refer : Fail pylint using Github actions workflow if file score is less than 6.0


  2. You have to make your command in "Analysing the code with pylint" step to return code != 0.

    You are using https://pubs.opengroup.org/onlinepubs/009695399/utilities/find.html which ignores completely the exit code or exec part and will return always 0, unless there is an error in iterating over files.

    You have to combine find with xargs instead – then your exit code will be coming from your pylint command instead of find.

    The find + xargs will go through all resources and nonzero status if any of executed command returned nonzero status.

    If you would like to stop on the first file not passing the lining I would recommend using set -e and writing the script differently:

    set -e
    for file in **/*.py; do pylint "$file"; done
    
    Login or Signup to reply.
  3. pylint-fail-under can be removed as pylint has the feature since 2.5.0 which was released a long time ago. You should also be able to use pylint . --recursive=y if your pylint version is above 2.13.0 (it does the same thing than find in your script)

    Add –recursive option to allow recursive discovery of all modules and packages in subtree. Running pylint with –recursive=y option will check all discovered .py files and packages found inside subtree of directory provided as parameter to pylint.

    https://pylint.pycqa.org/en/latest/whatsnew/2/2.13/full.html#what-s-new-in-pylint-2-13-0

    The final command could be: pylint --fail-under=7.0 --recursive=y --enable=W

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search