From ad6e1cbecaa100bd550efe9bb2171a99853a13ee Mon Sep 17 00:00:00 2001 From: Jacob Bednarz Date: Wed, 16 Sep 2020 12:57:09 +1000 Subject: [PATCH] add a build script --- script/build | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100755 script/build diff --git a/script/build b/script/build new file mode 100755 index 0000000..f53d233 --- /dev/null +++ b/script/build @@ -0,0 +1,58 @@ +#!/usr/bin/env bash + +version=$1 + +if [[ -z "$version" ]]; then + echo "usage: $0 " + exit 1 +fi + +git_sha=`git rev-parse --short HEAD` +version_with_sha="${version}+${git_sha}" + +if [ -d build ]; then + rm -rf build +fi +mkdir -p build + +platforms=("windows/amd64" "linux/amd64" "darwin/amd64") + +echo "==> Build started for v${version}" + +for platform in "${platforms[@]}" +do + platform_split=(${platform//\// }) + GOOS=${platform_split[0]} + GOARCH=${platform_split[1]} + output_name="cf-vault_${version}_${GOOS}_${GOARCH}" + + printf "==> Building %s\t%s\n" "$platform" "build/$output_name" | expand -t 30 + + + if [ $GOOS = "windows" ]; then + env GOOS=$GOOS GOARCH=$GOARCH go build -o "build/${output_name}.exe" -ldflags "-X github.com/jacobbednarz/cf-vault/cmd.Rev=${version_with_sha}" . + else + env GOOS=$GOOS GOARCH=$GOARCH go build -o "build/${output_name}" -ldflags "-X github.com/jacobbednarz/cf-vault/cmd.Rev=${version_with_sha}" . + fi + if [ $? -ne 0 ]; then + echo "Building the binary has failed!" + exit 1 + fi + + printf "==> Tarballing %s\t%s\n" "$platform" "build/${output_name}.tar.gz" | expand -t 30 + if [ $GOOS = "windows" ]; then + tar -czf "build/${output_name}.tar.gz" -C "build" "${output_name}.exe" + else + tar -czf "build/${output_name}.tar.gz" -C "build" "${output_name}" + fi + + if [ $? -ne 0 ]; then + echo "Creating the tarball has failed!" + exit 1 + fi +done + +echo "==> Generating file checksums to build/checksums.txt" +shasum -a 256 build/* > "build/checksums.txt" + +echo "==> Build process complete"