From 3e100a29c960400550d7432c272deaf687cecac9 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 16 Apr 2014 16:53:26 -0700 Subject: [PATCH] scripts: dist script --- .gitignore | 1 + scripts/dist.sh | 77 +++++++++++++++++++++---------------------------- 2 files changed, 34 insertions(+), 44 deletions(-) diff --git a/.gitignore b/.gitignore index 9538c71dd5..db181741c7 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,7 @@ _cgo_export.* _testmain.go +/dist *.exe *.test bin/ diff --git a/scripts/dist.sh b/scripts/dist.sh index a7f3d18ffc..c409820f0b 100755 --- a/scripts/dist.sh +++ b/scripts/dist.sh @@ -1,6 +1,19 @@ #!/bin/bash set -e +# Get the version from the command line +VERSION=$1 +if [ -z $VERSION ]; then + echo "Please specify a version." + exit 1 +fi + +# Make sure we have a bintray API key +if [ -z $BINTRAY_API_KEY ]; then + echo "Please set your bintray API key in the BINTRAY_API_KEY env var." + exit 1 +fi + # Get the parent directory of where this script is. SOURCE="${BASH_SOURCE[0]}" while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done @@ -9,53 +22,29 @@ DIR="$( cd -P "$( dirname "$SOURCE" )/.." && pwd )" # Change into that dir because we expect that cd $DIR -# Determine the version that we're building based on the contents -# of packer/version.go. -VERSION=$(grep "const Version " version.go | sed -E 's/.*"(.+)"$/\1/') -VERSIONDIR="${VERSION}" -PREVERSION=$(grep "const VersionPrerelease " version.go | sed -E 's/.*"(.*)"$/\1/') -if [ ! -z $PREVERSION ]; then - PREVERSION="${PREVERSION}.$(date -u +%s)" - VERSIONDIR="${VERSIONDIR}-${PREVERSION}" -fi - -echo "Version: ${VERSION} ${PREVERSION}" - -# Determine the arch/os combos we're building for -XC_ARCH=${XC_ARCH:-"386 amd64 arm"} -XC_OS=${XC_OS:-linux darwin windows freebsd openbsd} - -echo "Arch: ${XC_ARCH}" -echo "OS: ${XC_OS}" - -# Make sure that if we're killed, we kill all our subprocseses -trap "kill 0" SIGINT SIGTERM EXIT - -# This function builds whatever directory we're in... -gox \ - -arch="$XC_ARCH" \ - -os="$XC_OS" \ - -output "pkg/${VERSIONDIR}/{{.OS}}_{{.Arch}}/consul" \ - . - -# Zip all the packages -mkdir -p ./pkg/${VERSIONDIR}/dist -for PLATFORM in $(find ./pkg/${VERSIONDIR} -mindepth 1 -maxdepth 1 -type d); do - PLATFORM_NAME=$(basename ${PLATFORM}) - ARCHIVE_NAME="${VERSIONDIR}_${PLATFORM_NAME}" - - if [ $PLATFORM_NAME = "dist" ]; then - continue - fi - - pushd ${PLATFORM} - zip ${DIR}/pkg/${VERSIONDIR}/dist/${ARCHIVE_NAME}.zip ./* - popd +# Zip all the files +rm -rf ./dist/pkg +mkdir -p ./dist/pkg +for FILENAME in $(find ./dist -mindepth 1 -maxdepth 1 -type f); do + FILENAME=$(basename $FILENAME) + PLATFORM="${FILENAME%.*}" + zip ./dist/pkg/${PLATFORM}.zip ./dist/${FILENAME} done # Make the checksums -pushd ./pkg/${VERSIONDIR}/dist -shasum -a256 * > ./${VERSIONDIR}_SHA256SUMS +pushd ./dist/pkg +shasum -a256 * > ./${VERSION}_SHA256SUMS popd +# Upload +for ARCHIVE in ./dist/pkg/*; do + ARCHIVE_NAME=$(basename ${ARCHIVE}) + + echo Uploading: $ARCHIVE_NAME + curl \ + -T ${ARCHIVE} \ + -umitchellh:${BINTRAY_API_KEY} \ + "https://api.bintray.com/content/mitchellh/consul/consul/${VERSION}/${ARCHIVE_NAME}" +done + exit 0