github.com/Oppodelldog/droxy@v0.8.0/.release/build.sh (about) 1 #!/usr/bin/env bash 2 if [ "$1" = "test" ]; then 3 tag="v0.0.0" 4 echo "test mode: building current branch as v0.0.0" 5 else 6 workingBranch=$(git rev-parse --abbrev-ref HEAD) 7 8 git diff --exit-code > /dev/null 9 if [ $? -ne 0 ]; then 10 echo "git workspace is not clean, commit or stash your changes" 11 exit 1 12 fi 13 14 git fetch --tags 15 tag=$(git describe --tags "$(git rev-list --tags --max-count=1)") 16 if [ -z "${tag}" ]; then 17 echo "could not find latest tag" 18 exit 1 19 fi 20 21 git checkout "${tag}" 22 fi 23 24 target_folder=".release" 25 binary_name="droxy" 26 package="github.com/Oppodelldog/${binary_name}" 27 ldflags=-ldflags="-X github.com/Oppodelldog/droxy/version.Number=${tag}" 28 29 platforms=("linux/amd64" "windows/amd64" "windows/386" "linux/arm/7") 30 31 for platform in "${platforms[@]}" 32 do 33 platform_split=(${platform//\// }) 34 GOOS="${platform_split[0]}" 35 GOARCH="${platform_split[1]}" 36 GOARM="" 37 38 if [ "${GOARCH}" = "arm" ]; then 39 GOARM=${platform_split[2]} 40 fi 41 42 output_folder="${GOOS}-${GOARCH}${GOARM}" 43 output_name=${binary_name} 44 if [ "${GOOS}" = "windows" ]; then 45 output_name+='.exe' 46 fi 47 48 env GOOS="${GOOS}" GOARCH="${GOARCH}" GOARM="${GOARM}" go build "${ldflags}" -o "${target_folder}/${tag}/${output_folder}/${output_name}" ${package} 49 if [ $? -ne 0 ]; then 50 echo 'An error has occurred! Aborting the script execution...' 51 exit 1 52 fi 53 54 currentWd=$(pwd) 55 sha256sum -b "${target_folder}/${tag}/${output_folder}/${output_name}" | awk '{ print $1 }' > "${target_folder}/${tag}/${output_folder}/${binary_name}.sum" 56 cp LICENSE "${target_folder}/${tag}/${output_folder}/LICENSE" 57 cd "${target_folder}/${tag}/${output_folder}" || exit 58 59 tar -cvzf "../${output_name}-${output_folder}.tar.gz" "${output_name}" "${binary_name}.sum" LICENSE 60 61 cd "${currentWd}" || exit 62 rm -rf "${target_folder:?}/${tag}/${output_folder}" 63 done 64 65 if [ "$1" = "test" ]; then 66 echo "test release done" 67 else 68 git checkout "${workingBranch}" 69 fi