Job to update docs configuration in docs and other odl projects
[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     if [ "$GERRIT_BRANCH" == "master" ]
41     then
42         # ####################################
43         # # Changes in the master branch #
44         # ####################################
45         git checkout master
46         odl_release_str=odl-$release_name
47         next_odl_release_str=odl-$RELEASE_NAME
48         #change the odl-<release> linking to stable-<release> to odl-<next_release> linking to latest
49         sed -i "s/$odl_release_str/$next_odl_release_str/g;" docs/conf.py
50         sed -i "s/$stable_release_str/latest/g;" docs/conf.py
51
52         # Get the value of line with odl-<release> linking to stable-<release>
53         # for appending it to the line next to odl-<next_release> linking to latest
54         line_number_nr=$(sed -n "/$next_odl_release_str/=" docs/conf.py)
55         pattern=$line_number_nr"p"
56         odl_latest="sed -n $pattern docs/conf.py"
57         odl_latest_line_value=$($odl_latest)
58         append_odl_latest=$(echo "$odl_latest_line_value" | sed "s/latest/$stable_release_str/g; s/$RELEASE_NAME/$release_name/g" )
59         echo "Making changes in Master Branch"
60         # Update docs/conf.py
61         # sed -i "$line_number_nr'i'\
62         # $append_odl_latest" docs/conf.py
63         sed -i "$line_number_nr a $append_odl_latest" docs/conf.py
64         # Updating version in docs/conf.yaml
65         sed -i "s/$Release_version/$Next_release/g" docs/conf.yaml
66         # Updating version in docs/javadoc.rst
67         sed -i "s/$release_name/$RELEASE_NAME/g" docs/javadoc.rst
68         if [ "$PUBLISH" == "true" ]
69         then
70                 git add docs/conf.py docs/conf.yaml docs/javadoc.rst
71                 echo "Update configuratiom files in master branch"
72                 git commit -s -m "Update configuratiom files in master branch
73
74                 In docs/conf.py , add odl-$RELEASE_NAME pointing to latest
75                 and change odl-$release_name to point to stable-$release_name.
76                 In docs/conf.yaml
77                 Change version from $Release_version to $Next_release.
78                 In docs/javadoc.rst
79                 Change links from $release_name to $RELEASE_NAME"
80                 git review
81         fi
82     else
83         ####################################
84         # Changes in the new stable branch #
85         ####################################
86         echo "Making changes in $GERRIT_BRANCH"
87
88         # #Updating links in docs/conf.py
89         sed -i "s/latest/$stable_release_str/g" docs/conf.py
90         if [ "$PUBLISH" == "true" ]
91         then
92                 git add docs/conf.py
93                 echo "Update docs/conf.py links from latest to $stable_release_str"
94                 git commit -s -m "Update docs/conf.py links from latest to $stable_release_str
95
96                 Should be $stable_release_str on ${GERRIT_BRANCH}."
97                 git review
98         fi
99     fi
100 fi