Debian Codegraph @

script/release

raw
1 #!/bin/bash
2 PROJDIR=$(cd `dirname $0`/.. && pwd)
3
4 VERSION="${1}"
5 TAG="v${VERSION}"
6 USER="tomnomnom"
7 REPO="gron"
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 FILELIST=""
30
31 for ARCH in "amd64" "386"; do
32 for OS in "darwin" "linux" "windows" "freebsd"; do
33
34 if [[ "${OS}" == "darwin" && "${ARCH}" == "386" ]]; then
35 continue
36 fi
37
38 BINFILE="${BINARY}"
39
40 if [[ "${OS}" == "windows" ]]; then
41 BINFILE="${BINFILE}.exe"
42 fi
43
44 rm -f ${BINFILE}
45
46 GOOS=${OS} GOARCH=${ARCH} go build github.com/${USER}/${REPO}
47
48 if [[ "${OS}" == "windows" ]]; then
49 ARCHIVE="${BINARY}-${OS}-${ARCH}-${VERSION}.zip"
50 zip ${ARCHIVE} ${BINFILE}
51 rm ${BINFILE}
52 else
53 ARCHIVE="${BINARY}-${OS}-${ARCH}-${VERSION}.tgz"
54 tar --create --gzip --file=${ARCHIVE} ${BINFILE}
55 fi
56
57 FILELIST="${FILELIST} ${PROJDIR}/${ARCHIVE}"
58 done
59 done
60
61 gh release create ${TAG} ${FILELIST}
62 rm ${FILELIST}
63