-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·32 lines (31 loc) · 1.08 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
#!/bin/bash
PROJECT_NAME="ecutils"
PKG="$PROJECT_NAME"
PKG_LIST=$(go list "${PKG}/..." | grep -v /vendor/)
GO_FILES=$(find . -name '*.go' | grep -v /vendor/ | grep -v _test.go)
BUILDDATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
CODEVERSION="1.1.4"
CODEBUILDREVISION=$(git rev-parse HEAD)
TARGETS=(
"linux/386"
"linux/amd64"
"linux/arm"
"linux/arm64"
"windows/386"
"windows/amd64"
"darwin/amd64"
)
mkdir -p "dist/$CODEBUILDREVISION"
for target in "${TARGETS[@]}"; do
IFS='/' read -r -a parts <<< "$target"
GOOS="${parts[0]}"
GOARCH="${parts[1]}"
EXTENSION=""
if [[ "$GOOS" == "windows" ]]; then
EXTENSION=".exe"
fi
echo " > Building binary for $GOOS/$GOARCH..."
GOOS="$GOOS" GOARCH="$GOARCH" BUILDDATE="$BUILDDATE" CODEBUILDREVISION="$CODEBUILDREVISION" \
go build -v -ldflags "-X main.GOOS=$GOOS -X main.GOARCH=$GOARCH -X main.CODEVERSION=$CODEVERSION -X main.CODEBUILDDATE=$BUILDDATE -X main.CODEBUILDREVISION=$CODEBUILDREVISION" \
-o "dist/$CODEBUILDREVISION/${PROJECT_NAME}-${GOOS}-${GOARCH}${EXTENSION}" cmd/main.go
done