forked from simagix/hatchet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·38 lines (35 loc) · 1.27 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
#! /bin/bash
# Copyright 2022-present Kuei-chun Chen. All rights reserved.
die() { echo "$*" 1>&2 ; exit 1; }
VERSION="v$(cat version)-$(date "+%Y%m%d")"
REPO=$(basename "$(dirname "$(pwd)")")/$(basename "$(pwd)")
LDFLAGS="-X main.version=$VERSION -X main.repo=$REPO"
TAG="simagix/hatchet"
[[ "$(which go)" = "" ]] && die "go command not found"
gover=$(go version | cut -d' ' -f3)
if [ "$gover" \< "go1.18" ]; then
[[ "$GOPATH" = "" ]] && die "GOPATH not set"
[[ "${GOPATH}/src/github.com/$REPO" != "$(pwd)" ]] && die "building hatchet should be under ${GOPATH}/src/github.com/$REPO"
fi
if [ ! -f go.sum ]; then
go mod tidy
fi
mkdir -p dist
if [ "$1" == "docker" ]; then
BR=$(git branch --show-current)
if [[ "${BR}" == "main" ]]; then
BR="latest"
fi
docker build --no-cache -f Dockerfile -t ${TAG}:${BR} .
# docker rmi -f $(docker images -f "dangling=true" -q) > /dev/null 2>&1
elif [ "$1" == "dist" ]; then
[[ "$(which uname)" = "" ]] && die "uname command not found"
ofile="./dist/hatchet-$(uname|tr '[:upper:]' '[:lower:]')-$(uname -m)"
go build -ldflags "$LDFLAGS" -o ${ofile} main/hatchet.go
else
rm -f ./dist/hatchet
go build -ldflags "$LDFLAGS" -o ./dist/hatchet main/hatchet.go
if [[ -f ./dist/hatchet ]]; then
./dist/hatchet -version
fi
fi