Add installation command for git-review and configuration of git
[releng/builder.git] / jjb / docs / docs_version_bump.sh
1 #!/bin/bash -l
2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2019 The Linux Foundation and others.
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Eclipse Public License v1.0
8 # which accompanies this distribution, and is available at
9 # http://www.eclipse.org/legal/epl-v10.html
10 ##############################################################################
11
12 update_file_usage () {
13     echo "Usage: $0 <RELEASE_NAME> <PUBLISH>"
14     echo ""
15     echo "    RELEASE_NAME:  The RELEASE_NAME e.g Magnesium ."
16     echo "    PUBLISH:  Set to true to PUBLISH"
17     echo ""
18 }
19 while getopts :h: opts; do
20   case "$opts" in
21     h)
22         update_file_usage
23         exit 0
24         ;;
25     [?])
26         update_file_usage
27         exit 1
28         ;;
29   esac
30 done
31 if [ "$GERRIT_PROJECT" == "docs" ]; then
32     RELEASE_NAME=$RELEASE_NAME
33     Next_release="$(tr '[:lower:]' '[:upper:]' <<< "${RELEASE_NAME:0:1}")${RELEASE_NAME:1}" # Captilize Version Name
34     release_name=$STREAM
35     Release_version="$(tr '[:lower:]' '[:upper:]' <<< "${release_name:0:1}")${release_name:1}" # Captilize Version Name
36     PUBLISH=$PUBLISH
37     stable_release_str=stable-$release_name
38     echo "Start Version Updating in docs project"
39     echo "RELEASE_NAME : $Next_release"
40     pip install --user --quiet --upgrade git-review
41     git config --global --add gitreview.username "jenkins-$SILO"
42     if [ "$GERRIT_BRANCH" == "master" ]
43     then
44         # ####################################
45         # # Changes in the master branch #
46         # ####################################
47         git checkout master
48         odl_release_str=odl-$release_name
49         next_odl_release_str=odl-$RELEASE_NAME
50         #change the odl-<release> linking to stable-<release> to odl-<next_release> linking to latest
51         sed -i "s/$odl_release_str/$next_odl_release_str/g;" docs/conf.py
52         sed -i "s/$stable_release_str/latest/g;" docs/conf.py
53
54         # Get the value of line with odl-<release> linking to stable-<release>
55         # for appending it to the line next to odl-<next_release> linking to latest
56         line_number_nr=$(sed -n "/$next_odl_release_str/=" docs/conf.py)
57         pattern=$line_number_nr"p"
58         odl_latest="sed -n $pattern docs/conf.py"
59         odl_latest_line_value=$($odl_latest)
60         append_odl_latest=$(echo "$odl_latest_line_value" | sed "s/latest/$stable_release_str/g; s/$RELEASE_NAME/$release_name/g" )
61         echo "Making changes in Master Branch"
62         # Update docs/conf.py
63         # sed -i "$line_number_nr'i'\
64         # $append_odl_latest" docs/conf.py
65         sed -i "$line_number_nr a $append_odl_latest" docs/conf.py
66         # Updating version in docs/conf.yaml
67         sed -i "s/$Release_version/$Next_release/g" docs/conf.yaml
68         # Updating version in docs/javadoc.rst
69         sed -i "s/$release_name/$RELEASE_NAME/g" docs/javadoc.rst
70         if [ "$PUBLISH" == "true" ]
71         then
72                 git add docs/conf.py docs/conf.yaml docs/javadoc.rst
73                 echo "Update configuratiom files in master branch"
74                 git commit -s -m "Update configuratiom files in master branch
75
76                 In docs/conf.py , add odl-$RELEASE_NAME pointing to latest
77                 and change odl-$release_name to point to stable-$release_name.
78                 In docs/conf.yaml
79                 Change version from $Release_version to $Next_release.
80                 In docs/javadoc.rst
81                 Change links from $release_name to $RELEASE_NAME"
82                 git review
83         fi
84     else
85         ####################################
86         # Changes in the new stable branch #
87         ####################################
88         echo "Making changes in $GERRIT_BRANCH"
89
90         # #Updating links in docs/conf.py
91         sed -i "s/latest/$stable_release_str/g" docs/conf.py
92         if [ "$PUBLISH" == "true" ]
93         then
94                 git add docs/conf.py
95                 echo "Update docs/conf.py links from latest to $stable_release_str"
96                 git commit -s -m "Update docs/conf.py links from latest to $stable_release_str
97
98                 Should be $stable_release_str on ${GERRIT_BRANCH}."
99                 git review
100         fi
101     fi
102 fi