github.com/pquerna/agent@v2.1.8+incompatible/scripts/utils/build-binary.sh (about)

     1  #!/bin/bash
     2  set -e
     3  
     4  if [[ ${#} -lt 3 ]]
     5  then
     6    echo "Usage: ${0} [platform] [arch] [buildVersion]" >&2
     7    exit 1
     8  fi
     9  
    10  export GOOS=${1}
    11  export GOARCH=${2}
    12  
    13  BUILD_VERSION=${3}
    14  NAME="buildkite-agent"
    15  
    16  BUILD_PATH="pkg"
    17  BINARY_FILENAME="$NAME-$GOOS-$GOARCH"
    18  
    19  if [[ "$GOARCH" = "armhf" ]]; then
    20    export GOARCH="arm"
    21    export GOARM="7"
    22  fi
    23  
    24  echo -e "Building $NAME with:\n"
    25  
    26  echo "GOOS=$GOOS"
    27  echo "GOARCH=$GOARCH"
    28  if [[ -n "$GOARM" ]]; then
    29    echo "GOARM=$GOARM"
    30  fi
    31  echo "BUILD_VERSION=$BUILD_VERSION"
    32  echo ""
    33  
    34  # Add .exe for Windows builds
    35  if [[ "$GOOS" == "windows" ]]; then
    36    BINARY_FILENAME="$BINARY_FILENAME.exe"
    37  fi
    38  
    39  mkdir -p $BUILD_PATH
    40  go build -v -ldflags "-extldflags '-static' -X github.com/buildkite/agent/agent.buildVersion=$BUILD_VERSION" -o $BUILD_PATH/$BINARY_FILENAME *.go
    41  
    42  chmod +x $BUILD_PATH/$BINARY_FILENAME
    43  
    44  echo -e "\nDone: \033[33m$BUILD_PATH/$BINARY_FILENAME\033[0m 💪"