-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck.sh
66 lines (55 loc) · 1.81 KB
/
check.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
#!/bin/sh
ROOT=$(cd `dirname $0`; pwd)
PARAMS=$*
LUA_CHECK_ROOT=${ROOT}/luacheck
TMP_DIR=${ROOT}/.temp
AUTHOR_DIR=${TMP_DIR}/author
LUACHECK_OUTPUT=${TMP_DIR}/luacheck_output
rm -rf ${TMP_DIR}
mkdir -p ${AUTHOR_DIR}
# 1. 导出luacheck异常信息
# 2. 去除luacheck输出的颜色码
lua -e "package.path=\"${LUA_CHECK_ROOT}/src/?.lua;${LUA_CHECK_ROOT}/src/?/init.lua;\"..package.path" \
${LUA_CHECK_ROOT}/bin/luacheck.lua ${PARAMS} \
| sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" \
>> ${LUACHECK_OUTPUT}
# 数据汇总
brief=`cat ${LUACHECK_OUTPUT} | grep "Total: "`
echo ${brief}
# 按作者名称分文件保存
cat ${LUACHECK_OUTPUT} | grep "^\W" \
| awk -v author_dir=${AUTHOR_DIR} -F ':' '{ \
cmd="v1=`git blame -p -L "$2","$2" "$1"|grep \"^author \"`" \
";author_file="author_dir"/${v1//author /}" \
";echo \""$0"\">>\"$author_file\"" \
;system(cmd) \
}'
# 检查输出的作者数量
author_count=`ls -l ${AUTHOR_DIR} | grep "^-" | wc -l`
if [ $author_count -le 0 ]; then
# 没有异常输出
exit 1
fi
# 合并文件
REPORT_FILE=${ROOT}/`date +%Y-%m-%d-%H-%M-%S`-lua_check_report
# 按作者统计异常数量
printf "author\t number of warnings/errors\n" >> ${REPORT_FILE}
echo "----------------------------" >> ${REPORT_FILE}
find ${AUTHOR_DIR} -type f -exec sh -c '
AUTHOR_DIR=$1
name=$(basename "{}")
file=${AUTHOR_DIR}/${name}
count=(`wc -l "${file}"`)
printf "%s:\t%s\n" "${name}" ${count}
' find-stat ${AUTHOR_DIR} \; >> ${REPORT_FILE}
echo ${brief} >> ${REPORT_FILE}
echo -e "\n" >> ${REPORT_FILE}
# 每个作者具体的异常项
find ${AUTHOR_DIR} -type f -exec sh -c '
AUTHOR_DIR=$1
name=$(basename "{}")
echo ${name}
cat "${AUTHOR_DIR}/${name}"
echo -e "\n"
' find-author ${AUTHOR_DIR} \; >> ${REPORT_FILE}
echo "report file: "${REPORT_FILE}