Skip to content

Commit

Permalink
Adding build-release.sh script
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenneth Shaw committed Mar 6, 2017
1 parent ce8da83 commit 103e4dd
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/usql
/build

.usql_history*

Expand Down
85 changes: 85 additions & 0 deletions contrib/build-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/bin/bash

VER=$1
BUILD=$2

if [ -z "$VER" ]; then
echo "usage: $0 <VER>"
exit 1
fi

PLATFORM=$(uname|sed -e 's/_.*//'|tr '[:upper:]' '[:lower:]')

TAG=v$VER
SRC=$(realpath $(cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/../)
NAME=$(basename $SRC)

PLAT=$PLATFORM
case $PLAT in
mingw64)
PLAT=windows
;;
esac

if [ -z "$BUILD" ]; then
BUILD=$SRC/build
if [ "$PLATFORM" == "mingw64" ]; then
BUILD=$HOME/$NAME
fi
fi

EXT=tar
if [ "$PLATFORM" == "mingw64" ]; then
EXT=zip
fi

DIR=$BUILD/$PLATFORM/$VER
BIN=$DIR/$NAME
OUT=$DIR/usql-$VER-$PLAT-amd64.$EXT

rm -rf $DIR
mkdir -p $DIR

if [ "$PLATFORM" == "mingw64" ]; then
BIN=$BIN.exe
fi

echo "PLATFORM: $PLATFORM"
echo "VER: $VER"
echo "DIR: $DIR"
echo "BIN: $BIN"
echo "OUT: $OUT"

set -e

pushd $SRC &> /dev/null

if [ "$PLATFORM" != "mingw64" ]; then
git checkout $TAG
fi

go build -ldflags="-X main.name=$NAME -X main.version=$VER" -o $BIN

if [ "$PLATFORM" != "mingw64" ]; then
echo "stripping $BIN"
strip $BIN
fi

echo "packing $BIN"
upx -q -q $BIN

echo "compressing $OUT"
case $EXT in
zip)
zip $OUT -j $BIN
;;
tar)
tar -C $DIR -cjvf $OUT.bz2 $(basename $BIN)
;;
esac

if [ "$PLATFORM" == "mingw64" ]; then
cp $OUT 'f:\'
fi

popd &> /dev/null
10 changes: 10 additions & 0 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ func (a *Args) Description() string {
return aboutDesc
}

var (
name = "usql"
version = "0.0.0-dev"
)

// Version returns the version string for the app.
func (a *Args) Version() string {
return name + " " + version
}

// startsWith checks that s begins with the specified prefix and is followed by
// at least one space, returning the remaining string trimmed of spaces.
//
Expand Down

0 comments on commit 103e4dd

Please sign in to comment.