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 |
| 25 | MASTER_REPO=${MASTER_REPO:-https://github.com/openstack-dev/devstack.git} |
| 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 | |
| 31 | # Uses this shocco branch: https://github.com/dtroyer/shocco/tree/rst_support |
| 32 | SHOCCO=${SHOCCO:-shocco} |
| 33 | if ! which shocco; then |
| 34 | if [[ ! -x shocco/shocco ]]; then |
| 35 | if [[ -z "$INSTALL_SHOCCO" ]]; then |
| 36 | echo "shocco not found in \$PATH, please set environment variable SHOCCO" |
| 37 | exit 1 |
| 38 | fi |
| 39 | echo "Installing local copy of shocco" |
| 40 | git clone -b rst_support https://github.com/dtroyer/shocco shocco |
| 41 | cd shocco |
| 42 | ./configure |
| 43 | make |
| 44 | cd .. |
| 45 | fi |
| 46 | SHOCCO=shocco/shocco |
| 47 | fi |
| 48 | |
| 49 | # Process command-line args |
| 50 | while getopts b:p c; do |
| 51 | case $c in |
| 52 | b) MASTER_BRANCH=$OPTARG |
| 53 | ;; |
| 54 | p) PUSH_REPO=1 |
| 55 | ;; |
| 56 | esac |
| 57 | done |
| 58 | shift `expr $OPTIND - 1` |
| 59 | |
| 60 | # Sanity check the args |
| 61 | if [[ "$1" == "." ]]; then |
| 62 | REPO="" |
| 63 | if [[ -n $PUSH_REPO ]]; then |
| 64 | echo "Push not allowed from an active workspace" |
| 65 | unset PUSH_REPO |
| 66 | fi |
| 67 | else |
| 68 | if [[ -z "$1" ]]; then |
| 69 | REPO=$MASTER_REPO |
| 70 | else |
| 71 | REPO=$1 |
| 72 | fi |
| 73 | fi |
| 74 | |
| 75 | # Check out a specific DevStack branch |
| 76 | if [[ -n $REPO ]]; then |
| 77 | # Make a workspace |
| 78 | TMP_ROOT=$(mktemp -d devstack-docs-XXXX) |
| 79 | echo "Building docs in $TMP_ROOT" |
| 80 | cd $TMP_ROOT |
| 81 | |
| 82 | # Get the master branch |
| 83 | git clone $REPO devstack |
| 84 | cd devstack |
| 85 | git checkout $MASTER_BRANCH |
| 86 | fi |
| 87 | |
| 88 | # Processing |
| 89 | # ---------- |
| 90 | |
| 91 | # Assumption is we are now in the DevStack repo workspace to be processed |
| 92 | |
| 93 | # Pull the latest docs branch from devstack.org repo |
| 94 | rm -rf docs || true |
| 95 | git clone -b gh-pages $GH_PAGES_REPO docs |
| 96 | |
| 97 | # Build list of scripts to process |
| 98 | FILES="" |
| 99 | for f in $(find . -name .git -prune -o \( -type f -name \*.sh -not -path \*shocco/\* -print \)); do |
| 100 | echo $f |
| 101 | FILES+="$f " |
| 102 | mkdir -p docs/`dirname $f`; |
| 103 | $SHOCCO $f > docs/$f.html |
| 104 | done |
| 105 | for f in $(find functions lib samples -type f -name \*); do |
| 106 | echo $f |
| 107 | FILES+="$f " |
| 108 | mkdir -p docs/`dirname $f`; |
| 109 | $SHOCCO $f > docs/$f.html |
| 110 | done |
| 111 | echo "$FILES" >docs-files |
| 112 | |
| 113 | # Switch to the gh_pages repo |
| 114 | cd docs |
| 115 | |
| 116 | # Collect the new generated pages |
| 117 | find . -name \*.html -print0 | xargs -0 git add |
| 118 | |
| 119 | # Push our changes back up to the docs branch |
| 120 | if ! git diff-index HEAD --quiet; then |
| 121 | git commit -a -m "Update script docs" |
| 122 | if [[ -n $PUSH ]]; then |
| 123 | git push |
| 124 | fi |
| 125 | fi |
| 126 | |
| 127 | # Clean up or report the temp workspace |
| 128 | if [[ -n REPO && -n $PUSH_REPO ]]; then |
| 129 | rm -rf $TMP_ROOT |
| 130 | else |
| 131 | if [[ -z "$TMP_ROOT" ]]; then |
| 132 | TMP_ROOT="$(pwd)" |
| 133 | fi |
| 134 | echo "Built docs in $TMP_ROOT" |
| 135 | fi |