Skip to content

Code Formatting and Linting Workflows #8

Code Formatting and Linting Workflows

Code Formatting and Linting Workflows #8

Workflow file for this run

name: Pylint Check
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
jobs:
pylint-check:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11.0'
- name: Install dependencies
run: |
pip install pylint
- name: Run Pylint
run: |
# Get the list of changed files
changes=$(git diff --name-only ${{ github.base_ref }} ${{ github.head_ref }} | grep '\.py$')
echo "Changed files: $changes"
# Make sure to include only the files that exist
changed_files=""
for file in $changes; do
if [ -f "$file" ]; then
changed_files="$changed_files $file"
fi
done
echo "Changed existing files: $changed_files"
# Check if there are any changed Python files
if [ -z "$changed_files" ]; then
echo "No Python files changed."
exit 0
fi
# Run pylint on the changed files and capture the score
pylint_score=$(pylint $changed_files | tee /dev/tty | grep 'Your code has been rated at' | awk '{print $7}' | cut -d '/' -f 1)
# Check if the score is below 9
if (( $(echo "$pylint_score < 9" | bc -l) )); then
echo "Pylint score is below 9: $pylint_score"
exit 1
else
echo "Pylint score is acceptable: $pylint_score"
fi