scripts for release

This commit is contained in:
Mitchell Hashimoto
2015-09-27 23:21:00 -07:00
parent 4a65b9950a
commit 89cee34181
3 changed files with 86 additions and 71 deletions

View File

@@ -13,6 +13,9 @@ all: deps format
@mkdir -p bin/
@bash --norc -i ./scripts/build.sh
bin: generate
@sh -c "'$(CURDIR)/scripts/build.sh'"
cov:
gocov test ./... | gocov-html > /tmp/coverage.html
open /tmp/coverage.html

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env bash
#!/bin/bash
#
# This script builds the application from source.
# This script builds the application from source for multiple platforms.
set -e
# Get the parent directory of where this script is.
@@ -9,44 +9,75 @@ while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
DIR="$( cd -P "$( dirname "$SOURCE" )/.." && pwd )"
# Change into that directory
cd $DIR
cd "$DIR"
# Get the git commit
GIT_COMMIT=$(git rev-parse HEAD)
GIT_DIRTY=$(test -n "`git status --porcelain`" && echo "+CHANGES" || true)
GIT_DESCRIBE=$(git describe --tags)
# If we're building on Windows, specify an extension
EXTENSION=""
if [ "$(go env GOOS)" = "windows" ]; then
EXTENSION=".exe"
fi
GOPATHSINGLE=${GOPATH%%:*}
if [ "$(go env GOOS)" = "windows" ]; then
GOPATHSINGLE=${GOPATH%%;*}
fi
if [ "$(go env GOOS)" = "freebsd" ]; then
export CC="clang"
fi
# On OSX, we need to use an older target to ensure binaries are
# compatible with older linkers
if [ "$(go env GOOS)" = "darwin" ]; then
export MACOSX_DEPLOYMENT_TARGET=10.6
fi
# 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}
# Install dependencies
echo "--> Installing dependencies to speed up builds..."
go get \
-ldflags "${CGO_LDFLAGS}" \
./...
echo "==> Getting dependencies..."
go get ./...
# Delete the old dir
echo "==> Removing old directory..."
rm -f bin/*
rm -rf pkg/*
mkdir -p bin/
# If its dev mode, only build for ourself
if [ "${NOMAD_DEV}x" != "x" ]; then
XC_OS=$(go env GOOS)
XC_ARCH=$(go env GOARCH)
fi
# Build!
echo "--> Building..."
go build \
-ldflags "${CGO_LDFLAGS} -X main.GitCommit=${GIT_COMMIT}${GIT_DIRTY} -X main.GitDescribe=${GIT_DESCRIBE}" \
-v \
-o bin/nomad${EXTENSION}
cp bin/nomad${EXTENSION} ${GOPATHSINGLE}/bin
echo "==> Building..."
gox \
-os="${XC_OS}" \
-os="!freebsd" \
-os="!openbsd" \
-arch="${XC_ARCH}" \
-ldflags "-X main.GitCommit ${GIT_COMMIT}${GIT_DIRTY}" \
-output "pkg/{{.OS}}_{{.Arch}}/nomad" \
.
# Move all the compiled things to the $GOPATH/bin
GOPATH=${GOPATH:-$(go env GOPATH)}
case $(uname) in
CYGWIN*)
GOPATH="$(cygpath $GOPATH)"
;;
esac
OLDIFS=$IFS
IFS=: MAIN_GOPATH=($GOPATH)
IFS=$OLDIFS
# Copy our OS/Arch to the bin/ directory
DEV_PLATFORM="./pkg/$(go env GOOS)_$(go env GOARCH)"
for F in $(find ${DEV_PLATFORM} -mindepth 1 -maxdepth 1 -type f); do
cp ${F} bin/
cp ${F} ${MAIN_GOPATH}/bin/
done
if [ "${NOMAD_DEV}x" = "x" ]; then
# Zip and copy to the dist dir
echo "==> Packaging..."
for PLATFORM in $(find ./pkg -mindepth 1 -maxdepth 1 -type d); do
OSARCH=$(basename ${PLATFORM})
echo "--> ${OSARCH}"
pushd $PLATFORM >/dev/null 2>&1
zip ../${OSARCH}.zip ./*
popd >/dev/null 2>&1
done
fi
# Done!
echo
echo "==> Results:"
ls -hl bin/

View File

@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
set -e
# Get the version from the command line
@@ -9,7 +9,7 @@ if [ -z $VERSION ]; then
fi
# Make sure we have a bintray API key
if [ -z $BINTRAY_API_KEY ]; then
if [ -z $BINTRAY_API_KEY ] && [ ! -z $NOBINTRAY ]; then
echo "Please set your bintray API key in the BINTRAY_API_KEY env var."
exit 1
fi
@@ -23,45 +23,25 @@ DIR="$( cd -P "$( dirname "$SOURCE" )/.." && pwd )"
cd $DIR
# Zip all the files
rm -rf ./dist/pkg
mkdir -p ./dist/pkg
for FILENAME in $(find ./dist -mindepth 1 -maxdepth 1 -type f); do
rm -rf ./pkg/dist
mkdir -p ./pkg/dist
for FILENAME in $(find ./pkg -mindepth 1 -maxdepth 1 -type f); do
FILENAME=$(basename $FILENAME)
EXTENSION="${FILENAME##*.}"
PLATFORM="${FILENAME%.*}"
if [ "${EXTENSION}" != "exe" ]; then
EXTENSION=""
else
EXTENSION=".${EXTENSION}"
fi
NOMADNAME="nomad${EXTENSION}"
pushd ./dist
if [ "${FILENAME}" = "ui.zip" ]; then
cp ${FILENAME} ./pkg/${VERSION}_web_ui.zip
else
if [ "${EXTENSION}" = "" ]; then
chmod +x ${FILENAME}
fi
cp ${FILENAME} ${NOMADNAME}
zip ./pkg/${VERSION}_${PLATFORM}.zip ${NOMADNAME}
rm ${NOMADNAME}
fi
popd
cp ./pkg/${FILENAME} ./pkg/dist/nomad_${VERSION}_${FILENAME}
done
# Make the checksums
pushd ./dist/pkg
shasum -a256 * > ./${VERSION}_SHA256SUMS
popd
if [ -z $NOSIGN ]; then
echo "==> Signing..."
pushd ./pkg/dist
rm -f ./nomad_${VERSION}_SHA256SUMS*
shasum -a256 * > ./nomad_${VERSION}_SHA256SUMS
gpg --default-key 348FFC4C --detach-sig ./nomad_${VERSION}_SHA256SUMS
popd
fi
# Upload
for ARCHIVE in ./dist/pkg/*; do
if [ ! -z $NOBINTRAY ]; then
for ARCHIVE in ./pkg/dist/*; do
ARCHIVE_NAME=$(basename ${ARCHIVE})
echo Uploading: $ARCHIVE_NAME
@@ -69,6 +49,7 @@ for ARCHIVE in ./dist/pkg/*; do
-T ${ARCHIVE} \
-umitchellh:${BINTRAY_API_KEY} \
"https://api.bintray.com/content/mitchellh/nomad/nomad/${VERSION}/${ARCHIVE_NAME}"
done
done
fi
exit 0