-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·26 lines (23 loc) · 1.09 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
#!/usr/bin/env bash
set -Eeuo pipefail
build_date="$(date '+%Y%m%d-%H:%M:%S')"
# let one pass the git version from outside (useful for Nix builds)
if [ -z "${git_version:-}" ]; then
git_version="$(git describe --tags --match "v*" --dirty --abbrev=4 2>/dev/null || true)"
fi
if [ -z "$git_version" ]; then
git_version="v0.0.0-$(git describe --always --dirty --abbrev=4)"
fi
pulley_git_sha=${1:-${pulley_git_sha:-"$(git rev-parse HEAD)"}}
if command -v hostname >&/dev/null; then
fallback_hostname="$(hostname -f 2>/dev/null || true)"
fi
pulley_build_username=${3:-${pulley_build_username:-"$USER@${HOST:-${HOSTNAME:-${fallback_hostname:-unknown}}}"}}
ldflags=(
"-X github.com/knl/pulley/internal/version.Version=$git_version"
"-X github.com/knl/pulley/internal/version.Revision=$pulley_git_sha"
"-X github.com/knl/pulley/internal/version.BuildUser=$pulley_build_username"
"-X github.com/knl/pulley/internal/version.BuildDate=$build_date"
)
# Use CGO_ENABLED=0 as we don't call any C builds, and will be doing cross compiling
GO111MODULE=on CGO_ENABLED=0 go build -ldflags="${ldflags[*]}"