-
Notifications
You must be signed in to change notification settings - Fork 0
/
ci_format
executable file
·43 lines (33 loc) · 1.01 KB
/
ci_format
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
#!/usr/bin/env bash
go version || exit $?
go mod download || exit $?
go mod vendor || exit $?
LISTFILE=$(git ls-files -m | grep -vP "^$")
export GOROOT=$(echo ${GOROOT})
export GOPATH=$(echo ${GOPATH})
[[ "${GOPATH}" != "" ]] || export GOPATH=/go
export PACKAGE_BIN=/usr/src/tools
export PATH=${PACKAGE_BIN}:${GOPATH}/bin:${PATH}
export CC=${CC}
export CGO_ENABLED=${CGO_ENABLED}
export GO111MODULE=${GO111MODULE}
echo -e "\n\t >>> Reformat sources..."
for gofile in $(find . -type f -name '*.go' | grep -v '/vendor/' | grep -v '/test/' );
do
echo -e "Checking Format file ${gofile}..."
go fmt ${gofile}
goimports -w ${gofile}
done
FRMFILE=$(git ls-files -m | grep -vP "^$")
for PKG in ${LISTFILE}
do
FRMFILE=$(echo -ne "${FRMFILE}" | grep -vP "^${PKG}$" | grep -vP "^$")
done
if [[ "$(echo -ne "${FRMFILE}" | wc -l)" != "0" ]]
then
echo -e "\n\n\t>>> This file need to be formatted with gofmt & goimports ($(echo -ne "${FRMFILE}" | wc -l) files impacted): "
echo -e "${FRMFILE}"
echo -e "\n\n"
exit 1
fi
exit 0