forked from freebsd/iocage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake8.sh
executable file
·35 lines (27 loc) · 1.34 KB
/
flake8.sh
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
#!/bin/sh
# Run pep8 on all .py files in all subfolders
tmpafter=$(mktemp)
find ./iocage_cli ./iocage_lib -name \*.py -exec flake8 --max-line-length=100 --ignore=E127,E203,W503,F811,W504 {} + > ${tmpafter}
num_errors_after=`cat ${tmpafter} | wc -l`
echo "Current Error Count: ${num_errors_after}"
# get current branch/tag
cur=$(git status -sb | awk '/^## [^H]/{print $2}')
[ -z "${cur}" ] && cur=$(git branch -q | awk '/^\* .*/{gsub("\)$","",$NF);print $NF}')
# Get new tags from remote
git fetch --tags --quiet
# Get latest tag name
last_release=$(git describe --tags `git rev-list --tags --max-count=1`)
echo "Comparing with last stable release: ${last_release}"
git checkout -q ${last_release}
tmpbefore=$(mktemp)
find ./iocage_cli ./iocage_lib -name \*.py -exec flake8 --max-line-length=100 --ignore=E127,E203,W503,F811,W504 {} + > ${tmpbefore}
num_errors_before=`cat ${tmpbefore} | wc -l`
echo "${last_release}'s Error Count: ${num_errors_before}"
# The number may be lower then the last release, but that doesn't tell them that they're not higher than they should be.
num_errors_adjusted=$((num_errors_before - num_errors_after))
[ -n "${cur}" ] && git checkout -q ${cur}
if [ ${num_errors_adjusted} != 0 ] && [ ${num_errors_adjusted} -gt ${num_errors_before} ]; then
echo "New Flake8 errors were introduced:"
diff -u ${tmpbefore} ${tmpafter}
exit 1
fi