-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
47 lines (37 loc) · 2.1 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
#!/usr/bin/env bash
set -e
#
# 来源: https://github.com/wolfeidau/somproject
#
OWNER=hitokoto
BIN_NAME=worker
PROJECT_NAME=notification_worker
# Get the parent directory of where this script is.
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
DIR="$( cd -P "$( dirname "$SOURCE" )/.." && pwd )"
GIT_COMMIT="$(git rev-parse HEAD)"
GIT_DIRTY="$(test -n "$(git status --porcelain)" && echo "+CHANGES" || true)"
VERSION=$(grep "const Version " version.go | sed -E 's/.*"(.+)"$/\1/' )
# remove working build
rm -rf .gopath
if [ ! -d ".gopath" ]; then
mkdir -p .gopath/src/source.hitokoto.cn/${OWNER}
ln -sf ../../../.. .gopath/src/source.hitokoto.cn/${OWNER}/${PROJECT_NAME}
fi
export GOPATH="$(pwd)/.gopath"
# move the working path and build
cd .gopath/src/source.hitokoto.cn/${OWNER}/${PROJECT_NAME}
go get -d -v ./...
# building the master branch on ci
if [ "$BUILDBOX_BRANCH" = "master" ]; then
go build -ldflags "-X main.GitCommit=${GIT_COMMIT}${GIT_DIRTY}" -tags release -o ./bin/${BIN_NAME}_"${VERSION}"_linux_amd64
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags "-X main.GitCommit=${GIT_COMMIT}${GIT_DIRTY}" -tags release -o ./bin/${BIN_NAME}_"${VERSION}"_linux_arm64
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags "-X main.GitCommit=${GIT_COMMIT}${GIT_DIRTY}" -tags release -o ./bin/${BIN_NAME}_"${VERSION}"_windows_amd64.exe
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "-X main.GitCommit=${GIT_COMMIT}${GIT_DIRTY}" -tags release -o ./bin/${BIN_NAME}_"${VERSION}"_darwin_amd64
else
go build -ldflags "-X main.GitCommit=${GIT_COMMIT}${GIT_DIRTY}" -o ./bin/${BIN_NAME}_"${VERSION}"_linux_amd64
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags "-X main.GitCommit=${GIT_COMMIT}${GIT_DIRTY}" -o ./bin/${BIN_NAME}_"${VERSION}"_linux_arm64
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags "-X main.GitCommit=${GIT_COMMIT}${GIT_DIRTY}" -o ./bin/${BIN_NAME}_"${VERSION}"_windows_amd64.exe
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "-X main.GitCommit=${GIT_COMMIT}${GIT_DIRTY}" -o ./bin/${BIN_NAME}_"${VERSION}"_darwin_amd64
fi