Establishing document structures for Colorado.
[opnfvdocs.git] / build-composite.sh
1 #!/bin/bash
2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2016 NEC and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10
11 set -o errexit
12 set -o nounset
13 set -o pipefail
14 set -o xtrace
15
16 GIT_CLONE_BASE=${GIT_CLONE_BASE:-ssh://gerrit.opnfv.org:29418}
17 GERRIT_BRANCH=${GERRIT_BRANCH:-master}
18 WORKSPACE=${WORKSPACE:-/tmp}
19
20 get_repo_names() {
21     # NOTE: Not all repositories are ready for the composite docs,
22     #       so we have the repo name list here to add project docs
23     #       one by one. This will be replaced by the list in project.cfg .
24     # grep -v '^#' releng/jjb/opnfvdocs/project.cfg | sort
25     echo "apex"
26     echo "bottlenecks"
27     echo "compass4nfv"
28     echo "copper"
29     echo "doctor"
30     echo "fastpathmetrics"
31     echo "fuel"
32     echo "functest"
33     echo "ipv6"
34     echo "joid"
35     echo "ovsnfv"
36     echo "pharos"
37     echo "prediction"
38     echo "promise"
39     echo "sdnvpn"
40     echo "vswitchperf"
41     echo "yardstick"
42 }
43
44 git_clone() {
45     _repo="$1"
46
47     [[ -d "$WORKSPACE/$_repo" ]] && return 0
48     pushd $WORKSPACE
49     git clone -b $GERRIT_BRANCH --depth 1 --quiet $GIT_CLONE_BASE/$_repo
50     popd
51 }
52
53 git_clone releng
54
55 repos=$(get_repo_names)
56
57 [[ -e docs/projects ]] && rm -rf docs/projects
58 mkdir -p docs/projects
59
60 echo
61 echo "Cloning repos of participating OPNFV Projects and copying docs"
62 echo
63 for repo in $repos; do
64     echo "    $repo ($GERRIT_BRANCH)"
65     git_clone $repo
66     [[ -e $WORKSPACE/$repo/docs ]] || continue
67     [[ -e docs/projects/$repo ]] && rm -rf docs/projects/$repo
68     cp -r $WORKSPACE/$repo/docs docs/projects/$repo
69 done
70
71 # NOTE: Removing index.rst in project repos to reduce number of docs.
72 find docs/projects -type f -name 'index.rst' -print | xargs -I i rm -f i
73
74 # fix relative file paths
75 pattern='.. \(include\|figure\):: *[^ \/]'
76 base_path="/$(pwd)/docs_build/_src"
77 find docs/projects -type f -name '*.rst' -print | while read f
78 do
79     sed -i -e "/$pattern/s|:: *|:: $base_path/$(dirname ${f#docs/})/|" $f
80 done
81
82 # for debug
83 grep -e '.. include::' -e '.. figure::' -r docs/projects
84
85 # NOTE: automated link generation is not ready...
86 echo
87 echo "Creating document links"
88 echo
89 targets="
90 configurationguide/configuration.options.render.rst
91 configurationguide/installation.procedure.render.rst
92 userguide/feature.userguide.render.rst
93 testframework/framework.installation.procedure.render.rst
94 testframework/framework.userguide.render.rst
95 "
96 # configurationguide/post-install.rst
97 for guide in $targets
98 do
99     mainfile="$WORKSPACE/docs/$guide"
100     basefilename=$(basename ${guide/-/})
101     for repo in $repos
102     do
103         targetfile="$WORKSPACE/docs/projects/$repo/${guide/-/}"
104         targetlink="../projects/$repo/${guide/-/}"
105         projectfilename="${basefilename/.rst/-$repo.rst}"
106         projectfile="$(dirname $mainfile)/$projectfilename"
107         [[ -e "$targetfile" ]] || continue
108         echo "Adding $repo to $guide ..."
109         echo "" >> $mainfile
110         echo ".. toctree::" >> $mainfile
111         echo "" >> $mainfile
112         echo "    $projectfilename" >> $mainfile
113         echo ".. include:: $targetlink" > $projectfile
114     done
115     echo
116     echo "Generated $guide:"
117     cat $mainfile
118     echo
119 done
120
121 $WORKSPACE/releng/utils/docs-build.sh
122
123 echo "Done"