Dean Troyer | 9b97367 | 2013-10-16 15:13:56 -0500 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # **build_docs.sh** - Build the gh-pages docs for DevStack |
| 4 | # |
| 5 | # - Install shocco if not found on PATH |
| 6 | # - Clone MASTER_REPO branch MASTER_BRANCH |
| 7 | # - Re-creates ``docs`` directory from existing repo + new generated script docs |
| 8 | |
| 9 | # Usage: |
| 10 | ## build_docs.sh [[-b branch] [-p] repo] | . |
| 11 | ## -b branch The DevStack branch to check out (default is master; ignored if |
| 12 | ## repo is not specified) |
| 13 | ## -p Push the resulting docs tree to the source repo; fatal error if |
| 14 | ## repo is not specified |
| 15 | ## repo The DevStack repository to clone (default is DevStack github repo) |
| 16 | ## If a repo is not supplied use the current directory |
| 17 | ## (assumed to be a DevStack checkout) as the source. |
| 18 | ## . Use the current repo and branch (do not use with -p to |
| 19 | ## prevent stray files in the workspace being added tot he docs) |
| 20 | |
| 21 | # Defaults |
| 22 | # -------- |
| 23 | |
| 24 | # Source repo/branch for DevStack |
Sphoorti Joglekar | ce365ce | 2014-04-01 19:47:40 +0530 | [diff] [blame] | 25 | MASTER_REPO=${MASTER_REPO:-git://git.openstack.org/openstack-dev/devstack} |
Dean Troyer | 9b97367 | 2013-10-16 15:13:56 -0500 | [diff] [blame] | 26 | MASTER_BRANCH=${MASTER_BRANCH:-master} |
| 27 | |
| 28 | # http://devstack.org is a GitHub gh-pages site in the https://github.com/cloudbuilders/devtack.git repo |
| 29 | GH_PAGES_REPO=git@github.com:cloudbuilders/devstack.git |
| 30 | |
Dean Troyer | c04ddbe | 2013-11-06 02:15:11 -0600 | [diff] [blame] | 31 | # Keep track of the devstack directory |
| 32 | TOP_DIR=$(cd $(dirname "$0")/.. && pwd) |
| 33 | |
Dean Troyer | 9b97367 | 2013-10-16 15:13:56 -0500 | [diff] [blame] | 34 | # Uses this shocco branch: https://github.com/dtroyer/shocco/tree/rst_support |
| 35 | SHOCCO=${SHOCCO:-shocco} |
| 36 | if ! which shocco; then |
Dean Troyer | c04ddbe | 2013-11-06 02:15:11 -0600 | [diff] [blame] | 37 | if [[ ! -x $TOP_DIR/shocco/shocco ]]; then |
Dean Troyer | 9b97367 | 2013-10-16 15:13:56 -0500 | [diff] [blame] | 38 | if [[ -z "$INSTALL_SHOCCO" ]]; then |
| 39 | echo "shocco not found in \$PATH, please set environment variable SHOCCO" |
| 40 | exit 1 |
| 41 | fi |
| 42 | echo "Installing local copy of shocco" |
Dean Troyer | c04ddbe | 2013-11-06 02:15:11 -0600 | [diff] [blame] | 43 | if ! which pygmentize; then |
| 44 | sudo pip install Pygments |
| 45 | fi |
| 46 | if ! which rst2html.py; then |
| 47 | sudo pip install docutils |
| 48 | fi |
Dean Troyer | 9b97367 | 2013-10-16 15:13:56 -0500 | [diff] [blame] | 49 | git clone -b rst_support https://github.com/dtroyer/shocco shocco |
| 50 | cd shocco |
| 51 | ./configure |
| 52 | make |
| 53 | cd .. |
| 54 | fi |
Dean Troyer | c04ddbe | 2013-11-06 02:15:11 -0600 | [diff] [blame] | 55 | SHOCCO=$TOP_DIR/shocco/shocco |
Dean Troyer | 9b97367 | 2013-10-16 15:13:56 -0500 | [diff] [blame] | 56 | fi |
| 57 | |
| 58 | # Process command-line args |
| 59 | while getopts b:p c; do |
| 60 | case $c in |
| 61 | b) MASTER_BRANCH=$OPTARG |
| 62 | ;; |
| 63 | p) PUSH_REPO=1 |
| 64 | ;; |
| 65 | esac |
| 66 | done |
| 67 | shift `expr $OPTIND - 1` |
| 68 | |
| 69 | # Sanity check the args |
| 70 | if [[ "$1" == "." ]]; then |
| 71 | REPO="" |
| 72 | if [[ -n $PUSH_REPO ]]; then |
| 73 | echo "Push not allowed from an active workspace" |
| 74 | unset PUSH_REPO |
| 75 | fi |
| 76 | else |
| 77 | if [[ -z "$1" ]]; then |
| 78 | REPO=$MASTER_REPO |
| 79 | else |
| 80 | REPO=$1 |
| 81 | fi |
| 82 | fi |
| 83 | |
| 84 | # Check out a specific DevStack branch |
| 85 | if [[ -n $REPO ]]; then |
| 86 | # Make a workspace |
| 87 | TMP_ROOT=$(mktemp -d devstack-docs-XXXX) |
| 88 | echo "Building docs in $TMP_ROOT" |
| 89 | cd $TMP_ROOT |
| 90 | |
| 91 | # Get the master branch |
| 92 | git clone $REPO devstack |
| 93 | cd devstack |
| 94 | git checkout $MASTER_BRANCH |
| 95 | fi |
| 96 | |
| 97 | # Processing |
| 98 | # ---------- |
| 99 | |
| 100 | # Assumption is we are now in the DevStack repo workspace to be processed |
| 101 | |
| 102 | # Pull the latest docs branch from devstack.org repo |
Adam Spiers | 4b2c5ed | 2013-10-24 17:40:13 +0100 | [diff] [blame] | 103 | if ! [ -d docs ]; then |
| 104 | git clone -b gh-pages $GH_PAGES_REPO docs |
| 105 | fi |
Dean Troyer | 9b97367 | 2013-10-16 15:13:56 -0500 | [diff] [blame] | 106 | |
| 107 | # Build list of scripts to process |
| 108 | FILES="" |
| 109 | for f in $(find . -name .git -prune -o \( -type f -name \*.sh -not -path \*shocco/\* -print \)); do |
| 110 | echo $f |
| 111 | FILES+="$f " |
| 112 | mkdir -p docs/`dirname $f`; |
| 113 | $SHOCCO $f > docs/$f.html |
| 114 | done |
| 115 | for f in $(find functions lib samples -type f -name \*); do |
| 116 | echo $f |
| 117 | FILES+="$f " |
| 118 | mkdir -p docs/`dirname $f`; |
| 119 | $SHOCCO $f > docs/$f.html |
| 120 | done |
| 121 | echo "$FILES" >docs-files |
| 122 | |
| 123 | # Switch to the gh_pages repo |
| 124 | cd docs |
| 125 | |
| 126 | # Collect the new generated pages |
| 127 | find . -name \*.html -print0 | xargs -0 git add |
| 128 | |
| 129 | # Push our changes back up to the docs branch |
| 130 | if ! git diff-index HEAD --quiet; then |
| 131 | git commit -a -m "Update script docs" |
| 132 | if [[ -n $PUSH ]]; then |
| 133 | git push |
| 134 | fi |
| 135 | fi |
| 136 | |
| 137 | # Clean up or report the temp workspace |
| 138 | if [[ -n REPO && -n $PUSH_REPO ]]; then |
| 139 | rm -rf $TMP_ROOT |
| 140 | else |
| 141 | if [[ -z "$TMP_ROOT" ]]; then |
| 142 | TMP_ROOT="$(pwd)" |
| 143 | fi |
| 144 | echo "Built docs in $TMP_ROOT" |
| 145 | fi |