forked from remind101/assume-role
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·65 lines (53 loc) · 1.19 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
#!/bin/bash
function log() {
echo "===== $(date) ==> ${*}"
}
log "Running go vet"
if ! go vet ./...; then
echo "go vet failed"
exit 1
fi
echo
shopt -s nullglob
set -- *_test.go
if [ "$#" -gt 0 ]; then
log "Running go test"
if ! go test -v; then
echo "go test failed"
exit 1
fi
fi
shopt -u nullglob
echo
if type -p govulncheck >/dev/null; then
log "Running govulncheck"
govulncheck ./...
fi
echo
if type -p golangci-lint >/dev/null; then
log "Running golangci-lint"
if ! golangci-lint run -E revive -E errcheck -E nilerr -E gosec -E staticcheck -E prealloc; then
echo "Check above..."
fi
fi
echo
D=$(basename "${PWD}")
name=${1:-$D}
mkdir -p bin
read -r h m s <<<"$(date "+%H %M %S")"
minor=$(((${h##0} + 1) * (${m##0} + 1) * (${s##0} + 1)))
major=$(date +%Y%m%d)
version="${major}.${minor}"
oses=(linux darwin)
archs=(amd64 arm64)
log "building..."
for GOOS in "${oses[@]}"; do
for GOARCH in "${archs[@]}"; do
echo "Building ${GOARCH} for ${GOOS}..."
# shellcheck disable=SC2097,SC2098
GOOS=${GOOS} GOARCH=${GOARCH} CGO_ENABLED=0 \
go build -ldflags "-s -w -X 'main.Version=v${version}'" \
-o "bin/${name}-${GOOS}-${GOARCH}" .
done
done
echo