-
Notifications
You must be signed in to change notification settings - Fork 313
/
Copy pathfmt.sh
executable file
·49 lines (42 loc) · 970 Bytes
/
fmt.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
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "${0}")"
cd "$(git rev-parse --show-toplevel)"
gen() {
# Unfortunately, this is the only way to ensure go.mod and go.sum are correct.
# See https://github.com/golang/go/issues/27005
go list ./... > /dev/null
go mod tidy
go generate ./...
}
fmt() {
gofmt -w -s .
go run go.coder.com/go-tools/cmd/goimports -w "-local=$(go list -m)" .
go run mvdan.cc/sh/cmd/shfmt -i 2 -w -s -sr .
# shellcheck disable=SC2046
npx -q prettier \
--write \
--print-width 120 \
--no-semi \
--trailing-comma all \
--loglevel silent \
$(git ls-files "*.yaml" "*.yml" "*.md")
}
unstaged_files() {
git ls-files --other --modified --exclude-standard
}
check() {
if [[ ${CI-} && $(unstaged_files) != "" ]]; then
echo
echo "Files need generation or are formatted incorrectly."
echo "Run:"
echo "./ci/fmt.sh"
echo
git status
git diff
exit 1
fi
}
gen
fmt
check