Skip to content

Commit

Permalink
add a build script
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobbednarz committed Sep 16, 2020
1 parent 9b8eee7 commit ad6e1cb
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions script/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env bash

version=$1

if [[ -z "$version" ]]; then
echo "usage: $0 <version-number>"
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"

0 comments on commit ad6e1cb

Please sign in to comment.