#!/bin/bash

GEM_SERVER=https://int.jamkazam.com:9000/gems
DEB_SERVER=https://int.jamkazam.com:9010/apt-`uname -p`

echo "starting build..."
./build

if [ "$?" = "0" ]; then
    echo "build succeeded"


    # generate gem version based on jenkins build number
    if [ -z $BUILD_NUMBER ]; then
        BUILD_NUMBER="1"
    fi
    VERSION="0.1.${BUILD_NUMBER}"
    echo "packaging gem jam_websockets-$VERSION"
    cat > lib/jam_websockets/version.rb << EOF
module JamWebsockets
  VERSION = "$VERSION"
end
EOF

    gem build jam_websockets.gemspec

    GEMNAME="jam_websockets-${VERSION}.gem"

    echo "publishing gem"
    curl -f -T $GEMNAME $GEM_SERVER/$GEMNAME

    if [ "$?" != "0" ]; then
        echo "gem publish failed"
        exit 1
    fi
    echo "done publishing gem"
else
    echo "build failed"
    exit 1
fi



