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
|
2021-04-19 16:18:51 +03:00
|
|
|
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"
|
2021-04-18 22:59:38 +03:00
|
|
|
if [ -n "$GOOS$GOARCH" ]; then
|
2020-12-30 19:40:27 +03:00
|
|
|
BINARY="releases/$BINARY-$VERSION-$GOOS-$GOARCH"
|
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
|
2021-01-10 17:50:55 +03:00
|
|
|
go build -ldflags="-s -w -X main.versionString=$VERSION" -o "$BINARY"
|