1
1
mirror of https://github.com/walles/moar.git synced 2024-12-02 09:15:46 +03:00
moar/build.sh

29 lines
908 B
Bash
Raw Normal View History

2019-07-07 19:34:05 +03:00
#!/bin/bash
2021-04-18 22:59:38 +03:00
if [ -z ${CI+x} ]; then
# Local build, not in CI, format source
gofmt -s -w .
2021-04-18 22:59:38 +03:00
fi
2021-04-15 16:16:06 +03:00
VERSION="$(git describe --tags --dirty --always)"
2019-07-07 19:34:05 +03:00
2019-08-04 20:07:14 +03:00
BINARY="moar"
if [ -n "${GOOS}${GOARCH}" ]; then
EXE=""
if [ "${GOOS}" = "windows" ]; then
EXE=".exe"
fi
BINARY="releases/${BINARY}-${VERSION}-${GOOS}-${GOARCH}${EXE}"
2019-08-04 20:07:14 +03:00
fi
2021-01-10 17:50:55 +03:00
# Linker flags version number trick below from here:
2019-07-07 19:34:05 +03:00
# https://www.reddit.com/r/golang/comments/4cpi2y/question_where_to_keep_the_version_number_of_a_go/d1kbap7?utm_source=share&utm_medium=web2x
2021-01-10 17:50:55 +03:00
# Linker flags -s and -w strips debug data, but keeps whatever is needed for
# proper panic backtraces, this makes binaries smaller:
# https://boyter.org/posts/trimming-golang-binary-fat/
2019-07-07 19:34:05 +03:00
# This line must be last in the script so that its return code
# propagates properly to its caller
go build -ldflags="-s -w -X main.versionString=${VERSION}" -o "${BINARY}"