forked from oliver006/redis_exporter
-
Notifications
You must be signed in to change notification settings - Fork 2
/
build-github-binaries.sh
executable file
·51 lines (37 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
46
47
48
49
50
51
#!/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 windows freebsd netbsd openbsd" -arch="386 amd64" -rebuild -ldflags "${GO_LDFLAGS}" -output ".build/redis_exporter-${DRONE_TAG}.{{.OS}}-{{.Arch}}/{{.Dir}}"
mkdir -p dist
for build in $(ls .build); do
echo "Creating archive for ${build}"
cp LICENSE README.md ".build/${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/" && zip -r --quiet -9 "../dist/${build}.zip" "${build}" && cd ../
else
tar -C ".build/" -czf "dist/${build}.tar.gz" "${build}"
fi
done
cd dist
ls -la
sha256sum *.gz *.zip > sha256sums.txt
ls -la
cd ..
echo "Upload to Github"
ghr -u oliver006 -r redis_exporter --replace "${DRONE_TAG}" dist/
echo "Done"