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
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'
Refer : Fail pylint using Github actions workflow if file score is less than 6.0
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
withxargs
instead – then your exit code will be coming from your pylint command instead offind
.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: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 usepylint . --recursive=y
if your pylint version is above2.13.0
(it does the same thing thanfind
in your script)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