forked from go-spring/go-spring
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
81 lines (70 loc) · 1.73 KB
/
run.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
#!/usr/bin/env bash
set -u
# 当前目录是否是 Go 项目目录
function isProjectDir() {
if [ -f "$1""/go.mod" ]; then
return $((1))
fi
return $((0))
}
# 找到 Go 项目目录并执行命令
function run() {
for element in $(ls $1); do
if [ "$element" == "documents" ]; then
continue
fi
dir_or_file=$1"/"$element
if [ -d "$dir_or_file" ]; then
if isProjectDir "$dir_or_file"; then
run "$dir_or_file" "$2"
cd "$dir_or_file" || exit
else
echo "$dir_or_file"
cd "$dir_or_file" || exit
case $2 in
"test")
# 执行当前目录及子目录下的测试用例
go mod vendor && go test -race -count=1 ./...
;;
"lint")
# https://github.com/golangci/golangci-lint
golangci-lint run
;;
*) ;;
esac
fi
fi
done
}
# 启动项目的 doc 页面
function doc() {
project=$2
array=("${project//-/ }")
dir=${array[0]}
if [[ $dir != "spring" && $dir != "starter" ]]; then
exit
fi
WORKSPACE=$1"/""$dir""/"$project
echo "$WORKSPACE"
echo ";; 首次启动加载时间较长,请耐心等待并手动刷新 doc 页面"
MODULE_NAME=$project
PACKAGE_PATH=github.com/go-spring
export GOPATH=/tmp/godoc-${MODULE_NAME}
MODULE_PATH=${GOPATH}/src/${PACKAGE_PATH}
rm -rf "${MODULE_PATH:?}"/"$MODULE_NAME" &>/dev/null
mkdir -p "$GOPATH"/bin
mkdir -p "$MODULE_PATH"
ln -sf "$WORKSPACE" "$MODULE_PATH"/"$MODULE_NAME"
cd "$MODULE_PATH"/"$MODULE_NAME" || exit
python -m webbrowser "http://localhost:6060/pkg/github.com/go-spring/""$MODULE_NAME"
godoc
}
# 命令包括: test、lint、doc.
case $1 in
"doc")
doc "$(pwd)" "$2"
;;
*)
run "$(pwd)" "$1"
;;
esac