forked from golemfactory/clay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lintdiff.sh
executable file
·94 lines (83 loc) · 2.39 KB
/
lintdiff.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
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
# Checks if new lint messages have appeared
FETCH_ORIGIN=origin
REF_BRANCH=origin/develop
CURRENT_BRANCH=$(git symbolic-ref --short -q HEAD)
REF_OUT=/tmp/ref-lint.out
CURRENT_OUT=/tmp/current-lint.out
FETCH=true
usage() {
echo "Usage: $0 [-b <branch>] [-o] [-f <origin>] [-h] command"
echo " -h show this help message"
echo " -b <branch> use branch \`branch\` for comparison. Default: origin/develop"
echo " -o offline mode, do not fetch origin"
echo " -f <remote> select the remote to fetch before linting. Default: origin"
exit 1
}
check_errcode() {
# Exitcodes >= 126 have special meaning:
# http://www.tldp.org/LDP/abs/html/exitcodes.html
if [ "$1" -ge 126 ]; then
echo "Fatal: command exited with code: $1. Aborting!"
exit 1
fi
}
if [ $# -eq 0 ]; then
usage
fi
while getopts "b:of:h" opt; do
case $opt in
b)
REF_BRANCH=$OPTARG
;;
o)
FETCH=false
;;
f)
FETCH_ORIGIN=$OPTARG
;;
*)
usage
;;
esac
done
shift $((OPTIND - 1))
# get new changes from develop, GitHub doesn't integrate them on its own
if $FETCH; then
echo "Fetching new changes from develop..."
git fetch "$FETCH_ORIGIN" || exit 1
fi
cleanup_artifacts() {
git reset --hard HEAD
git checkout "$CURRENT_BRANCH" || exit 1
}
# we checkout the reference branch first in case there are
# uncommitted changes to be overwritten by the merge
git checkout "$REF_BRANCH" || exit 1
trap cleanup_artifacts EXIT
commit=$(git rev-parse HEAD)
# We need to take files responsible for the linting configuration from
# the new commit.
git checkout "$CURRENT_BRANCH" .pylintrc setup.cfg
echo "Checking branch $REF_BRANCH, commit: $commit..."
echo $@
$@ >$REF_OUT
check_errcode $?
# Now take back the checked out config, go back to the new branch
git reset --hard HEAD
git checkout "$CURRENT_BRANCH" || exit 1
# The trap is no longer needed
trap - EXIT
commit=$(git rev-parse HEAD)
echo "Checking branch $CURRENT_BRANCH, commit: $commit..."
echo $@
$@ >$CURRENT_OUT
check_errcode $?
diff=$(diff --old-line-format="" --unchanged-line-format="" -w <(sort $REF_OUT) <(sort $CURRENT_OUT))
if [ -n "$diff" ]; then
echo -e "New findings:\n"
echo "$diff"
exit 1
else
echo "Check OK, no new findings..."
fi