From 87c870099145cfc4f51d808fb935dd1492a09729 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Wed, 10 Jul 2019 14:13:32 +0200 Subject: [PATCH] Replace gox with simple loop (#5) * Replace gox with simple loop Signed-off-by: Knut Ahlers * Properly clone array Signed-off-by: Knut Ahlers * Use function for sub-steps Signed-off-by: Knut Ahlers * No need to export suffix Signed-off-by: Knut Ahlers * Use package as source for filename Signed-off-by: Knut Ahlers * Fix iteration Signed-off-by: Knut Ahlers --- SHA256SUMS | 2 +- golang.sh | 45 ++++++++++++++++++++++++++++----------------- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/SHA256SUMS b/SHA256SUMS index 7fbf3e5..0db5e3e 100644 --- a/SHA256SUMS +++ b/SHA256SUMS @@ -1,2 +1,2 @@ 05e4977d541b2ef07c757acca912b7b58b379fb425eceb3a1f53c829a78a4aa4 docker2aci.sh -3ce8fae21fc7a65e2d56981642507f35d3896a638a89413a8a9d5430fc095ca0 golang.sh +365e7c96a65ac13a36df75f6dc18583db82f4e060de5c914bd8edcc1f5c5aac7 golang.sh diff --git a/golang.sh b/golang.sh index 9d372b3..bba7184 100755 --- a/golang.sh +++ b/golang.sh @@ -10,7 +10,11 @@ curl -sL https://raw.githubusercontent.com/Luzifer/github-publish/master/SHA256S } function step() { - echo "===> $@..." + echo "===> $@..." >&2 +} + +function substep() { + echo "======> $@..." >&2 } VERSION=$(git describe --tags --always || echo "dev") @@ -18,9 +22,9 @@ PWD=$(pwd) godir=${PWD/${GOPATH}\/src\//} REPO=${REPO:-$(echo ${godir} | cut -d '/' -f 3)} GHUSER=${GHUSER:-$(echo ${godir} | cut -d '/' -f 2)} -ARCHS=${ARCHS:-"linux/amd64 linux/arm darwin/amd64 windows/amd64"} +ARCHS=(${ARCHS:-linux/amd64 linux/arm darwin/amd64 windows/amd64}) DEPLOYMENT_TAG=${DEPLOYMENT_TAG:-${VERSION}} -PACKAGES=${PACKAGES:-$(echo ${godir} | cut -d '/' -f 1-3)} +PACKAGES=(${PACKAGES:-$(echo ${godir} | cut -d '/' -f 1-3)}) BUILD_DIR=${BUILD_DIR:-.build} DRAFT=${DRAFT:-true} FORCE_SKIP_UPLOAD=${FORCE_SKIP_UPLOAD:-false} @@ -31,18 +35,17 @@ go version step "Retrieve dependencies" pushd ${GOPATH} go get github.com/aktau/github-release -go get github.com/Luzifer/gox popd step "Test code" -test_params=() +go_params=() if [[ -n ${MOD_MODE} ]]; then - test_params+=(-mod="${MOD_MODE}") + go_params+=(-mod="${MOD_MODE}") fi -go vet "${test_params[@]}" ${PACKAGES} -go test "${test_params[@]}" ${PACKAGES} +go vet "${go_params[@]}" ${PACKAGES} +go test "${go_params[@]}" ${PACKAGES} step "Cleanup build directory if present" rm -rf ${BUILD_DIR} @@ -50,19 +53,27 @@ rm -rf ${BUILD_DIR} step "Compile program" mkdir ${BUILD_DIR} -build_params=( +build_params=("${go_params[@]}") +build_params+=( -ldflags="-X main.version=${VERSION}" - -osarch="${ARCHS}" - -output="${BUILD_DIR}/{{.Dir}}_{{.OS}}_{{.Arch}}" ) -if [[ -n ${MOD_MODE} ]]; then - build_params+=(-mod="${MOD_MODE}") -fi +for package in "${PACKAGES[@]}"; do + for osarch in "${ARCHS[@]}"; do + export GOOS=${osarch%%/*} + export GOARCH=${osarch##*/} -gox \ - "${build_params[@]}" \ - ${PACKAGES} + [[ ${GOOS} == "windows" ]] && suffix=".exe" || suffix="" + outfile="${BUILD_DIR}/${package##*/}_${GOOS}_${GOARCH}${suffix}" + + substep "Building for ${osarch} into ${outfile}" + + go build \ + -o "${outfile}" \ + "${build_params[@]}" \ + "${package}" + done +done step "Generate binary SHASUMs" cd ${BUILD_DIR}