Skip to content
Advertisement

Pylint fail under does not fail my Github action job

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 ?

Advertisement

Answer

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
Advertisement