2016-11-21 12:48:30 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
curl -sL https://raw.githubusercontent.com/Luzifer/github-publish/master/SHA256SUMS | \
|
2016-11-21 19:21:56 +00:00
|
|
|
grep "golang.sh" | sha256sum -c || exit 2
|
2016-11-21 12:48:30 +00:00
|
|
|
|
2017-03-06 10:27:54 +00:00
|
|
|
VERSION=$(git describe --tags --exact-match || echo "ghpublish__notags")
|
2016-11-21 12:48:30 +00:00
|
|
|
PWD=$(pwd)
|
|
|
|
godir=${PWD/${GOPATH}\/src\/}
|
|
|
|
REPO=${REPO:-$(echo ${godir} | cut -d '/' -f 3)}
|
2016-11-21 21:23:13 +00:00
|
|
|
GHUSER=${GHUSER:-$(echo ${godir} | cut -d '/' -f 2)}
|
2016-11-21 12:48:30 +00:00
|
|
|
ARCHS=${ARCHS:-"linux/amd64 linux/arm darwin/amd64 windows/amd64"}
|
2017-03-06 10:27:54 +00:00
|
|
|
DEPLOYMENT_TAG=${DEPLOYMENT_TAG:-${VERSION}}
|
2016-11-21 12:48:30 +00:00
|
|
|
|
2017-03-06 10:27:54 +00:00
|
|
|
set -ex
|
2016-11-21 12:48:30 +00:00
|
|
|
|
2017-03-06 10:27:54 +00:00
|
|
|
# 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
|
2016-11-21 12:48:30 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
set -x
|
|
|
|
|
|
|
|
# Generate SHASUMs
|
|
|
|
sha256sum ${REPO}_* > SHA256SUMS
|
|
|
|
|
|
|
|
# Create a drafted release
|
2017-08-08 09:12:53 +00:00
|
|
|
DESC="${VERSION}"
|
|
|
|
if [ -f History.md ]; then
|
|
|
|
sv=$(echo ${VERSION} | sed 's/^v//')
|
|
|
|
DESC=$(awk "/# ${sv}/{flag=1;next} /# /{flag=0} flag" History.md | head -n -1 | tail -n +2)
|
|
|
|
fi
|
|
|
|
|
|
|
|
github-release release --user ${GHUSER} --repo ${REPO} \
|
|
|
|
--tag ${DEPLOYMENT_TAG} --name ${DEPLOYMENT_TAG} \
|
|
|
|
--description ${DESC} --draft || true
|
2016-11-21 12:48:30 +00:00
|
|
|
|
|
|
|
# Upload build assets
|
|
|
|
for file in ${REPO}_* SHA256SUMS; do
|
2017-03-06 10:27:54 +00:00
|
|
|
github-release upload --user ${GHUSER} --repo ${REPO} --tag ${DEPLOYMENT_TAG} --name ${file} --file ${file}
|
2016-11-21 12:48:30 +00:00
|
|
|
done
|
2017-07-09 18:19:11 +00:00
|
|
|
|
2017-07-09 18:22:19 +00:00
|
|
|
echo -e "\n\n=== Recorded checksums ==="
|
2017-07-09 18:19:11 +00:00
|
|
|
|
|
|
|
cat SHA256SUMS
|