-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeta-lint
executable file
·127 lines (113 loc) · 3.1 KB
/
meta-lint
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/bash
set -e
scriptdir=$(cd $(dirname $0); pwd)
cd $scriptdir
ALL_TAGS=""
ALL_PATHS="./..."
LINT_MODULES=${LINT_MODULES:-ALL}
lint() {
hash golangci-lint 2>&- || { echo "Need to lint GO files, but cannot find 'golangci-lint' in PATH." >&2; exit 1; }
for i in $LINT_MODULES
do
tags=${i}_TAGS
paths=${i}_PATHS
CMD="golangci-lint run $@"
if ! $CMD --build-tags "${!tags}" ${!paths}; then
EXIT_CODE=1
fi
done
}
moreopts=1
EXIT_CODE=0
OUTPUTDIR=.
LOGFILE="meta-lint.txt"
LINTTARGET="ALL"
ADD_GIT_NOTE=1
while [[ $moreopts = 1 && $# -gt 0 ]]; do
case "$1" in
--about|?|help|-h|--help )
echo -e "\nusage: $0 [module]"
echo -e " --topic - lint against the current topic"
echo -e " --outdir <path> - set output directory"
echo -e "\nRuns go meta-linters on last commit and report added issues\n"
echo
exit 0
;;
--full|full)
LINT_MODULES="METRIC_ENGINE SAILFISH"
shift
;;
--outdir)
OUTPUTDIR=$2
shift 2
;;
--no-note)
ADD_GIT_NOTE=0
shift
;;
HEAD|head|latestonly)
# prefer "HEAD"
ARGS="$ARGS --new-from-rev=HEAD~"
LOGFILE="meta-lint-COMMIT-$(git rev-parse --short HEAD).txt"
LINTTARGET="COMMIT-$(git rev-parse --short HEAD)"
revs=$(git rev-parse --short HEAD)
shift
;;
topic|--topic)
# prefer "topic"
topicBranch=$(git rev-parse --abbrev-ref HEAD@{upstream} 2>/dev/null ||:)
if [[ -z "${topicBranch}" ]]; then
branch=$(git symbolic-ref HEAD)
branch=${branch##refs/heads/}
remote=$(git config "branch.${branch}.remote")
remoteBranch=$(git config "branch.${branch}.merge")
remoteBranch=${remoteBranch##refs/heads/}
topicBranch="${remote:?}/${remoteBranch:?}"
fi
topicName=$(git symbolic-ref --short HEAD | sed 's/[^a-zA-Z0-9_-]/-/g')
ARGS="$ARGS --new-from-rev=${topicBranch}"
LOGFILE="meta-lint-TOPIC-${topicName}.txt"
LINTTARGET="TOPIC-${topicName}"
revs=$(git rev-list ${topicBranch}..HEAD --reverse)
shift
;;
*)
moreopts=0
;;
esac
done
exec 1> >(exec -a 'build logging tee' tee $OUTPUTDIR/$LOGFILE) 2>&1
logging_tee_pid=$!
echo
echo "Starting LINT against $LINTTARGET for modules $LINT_MODULES"
if [[ -n "$revs" ]]; then
echo
echo -e "LINT includes the following git commits:\n$revs"
echo
fi
lint "$ARGS" "$@"
echo "Finished LINT against $LINTTARGET for modules $LINT_MODULES"
echo
if [ "$EXIT_CODE" == "0" ]; then
echo 'GREAT JOB! Your lint run was CLEAN'
echo 'Attach this file to your code review as proof of your brilliance!'
echo
fi
echo "OUTPUT SAVED in $OUTPUTDIR/$LOGFILE"
echo -e "\n"
if [ "$EXIT_CODE" != "0" ]; then
echo "THERE ARE LINTER ISSUES! Resolve the listed issues before submitting your code for review!"
echo
fi
if [[ $ADD_GIT_NOTE = 1 ]]; then
git notes --ref meta-lint add -fF $OUTPUTDIR/$LOGFILE
fi
# close up tee
exec 1>&0 2>&1
if [ -n "$logging_tee_pid" ];then
while kill -0 $logging_tee_pid > /dev/null 2>&1
do
sleep 1
done
fi
exit $EXIT_CODE