1
0
Fork 0
mirror of https://github.com/Luzifer/github-publish.git synced 2024-11-09 23:00:14 +00:00
github-publish/golang.sh
Knut Ahlers 5d0421aa0f
Install requirement
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2017-12-28 18:33:28 +01:00

72 lines
1.8 KiB
Bash
Executable file

#!/bin/bash
set -euxo pipefail
( which apk 2>&1 1>/dev/null ) && apk add --update zip
( which apt-get 2>&1 1>/dev/null ) && apt-get install -y zip
curl -sL https://raw.githubusercontent.com/Luzifer/github-publish/master/SHA256SUMS | \
grep "golang.sh" | sha256sum -c || exit 2
VERSION=$(git describe --tags --exact-match || echo "ghpublish__notags")
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"}
DEPLOYMENT_TAG=${DEPLOYMENT_TAG:-${VERSION}}
set -ex
# Retrieve dependencies
go get github.com/aktau/github-release
go get github.com/mitchellh/gox
# Test code (used in PR tests, branch tests, and builds)
go vet .
go test .
# Compile program
gox -ldflags="-X main.version=${VERSION}" -osarch="${ARCHS}"
# Publish builds to Github
set +x
if ( test "${VERSION}" == "ghpublish__notags" ); then
echo "No tag present, stopping build now."
exit 0
fi
if [ -z "${GITHUB_TOKEN}" ]; then
echo "Please set \$GITHUB_TOKEN environment variable"
exit 1
fi
# Generate binary SHASUMs
sha256sum ${REPO}_* > SHA256SUMS
for file in ${REPO}_*; do
if [[ ${file} == *linux* ]]; then
tar -czf "${file}.tar.gz" "${file}"
else
zip "${file}.zip" "${file}"
fi
rm "${file}"
done
set -x
# Generate archive SHASUMs
sha256sum ${REPO}_* >> SHA256SUMS
# Create a drafted release
github-release release --user ${GHUSER} --repo ${REPO} --tag ${DEPLOYMENT_TAG} --name ${DEPLOYMENT_TAG} --draft || true
# Upload build assets
for file in ${REPO}_* SHA256SUMS; do
github-release upload --user ${GHUSER} --repo ${REPO} --tag ${DEPLOYMENT_TAG} --name ${file} --file ${file}
done
echo -e "\n\n=== Recorded checksums ==="
cat SHA256SUMS