Created
June 7, 2020 21:35
-
-
Save dcaponi/eaa79778a9d841d8b598b6fe325de263 to your computer and use it in GitHub Desktop.
Builds go binaries, adds some literature, and compresses the folder for Mac, Linux, and Windows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
package=$1 | |
if [[ -z "$package" ]]; then | |
echo "usage: $0 <package-name>" | |
exit 1 | |
fi | |
package_split=(${package//\// }) | |
package_name=${package_split[${#package_split[@]}-1]} | |
platforms=("windows/amd64" "windows/386" "darwin/amd64" "linux/amd64" "linux/386") | |
for platform in "${platforms[@]}" | |
do | |
platform_split=(${platform//\// }) | |
GOOS=${platform_split[0]} | |
GOARCH=${platform_split[1]} | |
output_name='build/'$GOOS'-'$GOARCH'/'$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 | |
cp './README.md' './build/'$GOOS'-'$GOARCH'/README.md' | |
cp './LICENSE' './build/'$GOOS'-'$GOARCH'/LICENSE' | |
if [ $GOOS = "windows" ]; then | |
zip -r 'build/'$GOOS'-'$GOARCH'.zip' 'build/'$GOOS'-'$GOARCH | |
else | |
tar -czvf 'build/'$GOOS'-'$GOARCH'.tar.gz' 'build/'$GOOS'-'$GOARCH | |
fi | |
rm -rf 'build/'$GOOS'-'$GOARCH | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment