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