Skip to content

Commit

Permalink
Adds release script
Browse files Browse the repository at this point in the history
  • Loading branch information
tomnomnom committed Mar 24, 2018
1 parent 5210c9a commit f77b38d
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions script/release
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/bin/bash
PROJDIR=$(cd `dirname $0`/.. && pwd)

VERSION="${1}"
TAG="v${VERSION}"
USER="tomnomnom"
REPO="httprobe"
BINARY="${REPO}"

if [[ -z "${VERSION}" ]]; then
echo "Usage: ${0} <version>"
exit 1
fi

if [[ -z "${GITHUB_TOKEN}" ]]; then
echo "You forgot to set your GITHUB_TOKEN"
exit 2
fi

cd ${PROJDIR}

# Run the tests
go test
if [ $? -ne 0 ]; then
echo "Tests failed. Aborting."
exit 3
fi

# Check if tag exists
git fetch --tags
git tag | grep "^${TAG}$"

if [ $? -ne 0 ]; then
github-release release \
--user ${USER} \
--repo ${REPO} \
--tag ${TAG} \
--name "${REPO} ${TAG}" \
--description "${TAG}" \
--pre-release
fi


for ARCH in "amd64" "386"; do
for OS in "darwin" "linux" "windows" "freebsd"; do

BINFILE="${BINARY}"

if [[ "${OS}" == "windows" ]]; then
BINFILE="${BINFILE}.exe"
fi

rm -f ${BINFILE}

GOOS=${OS} GOARCH=${ARCH} go build github.com/${USER}/${REPO}

if [[ "${OS}" == "windows" ]]; then
ARCHIVE="${BINARY}-${OS}-${ARCH}-${VERSION}.zip"
zip ${ARCHIVE} ${BINFILE}
else
ARCHIVE="${BINARY}-${OS}-${ARCH}-${VERSION}.tgz"
tar --create --gzip --file=${ARCHIVE} ${BINFILE}
fi

echo "Uploading ${ARCHIVE}..."
github-release upload \
--user ${USER} \
--repo ${REPO} \
--tag ${TAG} \
--name "${ARCHIVE}" \
--file ${PROJDIR}/${ARCHIVE}
done
done

0 comments on commit f77b38d

Please sign in to comment.