Created
January 20, 2015 23:03
-
-
Save Platane/efbbe60bf326f905499b to your computer and use it in GitHub Desktop.
deploy,sh
This file contains hidden or 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/sh | |
# deploy script | |
# default options | |
incr="0.0.1" | |
versionMessage="" | |
# parse option | |
while getopts i:m: opt; do | |
case $opt in | |
i) | |
incr=$OPTARG | |
;; | |
i) | |
versionMessage=$OPTARG | |
;; | |
esac | |
done | |
# grab the current version | |
oldVersion=`cat package.json | grep version | sed -e "s/.*\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*/\1/"` | |
# bump version | |
newVersion="" | |
i=1 | |
zero=0 | |
while [ $i -le 3 ] | |
do | |
u=`echo $incr | cut -d . -f $i` | |
v=`echo $oldVersion | cut -d . -f $i` | |
if [ $zero != 0 ] ; then | |
newVersion="$newVersion.0" | |
elif [ "$u" != "0" ] ; then | |
newVersion="$newVersion.$(( $v + 1 ))" | |
zero=1 | |
else | |
newVersion="$newVersion.$v" | |
fi | |
i=$(( $i + 1 )) | |
done | |
newVersion=${newVersion:1} | |
# ask for comfirmation | |
echo "--- going to bump from $oldVersion to $newVersion" | |
echo "Is that alright ?" | |
read comfirm | |
if [ "$comfirm" != "" ] && [ "$comfirm" != "y" ] && [ "$comfirm" != "Y" ]; then | |
exit 0 | |
fi | |
# switch branch | |
echo "------" | |
echo "Switching branch" | |
echo "------" | |
echo "" | |
git fetch | |
git stash | |
git checkout gh-pages | |
git checkout master -- . | |
git reset | |
echo "------" | |
echo "Building" | |
echo "------" | |
echo "" | |
npm install | |
# TODO production build ( minify, no debug mode in browsersify ) | |
node ./node_modules/gulp/bin/gulp.js build | |
# edit gitignore | |
echo "js | |
css | |
test | |
node_modules | |
npm-debug.log | |
.tmp | |
.travis.yml | |
gulpFile.js | |
deploy.sh | |
package.json | |
!js/bundle.js | |
!css/style.css" > .gitignore | |
# TODO rm stuff, in order to detetect anomalies in sanity check | |
# refresh after edit gitignore | |
git rm -r . --cached > .tmp | |
git add . > .tmp | |
# TODO fix this, the exception in gitignore dont seems to work | |
git add -f css/style.css js/bundle.js | |
# status | |
git status | |
echo "Is the version sane ?" | |
read comfirm | |
if [ "$comfirm" != "" ] && [ "$comfirm" != "y" ] && [ "$comfirm" != "Y" ] ; then | |
exit 0 | |
fi | |
# commit | |
git commit -m "v$newVersion | |
$versionMessage" | |
# write new version in master | |
git checkout master | |
# TODO fix the sed regexp | |
cat package.json | sed -e 's/.*version.*/ \"version\" : \"$newVersion\",/' > .tmp | |
cat .tmp > package.json | |
git add package.json | |
git commit -m "v$newVersion | |
$versionMessage" | |
# tag ? | |
echo "tag master ?" | |
read comfirm | |
if [ "$comfirm" == "" ] || [ "$comfirm" == "y" ] || [ "$comfirm" == "Y" ] ; then | |
# TODO | |
echo "TODO" | |
fi | |
# tag ? | |
echo "push ?" | |
read comfirm | |
if [ "$comfirm" == "" ] || [ "$comfirm" == "y" ] || [ "$comfirm" == "Y" ] ; then | |
git push | |
git checkout gh-pages | |
git push | |
git checkout master | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment