Safer docs/ build process: into own folder
authorSergey Karayev <sergeykarayev@gmail.com>
Tue, 25 Feb 2014 19:09:39 +0000 (11:09 -0800)
committerSergey Karayev <sergeykarayev@gmail.com>
Tue, 25 Feb 2014 19:13:32 +0000 (11:13 -0800)
build_and_deploy_docs.sh [new file with mode: 0755]
docs/build_and_deploy_docs.sh [deleted file]

diff --git a/build_and_deploy_docs.sh b/build_and_deploy_docs.sh
new file mode 100755 (executable)
index 0000000..b9de295
--- /dev/null
@@ -0,0 +1,35 @@
+echo "The remote from which you will submit the PR to BVLC:gh-pages must be called 'origin'"
+echo "To build and view docs when not on master, simply do 'jekyll serve -s docs'."
+echo
+
+ORIGIN=`git config --get remote.origin.url`
+BRANCH=`git rev-parse --abbrev-ref HEAD`
+MSG=`git log --oneline -1`
+
+if [ $BRANCH='master' ]; then
+    # Make sure that docs/_site tracks remote:gh-pages.
+    # If not, then we make a new repo and check out just that branch.
+    mkdir docs/_site
+    cd docs/_site
+    SITE_ORIGIN=`git config --get remote.origin.url`
+    SITE_BRANCH=`git rev-parse --abbrev-ref HEAD`
+
+    if [ $SITE_ORIGIN=$ORIGIN ] && [ $SITE_BRANCH='gh-pages' ]; then
+        echo "Confirmed that docs/_site has same origin as main repo, and is on gh-pages."
+    else
+        echo "Checking out origin:gh-pages into docs/_site."
+        git init
+        git remote add -t gh-pages -f origin $ORIGIN
+        git co gh-pages
+    fi
+
+    echo "Building the site into docs/_site, and committing the changes."
+    jekyll build -s .. -d .
+    git add --all .
+    git commit -m "$MSG"
+    git push origin gh-pages
+
+    echo "All done!"
+    cd ../..
+else echo "You must run this deployment script from the 'master' branch."
+fi
diff --git a/docs/build_and_deploy_docs.sh b/docs/build_and_deploy_docs.sh
deleted file mode 100644 (file)
index db02c33..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-echo "This script builds docs/ and deploys the site to origin/gh-pages."
-echo "It must be run from master branch, or nothing will happen."
-echo ""
-echo "COMMIT YOUR WORK BEFORE RUNNING THIS."
-echo "This will delete *all* uncomitted files."
-read -p "Have you committed (y/n)? " -n 1 -r
-echo    # (optional) move to a new line
-if [[ ! $REPLY =~ ^[Yy]$ ]]
-then
-    exit 1
-fi
-
-CUR_BRANCH=`git rev-parse --abbrev-ref HEAD`
-MSG=`git log --oneline -1`
-
-if [ $CUR_BRANCH='master' ]; then
-    jekyll build -s docs
-    git checkout gh-pages
-
-    # Need to make sure that gh-pages is a valid branch!
-    CUR_BRANCH=`git rev-parse --abbrev-ref HEAD`
-    if [ $CUR_BRANCH='gh-pages' ]; then
-        git rm -qr .
-        cp -r _site/. .
-        rm -r _site
-        git add -A
-        git commit -m "$MSG"
-        git push origin gh-pages
-        git checkout master
-    fi
-fi