blob: 1c145e237f0d26a7ee5f9694da7b5d78b38a1f35 [file] [log] [blame]
Dean Troyer9b973672013-10-16 15:13:56 -05001#!/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
25MASTER_REPO=${MASTER_REPO:-https://github.com/openstack-dev/devstack.git}
26MASTER_BRANCH=${MASTER_BRANCH:-master}
27
28# http://devstack.org is a GitHub gh-pages site in the https://github.com/cloudbuilders/devtack.git repo
29GH_PAGES_REPO=git@github.com:cloudbuilders/devstack.git
30
31# Uses this shocco branch: https://github.com/dtroyer/shocco/tree/rst_support
32SHOCCO=${SHOCCO:-shocco}
33if ! 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
47fi
48
49# Process command-line args
50while getopts b:p c; do
51 case $c in
52 b) MASTER_BRANCH=$OPTARG
53 ;;
54 p) PUSH_REPO=1
55 ;;
56 esac
57done
58shift `expr $OPTIND - 1`
59
60# Sanity check the args
61if [[ "$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
67else
68 if [[ -z "$1" ]]; then
69 REPO=$MASTER_REPO
70 else
71 REPO=$1
72 fi
73fi
74
75# Check out a specific DevStack branch
76if [[ -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
86fi
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
Adam Spiers4b2c5ed2013-10-24 17:40:13 +010094if ! [ -d docs ]; then
95 git clone -b gh-pages $GH_PAGES_REPO docs
96fi
Dean Troyer9b973672013-10-16 15:13:56 -050097
98# Build list of scripts to process
99FILES=""
100for f in $(find . -name .git -prune -o \( -type f -name \*.sh -not -path \*shocco/\* -print \)); do
101 echo $f
102 FILES+="$f "
103 mkdir -p docs/`dirname $f`;
104 $SHOCCO $f > docs/$f.html
105done
106for f in $(find functions lib samples -type f -name \*); do
107 echo $f
108 FILES+="$f "
109 mkdir -p docs/`dirname $f`;
110 $SHOCCO $f > docs/$f.html
111done
112echo "$FILES" >docs-files
113
114# Switch to the gh_pages repo
115cd docs
116
117# Collect the new generated pages
118find . -name \*.html -print0 | xargs -0 git add
119
120# Push our changes back up to the docs branch
121if ! git diff-index HEAD --quiet; then
122 git commit -a -m "Update script docs"
123 if [[ -n $PUSH ]]; then
124 git push
125 fi
126fi
127
128# Clean up or report the temp workspace
129if [[ -n REPO && -n $PUSH_REPO ]]; then
130 rm -rf $TMP_ROOT
131else
132 if [[ -z "$TMP_ROOT" ]]; then
133 TMP_ROOT="$(pwd)"
134 fi
135 echo "Built docs in $TMP_ROOT"
136fi