Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve build script #250

Merged
merged 1 commit into from
Apr 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ coverage.out
dist/
pkg/
src/
.build/
.DS_Store
.idea
*.rdb
39 changes: 29 additions & 10 deletions build-github-binaries.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
#!/usr/bin/env sh
#!/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 ""
Expand All @@ -8,22 +15,34 @@ 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 -rebuild --osarch="darwin/amd64" -ldflags "$GO_LDFLAGS" -output "dist/redis_exporter" && cd dist && tar -cvzf redis_exporter-$DRONE_TAG.darwin-amd64.tar.gz redis_exporter && rm redis_exporter && cd ..
gox -rebuild --osarch="darwin/386" -ldflags "$GO_LDFLAGS" -output "dist/redis_exporter" && cd dist && tar -cvzf redis_exporter-$DRONE_TAG.darwin-386.tar.gz redis_exporter && rm redis_exporter && cd ..
gox -rebuild --osarch="linux/amd64" -ldflags "$GO_LDFLAGS" -output "dist/redis_exporter" && cd dist && tar -cvzf redis_exporter-$DRONE_TAG.linux-amd64.tar.gz redis_exporter && rm redis_exporter && cd ..
gox -rebuild --osarch="linux/386" -ldflags "$GO_LDFLAGS" -output "dist/redis_exporter" && cd dist && tar -cvzf redis_exporter-$DRONE_TAG.linux-386.tar.gz redis_exporter && rm redis_exporter && cd ..
gox -rebuild --osarch="netbsd/amd64" -ldflags "$GO_LDFLAGS" -output "dist/redis_exporter" && cd dist && tar -cvzf redis_exporter-$DRONE_TAG.netbsd-amd64.tar.gz redis_exporter && rm redis_exporter && cd ..
gox -rebuild --osarch="netbsd/386" -ldflags "$GO_LDFLAGS" -output "dist/redis_exporter" && cd dist && tar -cvzf redis_exporter-$DRONE_TAG.netbsd-386.tar.gz redis_exporter && rm redis_exporter && cd ..
gox -rebuild --osarch="windows/amd64" -ldflags "$GO_LDFLAGS" -output "dist/redis_exporter" && cd dist && zip -9 redis_exporter-$DRONE_TAG.windows-amd64.zip redis_exporter.exe && rm redis_exporter.exe && cd ..
gox -rebuild --osarch="windows/386" -ldflags "$GO_LDFLAGS" -output "dist/redis_exporter" && cd dist && zip -9 redis_exporter-$DRONE_TAG.windows-386.zip redis_exporter.exe && rm redis_exporter.exe && cd ..
gox -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"
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

echo "Upload to Github"

pwd
ls -la
ls -la dist/

ghr -u oliver006 -r redis_exporter --replace $DRONE_TAG dist/
cd dist
sha256sum *.gz *.zip > sha256sums.txt
cd ..

ghr -u oliver006 -r redis_exporter --replace "${DRONE_TAG}" dist/

echo "Done"