11#! /bin/bash
22
3- # Many aspects of this came from https://gist.github.com/domenic/ec8b0fc8ab45f39403dd
3+ # Based on `push_docs_to_gh_pages.sh`
44# Significant alterations
55# - Support for multiple copies of documentation,
66# - only clearing out develop
1313# - File: "docs/index.md" with that contains develop docs
1414
1515# Required ENV Variables
16- PAGES_TARGET_BRANCH=" gh-pages"
1716LATEST_DOCS_BRANCH=" develop"
17+ GITHUB_IO_REPO=' jgebal/jgebal.github.io'
18+ GITHUB_IO_BRANCH=' master'
19+
1820# TRAVIS_* variables are set by travis directly and only need to be if testing externally
1921
20- # We don't want a pull request automatically updating the repository
22+ # We deploy only when building on develop branch or on TAG (release)
2123if [ " $TRAVIS_PULL_REQUEST " == " false" ] && { [ " ${CURRENT_BRANCH} " == " ${LATEST_DOCS_BRANCH} " ] || [ -n " ${TRAVIS_TAG} " ]; }; then
2224
2325 # ENV Variable checks are to help with configuration troubleshooting, they silently exit with unique message.
2426 # Anyone one of them not set can be used to turn off this functionality.
2527
2628 # If a version of the project is not defined
27- [[ -n " ${UTPLSQL_VERSION} " ]] || { echo " variable UTPLSQL_VERSION is not defines or missing value" ; exit 0 ; }
29+ [[ -n " ${UTPLSQL_VERSION} " ]] || { echo " variable UTPLSQL_VERSION is not defines or missing value" ; exit 1 ; }
2830 # Fail if the markdown documentation is not present.
2931 [[ -f ./docs/index.md ]] || { echo " file docs/index.md not found" ; exit 1; }
3032
31- # Save some useful information
33+ # Store latest commit SHA to be used when committing and pushing to github.io repo
3234 SHA=` git rev-parse --verify HEAD`
3335
34- # clone the repository and switch to PAGES_TARGET_BRANCH branch
36+ # clone the repository and switch to GITHUB_IO_BRANCH branch
3537 mkdir pages
36- cd pages
37- git clone https://${github_api_token} @github.com/${UTPLSQL_REPO} .
38-
39- PAGES_BRANCH_EXISTS=$( git ls-remote --heads origin ${PAGES_TARGET_BRANCH} )
38+ cd ./pages
39+ git clone --depth 1 https://${github_api_token} @github.com/${GITHUB_IO_REPO} -b ${GITHUB_IO_BRANCH} .
4040
41- if [ -n " $PAGES_BRANCH_EXISTS " ] ; then
42- echo " Pages Branch Found"
43- git checkout ${PAGES_TARGET_BRANCH}
44- else
45- echo " Creating Pages Branch"
46- git checkout --orphan ${PAGES_TARGET_BRANCH}
47- git rm -rf .
48- fi
41+ mkdir -p utPLSQL
42+ cd ./utPLSQL
4943 # clear out develop documentation directory and copy docs contents to it.
50- echo " updating 'develop' directory"
51- mkdir -p develop
52- rm -rf develop/** ./* || exit 0
53- cp -a ../docs/. ./develop
44+ echo " updating 'develop' documentation directory"
45+ mkdir -p ./develop
46+ rm -rf ./develop/** ./* || exit 0
47+ cp -a ../../docs/. ./develop
48+
5449 # If a Tagged Build then copy to it's own directory as well and to the 'latest' release directory
5550 if [ -n " $TRAVIS_TAG " ]; then
56- echo " Creating ${UTPLSQL_VERSION} "
57- mkdir -p ${UTPLSQL_VERSION}
58- rm -rf ${UTPLSQL_VERSION} /** ./* || exit 0
59- cp -a ../docs/. ${UTPLSQL_VERSION}
60- echo " Populating 'latest' directory"
61- mkdir -p latest
62- rm -rf latest/** ./* || exit 0
63- cp -a ../docs/. latest
51+ echo " Creating directory ./ ${UTPLSQL_VERSION} "
52+ mkdir -p ./ ${UTPLSQL_VERSION}
53+ rm -rf ./ ${UTPLSQL_VERSION} /** ./* || exit 0
54+ cp -a ../../ docs/. ./ ${UTPLSQL_VERSION}
55+ echo " Populating 'latest' directory"
56+ mkdir -p ./ latest
57+ rm -rf ./ latest/** ./* || exit 0
58+ cp -a ../../ docs/. ./ latest
6459 fi
6560 # Stage changes for commit
6661 git add .
62+
6763 # Check if there are doc changes, if none exit the script
68- if [[ -z ` git diff HEAD --exit-code` ]] && [ -n " ${PAGES_BRANCH_EXISTS} " ] ; then
64+ if [[ -z ` git diff HEAD --exit-code` ]]; then
6965 echo " No changes to docs detected."
7066 exit 0
7167 fi
@@ -75,7 +71,7 @@ if [ "$TRAVIS_PULL_REQUEST" == "false" ] && { [ "${CURRENT_BRANCH}" == "${LATEST
7571 echo " ---" >> index.md
7672 echo " layout: default" >> index.md
7773 echo " ---" >> index.md
78- echo " <!-- Auto generated from .travis/push_docs_to_gh_pages .sh -->" >> index.md
74+ echo " <!-- Auto generated from .travis/push_docs_to_github_io .sh -->" >> index.md
7975 echo " # Documentation versions" >> index.md
8076 echo " " >> index.md
8177 echo " " >> index.md # - 7th line - placeholder for latest release doc
@@ -96,6 +92,6 @@ if [ "$TRAVIS_PULL_REQUEST" == "false" ] && { [ "${CURRENT_BRANCH}" == "${LATEST
9692 git add .
9793 git commit -m " Deploy to gh-pages branch: base commit ${SHA} "
9894 # Now that we're all set up, we can push.
99- git push --quiet origin HEAD:${PAGES_TARGET_BRANCH }
95+ git push --quiet origin HEAD:${GITHUB_IO_BRANCH }
10096fi
10197
0 commit comments