Skip to content

Commit 5ef80b7

Browse files
authored
Second stab at fixing the version command in build.sh (#1762)
* Make sure GOOS=linux and GOARCH=amd64 for version cmd. The commit forces the version command to run with GOOS=linux and GOARCH=amd64. The version command was failing to run properly when cross-compiling to Mac OS and Windows, since the environment variables were causing the binary produced to not be executable on Travis CI. Closes #1759 Signed-off-by: Eric Chlebek <eric@sensu.io> * Don't pass cross-compile env vars to VERSION_CMD. Signed-off-by: Eric Chlebek <eric@sensu.io>
1 parent 6d92b02 commit 5ef80b7

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

build.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ VERSION_CMD="GOOS=linux GOARCH=amd64 go run ./version/cmd/version/version.go"
1919
HANDLERS=(slack)
2020

2121
set_race_flag() {
22-
if [ "$GOARCH" == "amd64" ]; then
22+
if [ "$GOARCH" == "amd64" ] && [ "$CGO_ENABLED" == "1" ]; then
2323
RACE="-race"
2424
fi
2525
}
@@ -79,6 +79,13 @@ build_tool_binary () {
7979
}
8080

8181
build_binary () {
82+
# Unset GOOS and GOARCH so that the version command builds on native OS/arch
83+
unset GOOS
84+
unset GOARCH
85+
86+
local version=$($VERSION_CMD -v)
87+
local prerelease=$($VERSION_CMD -p)
88+
8289
local goos=$1
8390
local goarch=$2
8491
local cmd=$3
@@ -87,8 +94,6 @@ build_binary () {
8794

8895
local outfile="target/${goos}-${goarch}/${cmd_name}"
8996

90-
local version=$($VERSION_CMD -v)
91-
local prerelease=$($VERSION_CMD -p)
9297
local build_date=$(date +"%Y-%m-%dT%H:%M:%S%z")
9398
local build_sha=$(git rev-parse HEAD)
9499

0 commit comments

Comments
 (0)