From ce76c031c52f38b379221491d18794546be91ba4 Mon Sep 17 00:00:00 2001 From: Maciej Lasyk Date: Mon, 3 Jan 2022 20:54:07 +0100 Subject: [PATCH] feat: build script --- build.sh | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 build.sh diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..7cb33a0 --- /dev/null +++ b/build.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +package=$1 +if [[ -z "$package" ]]; then + echo "usage: $0 " + exit 1 +fi +package_split=(${package//\// }) +package_name=${package_split[-1]} + +platforms=("linux/amd64" "linux/386" "linux/arm" "darwin/amd64") + +for platform in "${platforms[@]}" +do + platform_split=(${platform//\// }) + GOOS=${platform_split[0]} + GOARCH=${platform_split[1]} + output_name=$package_name'-'$GOOS'-'$GOARCH + if [ $GOOS = "windows" ]; then + output_name+='.exe' + fi + + env GOOS=$GOOS GOARCH=$GOARCH go build -o $output_name $package + if [ $? -ne 0 ]; then + echo 'An error has occurred! Aborting the script execution...' + exit 1 + fi +done \ No newline at end of file