Updating the overview doc with recent comments.
[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 "compass4nfv"
27     echo "copper"
28     echo "doctor"
29     echo "fastpathmetrics"
30     echo "fuel"
31     echo "functest"
32     echo "ipv6"
33     echo "joid"
34     echo "ovsnfv"
35     echo "pharos"
36     echo "promise"
37     echo "sdnvpn"
38     echo "vswitchperf"
39     echo "yardstick"
40 }
41
42 git_clone() {
43     _repo="$1"
44
45     [[ -d "$WORKSPACE/$_repo" ]] && return 0
46     pushd $WORKSPACE
47     git clone -b $GERRIT_BRANCH --depth 1 --quiet $GIT_CLONE_BASE/$_repo
48     popd
49 }
50
51 git_clone releng
52
53 repos=$(get_repo_names)
54
55 [[ -e docs/projects ]] && rm -rf docs/projects
56 mkdir -p docs/projects
57
58 echo
59 echo "Cloning repos of participating OPNFV Projects and copying docs"
60 echo
61 for repo in $repos; do
62     echo "    $repo ($GERRIT_BRANCH)"
63     git_clone $repo
64     [[ -e $WORKSPACE/$repo/docs ]] || continue
65     [[ -e docs/projects/$repo ]] && rm -rf docs/projects/$repo
66     cp -r $WORKSPACE/$repo/docs docs/projects/$repo
67 done
68
69 # NOTE: Removing index.rst in project repos to reduce number of docs.
70 find docs/projects -type f -name 'index.rst' -print | xargs -I i rm -f i
71
72 # fix relative file paths
73 pattern='.. \(include\|figure\):: *[^ \/]'
74 base_path="/$(pwd)/docs_build/_src"
75 find docs/projects -type f -name '*.rst' -print | while read f
76 do
77     sed -i -e "/$pattern/s|:: *|:: $base_path/$(dirname ${f#docs/})/|" $f
78 done
79
80 # for debug
81 grep -e '.. include::' -e '.. figure::' -r docs/projects
82
83 # NOTE: automated link generation is not ready...
84 echo
85 echo "Creating document links"
86 echo
87 targets="
88 configguide/installer-config.rst
89 configguide/feature-config.rst
90 userguide/test-usage.rst
91 userguide/feature-usage.rst
92 "
93 # configguide/post-install.rst
94 for guide in $targets
95 do
96     mainfile="$WORKSPACE/docs/$guide"
97     basefilename=$(basename ${guide/-/})
98     for repo in $repos
99     do
100         targetfile="$WORKSPACE/docs/projects/$repo/${guide/-/}"
101         targetlink="../projects/$repo/${guide/-/}"
102         projectfilename="${basefilename/.rst/-$repo.rst}"
103         projectfile="$(dirname $mainfile)/$projectfilename"
104         [[ -e "$targetfile" ]] || continue
105         echo "Adding $repo to $guide ..."
106         echo "" >> $mainfile
107         echo ".. toctree::" >> $mainfile
108         echo "" >> $mainfile
109         echo "    $projectfilename" >> $mainfile
110         echo ".. include:: $targetlink" > $projectfile
111     done
112     echo
113     echo "Generated $guide:"
114     cat $mainfile
115     echo
116 done
117
118 $WORKSPACE/releng/utils/docs-build.sh
119
120 echo "Done"