Created
October 10, 2016 04:23
-
-
Save sungwoncho/c825765b703c2e2fa677c6486b0eb1de to your computer and use it in GitHub Desktop.
This file contains 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
#!/bin/bash | |
# Store the filenames of previous build | |
PREVIOUS_BUILD=(./static/dist/*) | |
function fetch { | |
echo "###### Fetching..." | |
git pull origin prod | |
git checkout prod | |
} | |
function build_client { | |
echo "###### Building client..." | |
npm install | |
npm run build-client | |
} | |
function start_server { | |
echo "###### Restarting the server..." | |
pm2 stop app | |
pm2 start ./start.sh --name "app" | |
echo "###### Successfully finished deployment" | |
} | |
function clean_up_previous_build { | |
echo "###### Cleaning up previous build" | |
regex="([a-zA-Z_0-9]+)-([0-9a-z]+)\.(.*)" | |
for file in "${PREVIOUS_BUILD[@]}" | |
do | |
if [[ $file =~ $regex ]] | |
then | |
filename="${BASH_REMATCH[1]}" | |
hash="${BASH_REMATCH[2]}" | |
ext="${BASH_REMATCH[3]}" | |
if test -n "$(find ./static/dist -name "${filename}-[0-9a-z]*\.${ext}" ! -name "${filename}-${hash}*")" | |
then | |
# A newly generated file exists. Remove the old file. | |
rm "${file}" | |
fi | |
fi | |
done | |
} | |
function tag_release { | |
echo "###### Tagging the new release" | |
VERSION=`git describe --abbrev=0 --tags` | |
VERSION_BITS=(${VERSION//./ }) | |
VNUM1=${VERSION_BITS[0]} | |
VNUM2=${VERSION_BITS[1]} | |
VNUM3=${VERSION_BITS[2]} | |
VNUM3=$(($VNUM3+1)) | |
NEW_TAG="$VNUM1.$VNUM2.$VNUM3" | |
echo "Updating $VERSION to $NEW_TAG" | |
git tag $NEW_TAG | |
git push --tags | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment