diff --git a/.gitignore b/.gitignore index 0b4e9eb..38bb051 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,5 @@ *.out timeconverter +dist/timeconverter.rb +dist/timeconverter*.zip diff --git a/dist/.gitkeep b/dist/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/release.sh b/release.sh new file mode 100755 index 0000000..87609c2 --- /dev/null +++ b/release.sh @@ -0,0 +1,63 @@ +#!/usr/bin/env bash + +set -e + +version="0.1.0" +package="timeconverter" +bin="timeconverter" +repo="https://github.com/bbeardsley/timeconverter" + +platforms=( + "windows/amd64" + "windows/386" + "darwin/amd64" + "darwin/386" + "linux/amd64" + "linux/386" + "linux/arm" +) + +rm -f dist/* + +for platform in "${platforms[@]}" +do + platform_split=(${platform//\// }) + GOOS=${platform_split[0]} + GOARCH=${platform_split[1]} + + BIN="${bin}" + if [ $GOOS = "windows" ]; then + BIN="${bin}.exe" + fi + ZIP=$package'_v'$version'_'$GOOS'_'$GOARCH'.zip' + + echo "Building for GOOS=$GOOS GOARCH=$GOARCH" + + env GOOS=$GOOS GOARCH=$GOARCH go build -o dist/${BIN} && + zip -q dist/${ZIP} -j dist/${BIN} && + rm dist/${BIN} +done + +DARWIN_AMD64=${package}_v${version}_darwin_amd64.zip +DARWIN_386=${package}_v${version}_darwin_386.zip + +cat << EOF > dist/${package}.rb +# This file was generated by release.sh +require 'formula' +class TimeConverter < Formula + homepage '${repo}' + version '${version}' + + if Hardware::CPU.is_64_bit? + url '${repo}/releases/download/v${version}/${DARWIN_AMD64}' + sha '$( sha256sum dist/${DARWIN_AMD64} | awk '{ print $1 }' | xargs printf )' + else + url '${repo}/releases/download/v${version}/${DARWIN_386}' + sha '$( sha256sum dist/${DARWIN_386} | awk '{ print $1 }' | xargs printf )' + end + + def install + bin.install '${BIN}' + end +end +EOF