forked from buildbuddy-io/buildbuddy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildfix.sh
executable file
·51 lines (41 loc) · 1.21 KB
/
buildfix.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
#!/bin/bash
set -euo pipefail
cd "$(dirname "$0")"
# If ~/go/bin exists, make sure we respect it
export PATH="$PATH:$HOME/go/bin"
gazelle=$([[ "${1:-}" == '-g' ]] || [[ "${1:-}" == '--gazelle' ]] && echo 1 || echo 0)
c_yellow="\x1b[33m"
c_reset="\x1b[0m"
# buildifier format all BUILD files
echo "Formatting WORKSPACE/BUILD files..."
buildifier -r .
echo "Formatting .go files..."
# go fmt all .go files
gofmt -w .
if which clang-format &>/dev/null; then
echo "Formatting .proto files..."
protos=()
while read -r proto; do
protos+=("$proto")
done < <(git ls-files --exclude-standard | grep '\.proto$')
if [ ${#protos[@]} -gt 0 ]; then
clang-format -i --style=Google "${protos[@]}"
fi
else
echo -e "${c_yellow}WARNING: Missing clang-format tool; will not format proto files.${c_reset}"
fi
echo "Formatting frontend and markup files with prettier..."
if which node prettier &>/dev/null; then
BUILD_WORKSPACE_DIRECTORY="$(pwd)" ./tools/prettier/prettier.sh "$(which node)" "$(which prettier)" --write
else
bazel run //tools/prettier:fix
fi
if ((gazelle)); then
echo "Fixing BUILD deps with gazelle..."
if which gazelle &>/dev/null; then
gazelle
else
bazel run //:gazelle
fi
fi
echo 'All done!'