Repository navigation
<
8000
/div>
Expand file tree
/
Copy pathcheck.sh
More file actions
69 lines (54 loc) · 1.51 KB
/
Copy pathcheck.sh
File metadata and controls
69 lines (54 loc) · 1.51 KB
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
#!/bin/bash
# set -x
# set -e
# echo -e "==> start check ..."
echo -e "\033[34m==> start check ...\033[0m"
# 解析参数
set="$1"
# 工作目录路径
WD="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# 项目目录路径
PD="$(cd "$WD/../.." && pwd)"
# 工具目录路径
TD=${PD}/tools/hooks
# TD_NAME 当前目录,工具集,不格式化
TD_NAME=$(basename "${TD}")
cd ${PD}
# 为项目中的 bash 文加上运行权限
# find -name "*.sh" | xargs chmod +x
# cmd 获取改动的文件
files=
function change_files() {
work_files="$(git diff --name-status --no-renames | grep -v "^D" | awk '{ print $2; }')"
stage_files="$(git diff --name-status --cached --no-renames | grep -v "^D" | awk '{ print $2; }')"
files="${work_files} ${stage_files}"
# echo "$files"
}
# cmd 获取全部的文件,排除.git 和 工具目录
function all_files() {
files="$(find -name "*" -type f | grep -v .git | grep -v ${TD_NAME})"
# echo "$files"
}
# 文档排版检查
if [ "${set}" == "all" ]; then
all_files
else
change_files
fi
echo "--> files: $files"
# 文档排版检查
bash ${TD}/check-doc.sh "${files}"
# go 代码静态检查
files_go=$(echo "$files" | grep .go)
echo "--> files go: ${files_go}"
if [ -n "${files_go}" ]; then
bash ${TD}/check-code-go.sh "${files_go}"
fi
# bash 代码静态检查
files_bash=$(echo "$files" | grep .sh)
echo "--> files bash: ${files_bash}"
if [ -n "${files_bash}" ]; then
bash ${TD}/check-code-bash.sh "${files_bash}"
fi
# echo -e "==< end check"
echo -e "\033[34m==< end check\033[0m"