-
Notifications
You must be signed in to change notification settings - Fork 3
72 lines (62 loc) · 2.07 KB
/
pylint-checks.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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
shell: bash
run: |
# Get the list of changed files and calculate the total pylint score for them
# Get the list of changed files
{ # try
changes=$(git diff --name-only origin/${{ github.base_ref }} origin/${{ github.head_ref }} | grep '\.py$')
} || { # catch
if [ $? -eq 1 ]; then
echo "No python file changes found in the pull request."
exit 0
fi
}
echo -e "changes:\n$changes\n"
# 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 -e "Changed existing files:\n$changed_files\n"
# 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
which tee
{ # try
pylint_score=$(pylint $changed_files | tee /dev/tty | grep 'Your code has been rated at' | awk '{print $7}' | cut -d '/' -f 1)
} || { # catch
echo "Pylint failed to run with exit code: $?"
}
# 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