forked from oliver006/redis_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-github-binaries.sh
executable file
·45 lines (35 loc) · 1.3 KB
/
build-github-binaries.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env bash
set -u -e -o pipefail
if [[ -z "${DRONE_TAG}" ]] ; then
echo 'ERROR: Missing DRONE_TAG env'
exit 1
fi
echo "Building binaries for Github"
echo ""
export CGO_ENABLED=0
export GO_LDFLAGS="-s -w -extldflags \"-static\" -X main.BuildVersion=$DRONE_TAG -X main.BuildCommitSha=$DRONE_COMMIT_SHA -X main.BuildDate=$(date +%F-%T)"
echo "GO_LDFLAGS: $GO_LDFLAGS"
go get github.com/mitchellh/gox
go get github.com/tcnksm/ghr
if [[ -f 'go.mod' ]] ; then
go mod tidy
fi
gox -verbose -os="darwin linux freebsd windows netbsd" -arch="386 amd64" -rebuild -ldflags "${GO_LDFLAGS}" -output '.build/{{.OS}}-{{.Arch}}/{{.Dir}}'
mkdir -p dist
for build in $(ls .build); do
echo "Creating archive for ${build}"
if [[ "${build}" =~ ^windows-.*$ ]] ; then
# Make sure to clear out zip files to prevent zip from appending to the archive.
rm "dist/redis_exporter-${DRONE_TAG}.${build}.zip" || true
cd ".build/${build}" && zip --quiet -9 "../../dist/redis_exporter-${DRONE_TAG}.${build}.zip" 'redis_exporter.exe' && cd ../../
else
tar -C ".build/${build}" -czf "dist/redis_exporter-${DRONE_TAG}.${build}.tar.gz" 'redis_exporter'
fi
done
cd dist
sha256sum *.gz *.zip > sha256sums.txt
ls -la
cd ..
echo "Upload to Github"
ghr -u oliver006 -r redis_exporter --replace "${DRONE_TAG}" dist/
echo "Done"