-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
tools.sh
executable file
·161 lines (145 loc) · 3.27 KB
/
tools.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/env bash
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: BUSL-1.1
set -euo pipefail
# Determine the root directory of the repository
repo_root() {
git rev-parse --show-toplevel
}
# Install an external Go tool.
go_install() {
if go install "$1"; then
echo "--> $1 ✔"
else
echo "--> $1 ✖"
return 1
fi
}
# Check for a tool binary in the path.
check_tool() {
if builtin type -P "$2" &> /dev/null; then
echo "--> $2 ✔"
else
echo "--> $2 ✖"
echo "Could not find required $1 tool $2. Run 'make tools-$1' to install it." 1>&2
return 1
fi
}
# Install external tools.
install_external() {
local tools
# If you update this please update check_external below as well as our external tools
# install action .github/actions/install-external-tools/action.yml
#
tools=(
honnef.co/go/tools/cmd/staticcheck@latest
github.com/bufbuild/buf/cmd/buf@v1.45.0
github.com/favadi/protoc-go-inject-tag@latest
github.com/golangci/misspell/cmd/misspell@latest
github.com/golangci/revgrep/cmd/revgrep@latest
github.com/loggerhead/enumer@latest
github.com/rinchsan/gosimports/cmd/gosimports@latest
golang.org/x/tools/cmd/goimports@latest
google.golang.org/protobuf/cmd/protoc-gen-go@v1.34.2
google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.4.0
gotest.tools/gotestsum@latest
mvdan.cc/gofumpt@latest
mvdan.cc/sh/v3/cmd/shfmt@latest
)
echo "==> Installing external tools..."
for tool in "${tools[@]}"; do
go_install "$tool"
done
}
# Check that all tools are installed
check_external() {
# Ensure that all external tools are available. In CI we'll prefer installing pre-built external
# tools for speed instead of go install so that we don't require downloading Go modules and
# compiling tools from scratch in every CI job.
# See .github/actions/install-external-tools.yml for that workflow.
local tools
tools=(
buf
enumer
gofumpt
goimports
gosimports
gotestsum
misspell
protoc-gen-go
protoc-gen-go-grpc
protoc-go-inject-tag
revgrep
shfmt
staticcheck
)
echo "==> Checking for external tools..."
for tool in "${tools[@]}"; do
check_tool external "$tool"
done
}
# Install internal tools.
install_internal() {
local tools
# If you update this please update check tools below.
tools=(
codechecker
stubmaker
)
echo "==> Installing internal tools..."
pushd "$(repo_root)" &> /dev/null
for tool in "${tools[@]}"; do
go_install ./tools/"$tool"
done
popd &> /dev/null
}
# Check internal that all tools are installed
check_internal() {
# Ensure that all required internal tools are available.
local tools
tools=(
codechecker
stubmaker
)
echo "==> Checking for internal tools..."
for tool in "${tools[@]}"; do
check_tool internal "$tool"
done
}
# Install tools.
install() {
install_internal
install_external
}
# Check tools.
check() {
check_internal
check_external
}
main() {
case $1 in
install-external)
install_external
;;
install-internal)
install_internal
;;
check-external)
check_external
;;
check-internal)
check_internal
;;
install)
install
;;
check)
check
;;
*)
echo "unknown sub-command" >&2
exit 1
;;
esac
}
main "$@"