Feat!: Remove all stable/aluminium jobs
[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 eg: Silicon, Phosphorus."
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 set +u  # Allow unbound variables for virtualenv
32 virtualenv --quiet "/tmp/v/git-review"
33 # shellcheck source=/tmp/v/git-review/bin/activate disable=SC1091
34 source "/tmp/v/git-review/bin/activate"
35 pip install --quiet --upgrade "pip==9.0.3" setuptools
36 pip install --quiet --upgrade git-review
37 git config --global --add gitreview.username "jenkins-$SILO"
38 cd "$WORKSPACE"/docs || exit
39 RELEASE_NAME=$RELEASE_NAME
40 Next_release="$(tr '[:lower:]' '[:upper:]' <<< "${RELEASE_NAME:0:1}")${RELEASE_NAME:1}" # Captilize Version Name
41 release_name=$STREAM
42 Release_version="$(tr '[:lower:]' '[:upper:]' <<< "${release_name:0:1}")${release_name:1}" # Captilize Version Name
43 PUBLISH=$PUBLISH
44 stable_release_str=stable-$release_name
45 echo "Start Version Updating in docs project"
46 echo "RELEASE_NAME : $Next_release"
47 if [ "$GERRIT_BRANCH" == "master" ]
48 then
49     # ####################################
50     # # Changes in the master branch #
51     # ####################################
52     git checkout master
53     odl_release_str=odl-$release_name
54     next_odl_release_str=odl-$RELEASE_NAME
55     #change the odl-<release> linking to stable-<release> to odl-<next_release> linking to latest
56     sed -i "s/$odl_release_str/$next_odl_release_str/g;" docs/conf.py
57     sed -i "s/$stable_release_str/latest/g;" docs/conf.py
58
59     # Get the value of line with odl-<release> linking to stable-<release>
60     # for appending it to the line next to odl-<next_release> linking to latest
61     line_number_nr=$(sed -n "/$next_odl_release_str/=" docs/conf.py)
62     pattern=$line_number_nr"p"
63     odl_latest="sed -n $pattern docs/conf.py"
64     odl_latest_line_value=$($odl_latest)
65     append_odl_latest=$(echo "$odl_latest_line_value" | sed "s/latest/$stable_release_str/g; s/$RELEASE_NAME/$release_name/g" )
66     echo "Making changes in Master Branch"
67     # Update docs/conf.py
68     # sed -i "$line_number_nr'i'\
69     # $append_odl_latest" docs/conf.py
70     sed -i "$line_number_nr a $append_odl_latest" docs/conf.py
71     # Updating version in docs/conf.yaml
72     sed -i "s/$Release_version/$Next_release/g" docs/conf.yaml
73     # Updating version in docs/javadoc.rst
74     sed -i "s/$release_name/$RELEASE_NAME/g" docs/javadoc.rst
75     if [ "$PUBLISH" == "true" ]
76     then
77             git add docs/conf.py docs/conf.yaml docs/javadoc.rst
78             echo "Update configuratiom files in master branch"
79             git commit -s -m "Update configuratiom files in master branch
80
81             In docs/conf.py , add odl-$RELEASE_NAME pointing to latest
82             and change odl-$release_name to point to stable-$release_name.
83             In docs/conf.yaml
84             Change version from $Release_version to $Next_release.
85             In docs/javadoc.rst
86             Change links from $release_name to $RELEASE_NAME"
87             git review
88     fi
89 else
90     ####################################
91     # Changes in the new stable branch #
92     ####################################
93     echo "Making changes in $GERRIT_BRANCH"
94
95     # #Updating links in docs/conf.py
96     sed -i "s/latest/$stable_release_str/g" docs/conf.py
97     if [ "$PUBLISH" == "true" ]
98     then
99             git add docs/conf.py
100             echo "Update docs/conf.py links from latest to $stable_release_str"
101             git commit -s -m "Update docs/conf.py links from latest to $stable_release_str
102
103             Should be $stable_release_str on ${GERRIT_BRANCH}."
104             git review
105     fi
106 fi