Skip to content

Commit

Permalink
Improve build script
Browse files Browse the repository at this point in the history
* Use single gox command to parallelize build.
* Automatically package any archs gox spits out.
* Add sha256sums for packages.
  • Loading branch information
SuperQ committed Apr 8, 2019
1 parent 56b5fb9 commit b78dc96
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
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
38 changes: 28 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,33 @@ 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 -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

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

echo "Done"

0 comments on commit b78dc96

Please sign in to comment.