Skip to content

Commit f77b38d

Browse files
committed
Adds release script
1 parent 5210c9a commit f77b38d

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

script/release

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/bin/bash
2+
PROJDIR=$(cd `dirname $0`/.. && pwd)
3+
4+
VERSION="${1}"
5+
TAG="v${VERSION}"
6+
USER="tomnomnom"
7+
REPO="httprobe"
8+
BINARY="${REPO}"
9+
10+
if [[ -z "${VERSION}" ]]; then
11+
echo "Usage: ${0} <version>"
12+
exit 1
13+
fi
14+
15+
if [[ -z "${GITHUB_TOKEN}" ]]; then
16+
echo "You forgot to set your GITHUB_TOKEN"
17+
exit 2
18+
fi
19+
20+
cd ${PROJDIR}
21+
22+
# Run the tests
23+
go test
24+
if [ $? -ne 0 ]; then
25+
echo "Tests failed. Aborting."
26+
exit 3
27+
fi
28+
29+
# Check if tag exists
30+
git fetch --tags
31+
git tag | grep "^${TAG}$"
32+
33+
if [ $? -ne 0 ]; then
34+
github-release release \
35+
--user ${USER} \
36+
--repo ${REPO} \
37+
--tag ${TAG} \
38+
--name "${REPO} ${TAG}" \
39+
--description "${TAG}" \
40+
--pre-release
41+
fi
42+
43+
44+
for ARCH in "amd64" "386"; do
45+
for OS in "darwin" "linux" "windows" "freebsd"; do
46+
47+
BINFILE="${BINARY}"
48+
49+
if [[ "${OS}" == "windows" ]]; then
50+
BINFILE="${BINFILE}.exe"
51+
fi
52+
53+
rm -f ${BINFILE}
54+
55+
GOOS=${OS} GOARCH=${ARCH} go build github.com/${USER}/${REPO}
56+
57+
if [[ "${OS}" == "windows" ]]; then
58+
ARCHIVE="${BINARY}-${OS}-${ARCH}-${VERSION}.zip"
59+
zip ${ARCHIVE} ${BINFILE}
60+
else
61+
ARCHIVE="${BINARY}-${OS}-${ARCH}-${VERSION}.tgz"
62+
tar --create --gzip --file=${ARCHIVE} ${BINFILE}
63+
fi
64+
65+
echo "Uploading ${ARCHIVE}..."
66+
github-release upload \
67+
--user ${USER} \
68+
--repo ${REPO} \
69+
--tag ${TAG} \
70+
--name "${ARCHIVE}" \
71+
--file ${PROJDIR}/${ARCHIVE}
72+
done
73+
done
74+

0 commit comments

Comments
 (0)