Created
July 12, 2014 20:54
-
-
Save rjeczalik/eb85bf4fc09288b5acab to your computer and use it in GitHub Desktop.
For building release archives + Markdown output.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# Usage: | |
# | |
# ~ $ gorelease linux:windows 386:amd64 github.com/rjeczalik/bin/cmd/gobin | |
# ~/src/github.com/rjeczalik/bin/cmd/gobin $ gorelease linux:windows 386:amd64 | |
die() { | |
if [ ! -z "${*}" ]; then | |
echo "gocross: ${*}" 1>&2 | |
fi | |
exit 1 | |
} | |
die_usage() { | |
echo "usage: gorelease <GOOSes> <GOARCHs> [<import_path=\$PWD>]" 1>&2 | |
exit 1 | |
} | |
if [ ${#} -ne 3 ] && [ ${#} -ne 2 ]; then | |
die_usage | |
fi | |
os=$(echo ${1} | tr ':' ' ') | |
arch=$(echo ${2} | tr ':' ' ') | |
pkg=${3} | |
if [ ${#} -eq 2 ]; then | |
# will fail on nested src/ - $GOPATH lookup? | |
pkg=${PWD#*/src/} | |
fi | |
name=$(basename ${pkg}) | |
for goos in ${os}; do | |
for goarch in ${arch}; do | |
case "${goos}" in | |
darwin) | |
output=${name}-${goos}_${goarch}.zip | |
echo -n "* \`${output}\` " | |
GOOS="${goos}" GOARCH="${goarch}" go build "${pkg}" | |
rm -f "${output}" | |
zip -9 "${output}" "${name}" >/dev/null | |
rm -f "${name}" | |
echo SHA1 \`$(sha1sum "${output}" | cut -d' ' -f1)\` | |
;; | |
windows) | |
output=${name}-${goos}_${goarch}.zip | |
echo -n "* \`${output}\` " | |
GOOS="${goos}" GOARCH="${goarch}" go build "${pkg}" | |
rm -f "${output}" | |
zip -9 "${output}" "${name}.exe" >/dev/null | |
rm -f "${name}.exe" | |
echo SHA1 \`$(sha1sum "${output}" | cut -d' ' -f1)\` | |
;; | |
"") | |
;; | |
*) | |
output=${name}-${goos}_${goarch}.bz2 | |
echo -n "* \`${output}\` " | |
GOOS="${goos}" GOARCH="${goarch}" go build "${pkg}" | |
rm -f "${name}.bz2" | |
bzip2 -9 "${name}" | |
mv "${name}.bz2" "${output}" | |
chmod -x "${output}" | |
echo SHA1 \`$(sha1sum "${output}" | cut -d' ' -f1)\` | |
;; | |
esac | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment