8c3c81011dcfb3a721f8ae3f56012450c93f4b44
[vpp.git] / docs / scripts / publish-docs.sh
1 #!/bin/bash -ex
2
3 # publish-docs.sh
4 #
5 # This sccript is used to publish the VPP User documents to
6 # the FD.io Site.
7 #
8 # Arguments:
9 #
10 # $1: The main site repo user name
11 # $2: The release branch name for example 1908, 1904 etc.
12
13 # Some basic checks
14 if [ ! -d "docs" ]; then
15   echo "This script is meant to be run from the root directory."
16   exit 1;
17 fi
18
19 if [ "$#" -ne 2 ]; then
20     echo "Please specify the site username and branch."
21     exit 1;
22 fi
23
24 # Get the workspace root
25 WS_ROOT=$PWD
26
27 # Get the VPP branch and username
28 SITE_USERNAME=$1
29 VPP_BRANCH=$2
30
31 #Build the docs
32 make docs-clean
33 make docs-venv
34 make docs
35
36 # Clone the site repo
37 rm -fr site
38 rm -fr sphinx_env
39 git clone ssh://git@github.com/$SITE_USERNAME/site
40 cd site
41 git submodule update --init --recursive
42 git remote add upstream ssh://git@github.com/FDio/site
43 git remote -v
44 git fetch upstream
45 git merge -m "Publish the Docs" upstream/master
46
47 # Get the version
48 VERSION=`source $WS_ROOT/src/scripts/version`
49 VERSION=${VERSION/"~"/"-"}
50
51 # Copy the files to the appropriate directory
52 SRC_DIR=../docs/_build/html/.
53 if [ "$VPP_BRANCH" == "master" ]
54 then
55     TARGET_DIR=./static/docs/vpp/master
56     rm -fr $TARGET_DIR
57 else
58     TARGET_DIR=./static/docs/vpp/v$VPP_BRANCH
59     rm -fr $TARGET_DIR
60     mkdir -p $TARGET_DIR
61     VERSION=v$VPP_BRANCH
62     rm ./static/docs/vpp/latest
63     ln -s $VERSION ./static/docs/vpp/latest
64 fi
65
66 # Create a branch for the commit
67 git checkout -b $VERSION
68 git branch
69
70 # Copy the docs
71 cp -r $SRC_DIR $TARGET_DIR
72
73 # Create the feature list
74 pushd ..
75 source ./sphinx_venv/bin/activate
76 find . -name FEATURE.yaml | ./src/scripts/fts.py --markdown > site/content/vppProject/vppfeatures/features.md
77 deactivate
78 popd
79
80 # Push the new docs
81 git add "*"
82 git commit -s -m "Publish docs from VPP $VERSION"
83 git push origin "$VERSION"
84
85 exit 0