diff options
author | Ryota MIBU <r-mibu@cq.jp.nec.com> | 2016-07-20 22:04:43 +0900 |
---|---|---|
committer | Ryota Mibu <r-mibu@cq.jp.nec.com> | 2016-07-22 11:59:42 +0000 |
commit | f59a2d4f1c5655e5ec4f3ab5fe70932ac2fa94f0 (patch) | |
tree | 7051de9f4a7e45631ae33ba0a5f8ecfed39a01ab | |
parent | a3174cb38b1dc22802da837d1bd0c3e117b9f43a (diff) |
support pre-hook in docs-build.sh
Some projects need special pre steps before executing docs-build.sh .
For instance, opnfvdocs needs to download other repos which will be
composited. Also, apidoc creation is needed during docs build in
yardstick.
In order to support such cases, this patch introduces pre-hook in
docs-build.sh that provides much flexibility to projects and
simplifies job definition in releng.
Change-Id: If9f26c490671ec0788dc48dd4fccb4513d0ca777
Signed-off-by: Ryota MIBU <r-mibu@cq.jp.nec.com>
-rwxr-xr-x | build-composite.sh | 110 | ||||
-rwxr-xr-x | docs/pre-hook.sh | 112 | ||||
-rwxr-xr-x | scripts/docs-build.sh | 20 |
3 files changed, 127 insertions, 115 deletions
diff --git a/build-composite.sh b/build-composite.sh index 48bcda061..f8d8c242f 100755 --- a/build-composite.sh +++ b/build-composite.sh @@ -8,114 +8,4 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -set -o errexit -set -o nounset -set -o pipefail -set -o xtrace - -GIT_CLONE_BASE=${GIT_CLONE_BASE:-ssh://gerrit.opnfv.org:29418} -GERRIT_BRANCH=${GERRIT_BRANCH:-master} -WORKSPACE=${WORKSPACE:-/tmp} - -get_repo_names() { - # NOTE: Not all repositories are ready for the composite docs, - # so we have the repo name list here to add project docs - # one by one. This will be replaced by the list in project.cfg . - # grep -v '^#' releng/jjb/opnfvdocs/project.cfg | sort - echo "apex" - echo "bottlenecks" - echo "compass4nfv" - echo "copper" - echo "doctor" - echo "fastpathmetrics" - echo "fuel" - echo "functest" - echo "ipv6" - echo "joid" - echo "ovsnfv" - echo "pharos" - echo "prediction" - echo "promise" - echo "sdnvpn" - echo "vswitchperf" - echo "yardstick" -} - -git_clone() { - _repo="$1" - - [[ -d "$WORKSPACE/$_repo" ]] && return 0 - pushd $WORKSPACE - git clone -b $GERRIT_BRANCH --depth 1 --quiet $GIT_CLONE_BASE/$_repo - popd -} - -repos=$(get_repo_names) - -[[ -e docs/projects ]] && rm -rf docs/projects -mkdir -p docs/projects - -echo -echo "Cloning repos of participating OPNFV Projects and copying docs" -echo -for repo in $repos; do - echo " $repo ($GERRIT_BRANCH)" - git_clone $repo - [[ -e $WORKSPACE/$repo/docs ]] || continue - [[ -e docs/projects/$repo ]] && rm -rf docs/projects/$repo - cp -r $WORKSPACE/$repo/docs docs/projects/$repo -done - -# NOTE: Removing index.rst in project repos to reduce number of docs. -find docs/projects -type f -name 'index.rst' -print | xargs -I i rm -f i - -# fix relative file paths -pattern='.. \(include\|figure\):: *[^ \/]' -base_path="/$(pwd)/docs_build/_src" -find docs/projects -type f -name '*.rst' -print | while read f -do - sed -i -e "/$pattern/s|:: *|:: $base_path/$(dirname ${f#docs/})/|" $f -done - -# for debug -grep -e '.. include::' -e '.. figure::' -r docs/projects - -# NOTE: automated link generation is not ready... -echo -echo "Creating document links" -echo -targets=" -configurationguide/configuration.options.render.rst -configurationguide/scenario.description.rst -userguide/feature.userguide.render.rst -testframework/framework.installation.procedure.render.rst -testframework/framework.userguide.render.rst -" -# configurationguide/post-install.rst -for guide in $targets -do - mainfile="$WORKSPACE/docs/$guide" - basefilename=$(basename ${guide/-/}) - for repo in $repos - do - targetfile="$WORKSPACE/docs/projects/$repo/${guide/-/}" - targetlink="../projects/$repo/${guide/-/}" - projectfilename="${basefilename/.rst/-$repo.rst}" - projectfile="$(dirname $mainfile)/$projectfilename" - [[ -e "$targetfile" ]] || continue - echo "Adding $repo to $guide ..." - echo "" >> $mainfile - echo ".. toctree::" >> $mainfile - echo "" >> $mainfile - echo " $projectfilename" >> $mainfile - echo ".. include:: $targetlink" > $projectfile - done - echo - echo "Generated $guide:" - cat $mainfile - echo -done - OPNFVDOCS_DIR=. ./scripts/docs-build.sh - -echo "Done" diff --git a/docs/pre-hook.sh b/docs/pre-hook.sh new file mode 100755 index 000000000..cdfc4f683 --- /dev/null +++ b/docs/pre-hook.sh @@ -0,0 +1,112 @@ +#!/bin/bash +# SPDX-license-identifier: Apache-2.0 +############################################################################## +# Copyright (c) 2016 NEC and others. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +GIT_CLONE_BASE=${GIT_CLONE_BASE:-ssh://gerrit.opnfv.org:29418} +GERRIT_BRANCH=${GERRIT_BRANCH:-master} +WORKSPACE=${WORKSPACE:-.} + +get_repo_names() { + # NOTE: Not all repositories are ready for the composite docs, + # so we have the repo name list here to add project docs + # one by one. This will be replaced by the list in project.cfg . + # grep -v '^#' releng/jjb/opnfvdocs/project.cfg | sort + echo "apex" + echo "bottlenecks" + echo "compass4nfv" + echo "copper" + echo "doctor" + echo "fastpathmetrics" + echo "fuel" + echo "functest" + echo "ipv6" + echo "joid" + echo "ovsnfv" + echo "pharos" + echo "prediction" + echo "promise" + echo "sdnvpn" + echo "vswitchperf" + echo "yardstick" +} + +git_clone() { + _repo="$1" + + [[ -d "$WORKSPACE/$_repo" ]] && return 0 + pushd $WORKSPACE + git clone -b $GERRIT_BRANCH --depth 1 --quiet $GIT_CLONE_BASE/$_repo + popd +} + +repos=$(get_repo_names) + +[[ -e docs/projects ]] && rm -rf docs/projects +mkdir -p docs/projects + +echo +echo "Cloning repos of participating OPNFV Projects and copying docs" +echo +for repo in $repos; do + echo " $repo ($GERRIT_BRANCH)" + git_clone $repo + [[ -e $WORKSPACE/$repo/docs ]] || continue + [[ -e docs/projects/$repo ]] && rm -rf docs/projects/$repo + cp -r $WORKSPACE/$repo/docs docs/projects/$repo +done + +# NOTE: Removing index.rst in project repos to reduce number of docs. +find docs/projects -type f -name 'index.rst' -print | xargs -I i rm -f i + +# fix relative file paths +pattern='.. \(include\|figure\):: *[^ \/]' +base_path="/$(pwd)/docs_build/_src" +find docs/projects -type f -name '*.rst' -print | while read f +do + sed -i -e "/$pattern/s|:: *|:: $base_path/$(dirname ${f#docs/})/|" $f +done + +# for debug +grep -e '.. include::' -e '.. figure::' -r docs/projects + +# NOTE: automated link generation is not ready... +echo +echo "Creating document links" +echo +targets=" +configurationguide/configuration.options.render.rst +configurationguide/scenario.description.rst +userguide/feature.userguide.render.rst +testframework/framework.installation.procedure.render.rst +testframework/framework.userguide.render.rst +" +# configurationguide/post-install.rst +for guide in $targets +do + mainfile="$WORKSPACE/docs/$guide" + basefilename=$(basename ${guide/-/}) + for repo in $repos + do + targetfile="$WORKSPACE/docs/projects/$repo/${guide/-/}" + targetlink="../projects/$repo/${guide/-/}" + projectfilename="${basefilename/.rst/-$repo.rst}" + projectfile="$(dirname $mainfile)/$projectfilename" + [[ -e "$targetfile" ]] || continue + echo "Adding $repo to $guide ..." + echo "" >> $mainfile + echo ".. toctree::" >> $mainfile + echo "" >> $mainfile + echo " $projectfilename" >> $mainfile + echo ".. include:: $targetlink" > $projectfile + done + echo + echo "Generated $guide:" + cat $mainfile + echo +done diff --git a/scripts/docs-build.sh b/scripts/docs-build.sh index f95dd481d..afa68ec65 100755 --- a/scripts/docs-build.sh +++ b/scripts/docs-build.sh @@ -1,4 +1,4 @@ -#!/bin/bash -e +#!/bin/bash # SPDX-license-identifier: Apache-2.0 ############################################################################## # Copyright (c) 2016 NEC and others. @@ -7,7 +7,6 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -export PATH=$PATH:/usr/local/bin/ DOCS_DIR=${DOCS_DIR:-docs} INDEX_RST=${INDEX_RST:-index.rst} @@ -58,7 +57,9 @@ function check_rst_doc() { echo echo -e "$_msg\n$_errs" echo - [[ -n "$GERRIT_COMMENT" ]] && echo -e "$_msg\n$_errs" >> "$GERRIT_COMMENT" + if [ -n "$GERRIT_COMMENT" ]; then + echo -e "$_msg\n$_errs" >> "$GERRIT_COMMENT" + fi } } @@ -82,7 +83,9 @@ function add_html_notes() { function prepare_src_files() { mkdir -p "$(dirname $SRC_DIR)" - [[ -e "$SRC_DIR" ]] && rm -rf "$SRC_DIR" + if [ -e "$SRC_DIR" ]; then + rm -rf "$SRC_DIR" + fi cp -r "$DOCS_DIR" "$SRC_DIR" add_html_notes "$SRC_DIR" } @@ -187,6 +190,11 @@ fi virtualenv "$VENV_DIR" source "$VENV_DIR/bin/activate" + +if [ -e "$DOCS_DIR/pre-hook.sh" ]; then + source "$DOCS_DIR/pre-hook.sh" +fi + pip install -r "$OPNFVDOCS_DIR/etc/requirements.txt" find $DOCS_DIR -name $INDEX_RST -printf '%h\n' | while read dir @@ -227,7 +235,9 @@ do echo echo "$msg" echo - [[ -n "$GERRIT_COMMENT" ]] && echo "$msg" >> "$GERRIT_COMMENT" + if [ -n "$GERRIT_COMMENT" ]; then + echo "$msg" >> "$GERRIT_COMMENT" + fi } # TODO: failures in ODT creation should be handled error and |