1
0
Fork 0
mirror of https://github.com/Luzifer/github-publish.git synced 2024-11-09 23:00:14 +00:00

Replace gox with simple loop (#5)

* Replace gox with simple loop

Signed-off-by: Knut Ahlers <knut@ahlers.me>

* Properly clone array

Signed-off-by: Knut Ahlers <knut@ahlers.me>

* Use function for sub-steps

Signed-off-by: Knut Ahlers <knut@ahlers.me>

* No need to export suffix

Signed-off-by: Knut Ahlers <knut@ahlers.me>

* Use package as source for filename

Signed-off-by: Knut Ahlers <knut@ahlers.me>

* Fix iteration

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2019-07-10 14:13:32 +02:00 committed by GitHub
parent 100cb7d469
commit 87c8700991
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 18 deletions

View file

@ -1,2 +1,2 @@
05e4977d541b2ef07c757acca912b7b58b379fb425eceb3a1f53c829a78a4aa4 docker2aci.sh 05e4977d541b2ef07c757acca912b7b58b379fb425eceb3a1f53c829a78a4aa4 docker2aci.sh
3ce8fae21fc7a65e2d56981642507f35d3896a638a89413a8a9d5430fc095ca0 golang.sh 365e7c96a65ac13a36df75f6dc18583db82f4e060de5c914bd8edcc1f5c5aac7 golang.sh

View file

@ -10,7 +10,11 @@ curl -sL https://raw.githubusercontent.com/Luzifer/github-publish/master/SHA256S
} }
function step() { function step() {
echo "===> $@..." echo "===> $@..." >&2
}
function substep() {
echo "======> $@..." >&2
} }
VERSION=$(git describe --tags --always || echo "dev") VERSION=$(git describe --tags --always || echo "dev")
@ -18,9 +22,9 @@ PWD=$(pwd)
godir=${PWD/${GOPATH}\/src\//} godir=${PWD/${GOPATH}\/src\//}
REPO=${REPO:-$(echo ${godir} | cut -d '/' -f 3)} REPO=${REPO:-$(echo ${godir} | cut -d '/' -f 3)}
GHUSER=${GHUSER:-$(echo ${godir} | cut -d '/' -f 2)} 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}} 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} BUILD_DIR=${BUILD_DIR:-.build}
DRAFT=${DRAFT:-true} DRAFT=${DRAFT:-true}
FORCE_SKIP_UPLOAD=${FORCE_SKIP_UPLOAD:-false} FORCE_SKIP_UPLOAD=${FORCE_SKIP_UPLOAD:-false}
@ -31,18 +35,17 @@ go version
step "Retrieve dependencies" step "Retrieve dependencies"
pushd ${GOPATH} pushd ${GOPATH}
go get github.com/aktau/github-release go get github.com/aktau/github-release
go get github.com/Luzifer/gox
popd popd
step "Test code" step "Test code"
test_params=() go_params=()
if [[ -n ${MOD_MODE} ]]; then if [[ -n ${MOD_MODE} ]]; then
test_params+=(-mod="${MOD_MODE}") go_params+=(-mod="${MOD_MODE}")
fi fi
go vet "${test_params[@]}" ${PACKAGES} go vet "${go_params[@]}" ${PACKAGES}
go test "${test_params[@]}" ${PACKAGES} go test "${go_params[@]}" ${PACKAGES}
step "Cleanup build directory if present" step "Cleanup build directory if present"
rm -rf ${BUILD_DIR} rm -rf ${BUILD_DIR}
@ -50,19 +53,27 @@ rm -rf ${BUILD_DIR}
step "Compile program" step "Compile program"
mkdir ${BUILD_DIR} mkdir ${BUILD_DIR}
build_params=( build_params=("${go_params[@]}")
build_params+=(
-ldflags="-X main.version=${VERSION}" -ldflags="-X main.version=${VERSION}"
-osarch="${ARCHS}"
-output="${BUILD_DIR}/{{.Dir}}_{{.OS}}_{{.Arch}}"
) )
if [[ -n ${MOD_MODE} ]]; then for package in "${PACKAGES[@]}"; do
build_params+=(-mod="${MOD_MODE}") for osarch in "${ARCHS[@]}"; do
fi export GOOS=${osarch%%/*}
export GOARCH=${osarch##*/}
gox \ [[ ${GOOS} == "windows" ]] && suffix=".exe" || suffix=""
"${build_params[@]}" \ outfile="${BUILD_DIR}/${package##*/}_${GOOS}_${GOARCH}${suffix}"
${PACKAGES}
substep "Building for ${osarch} into ${outfile}"
go build \
-o "${outfile}" \
"${build_params[@]}" \
"${package}"
done
done
step "Generate binary SHASUMs" step "Generate binary SHASUMs"
cd ${BUILD_DIR} cd ${BUILD_DIR}