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