forked from review-robot/robot-gitee-welcome
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·134 lines (111 loc) · 2.17 KB
/
build.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
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
128
129
130
131
132
133
134
#!/bin/bash
set -euo pipefail
cd $(dirname $0)
me=$(basename $0)
plugin_name=$(pwd | xargs basename)
pn=$#
all_param=( $@ )
bazel=bazel-3.4.1
tips(){
echo -e "\n*************** $1 ***************\n"
}
update_repo(){
tips "update repo"
if [ -f go.mod ]; then
go mod tidy
else
go mod init github.com/opensourceways/robot-gitee-welcome
go mod tidy
fi
$bazel run //:gazelle -- update-repos -from_file=go.mod
$bazel run //:gazelle
}
build(){
update_repo
tips "build binary"
$bazel build --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 //:$plugin_name
}
image(){
update_repo
tips "build image"
$bazel run --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 //:image
}
push_image(){
update_repo
tips "push image"
$bazel run --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 //:push_image
}
clean(){
$bazel clean
}
cmd_help(){
if [ $# -eq 0 ]; then
cat << EOF
usage: $me cmd
supported cmd:
clean: clean local environment.
build: build binary.
image: build image.
push_image: build and push image.
help: show the usage for each commands.
EOF
return 0
fi
local cmd=$1
case $cmd in
"clean")
echo "$me clean"
;;
"build")
echo "$me build"
;;
"image")
echo "$me image"
;;
"push_image")
echo "$me push_image"
;;
"help")
echo "$me help other-child-cmd"
;;
*)
echo "unknown child cmd: $cmd"
;;
esac
}
fetch_parameter() {
local index=$1
if [ $pn -lt $index ]; then
echo ""
else
echo "${all_param[@]:${index}-1}"
fi
}
if [ $pn -lt 1 ]; then
cmd_help
exit 1
fi
cmd=$1
case $cmd in
"clean")
clean
;;
"build")
build $(fetch_parameter 2)
;;
"image")
image
;;
"push_image")
push_image
;;
"--help")
cmd_help
;;
"help")
cmd_help $(fetch_parameter 2)
;;
*)
echo "unknown cmd: $cmd"
;;
esac