Rewrite script to activate project docs versions 72/92072/1
authorThanh Ha <zxiiro@gmail.com>
Wed, 12 Aug 2020 01:15:42 +0000 (21:15 -0400)
committerThanh Ha <zxiiro@gmail.com>
Wed, 12 Aug 2020 01:18:57 +0000 (21:18 -0400)
Rewrite the script to activate project docs versions for all supported
ODL autorelease projects. This script maintains a list in the project
and needs to be run manually by a docs maintainer.

Issue: DOCS-129
Signed-off-by: Thanh Ha <zxiiro@gmail.com>
Change-Id: I158b9f2f50aacce0160b73bc79dd544dbf5b328d

activate-projects-rtd-branch.sh [new file with mode: 0755]
branch-cutting-checklist.txt
build_update_version_RTD.sh [deleted file]

diff --git a/activate-projects-rtd-branch.sh b/activate-projects-rtd-branch.sh
new file mode 100755 (executable)
index 0000000..b72012d
--- /dev/null
@@ -0,0 +1,95 @@
+#!/bin/bash
+# SPDX-License-Identifier: EPL-1.0
+##############################################################################
+# Copyright (c) 2019 The Linux Foundation and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+##############################################################################
+
+usage() {
+    echo "Usage: $0 <token> <version_name>"
+    echo ""
+    echo "    token:  RTD API Token"
+    echo "    version_name:  Name of the version to be activated e.g stable-aluminium."
+    echo ""
+}
+
+# Activate project docs version in RTD
+activate_version() {
+    token=$1
+    project_name=$2
+    version_name=$3
+
+    echo "Activating $project_name $version_name"
+    curl -X PATCH "https://readthedocs.org/api/v3/projects/$project_name/versions/$version_name/" \
+        -H "Authorization: Token $token"  \
+        -H "Content-Type: application/json" \
+        --data "{\"active\": true, \"hidden\": false}"
+}
+
+# Build "latest" to force RTD to update available versions
+update_available_versions() {
+    token=$1
+    project_name=$2
+
+    echo "Forcing RTD to update available versions"
+    curl -X POST "https://readthedocs.org/api/v3/projects/$project_name/versions/latest/builds/" \
+        -H "Authorization: Token $token" \
+        -H "Content-Length: 0"
+}
+
+while getopts :h: opts; do
+    case "$opts" in
+        h)
+            usage
+            exit 0
+            ;;
+        [?])
+            usage
+            exit 1
+            ;;
+    esac
+done
+
+if [ -z $2 ]; then
+    usage
+    exit 1
+fi
+
+################
+# Start script #
+################
+
+token="$1"
+version_name="$2"
+
+supported_projects=(
+    odl-aaa
+    odl-bgpcep
+    odl-daexim
+    odl-genius
+    opendaylight-distribution
+    odl-jsonrpc
+    odl-lispflowmapping
+    odl-netconf
+    odl-netvirt
+    odl-openflowplugin
+    opendaylight-ovsdb
+    opendaylight-serviceutils
+)
+
+for project in ${supported_projects[@]}; do
+    update_available_versions "$token" "$project" "$version_name"
+done
+
+echo ""
+echo ""
+echo "Waiting 60 seconds for available versions to update"
+sleep 60  # Wait a minute for RTD to update available versions
+
+for project in ${supported_projects[@]}; do
+    activate_version "$token" "$project" "$version_name"
+done
index 95a51ede6695d17633664cc94fdd0eb7b9ff44fe..a1bb775d0b90c9c95a472715b01c6f49d7030eb6 100644 (file)
@@ -4,3 +4,4 @@ cutting a new stable/branch after a release.
 * conf.py: Update projects intersphinx mapping latest -> stable/branch
 * conf.py: Update odl-{branch} intersphinx mapping add next release
 * conf.yaml: Update version for next release
+* Run the activate-projects-rtd-branch script to enable the new stable/branch docs
diff --git a/build_update_version_RTD.sh b/build_update_version_RTD.sh
deleted file mode 100755 (executable)
index 5c92f65..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
-#!/bin/bash
-# SPDX-License-Identifier: EPL-1.0
-##############################################################################
-# Copyright (c) 2019 The Linux Foundation and others.
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Eclipse Public License v1.0
-# which accompanies this distribution, and is available at
-# http://www.eclipse.org/legal/epl-v10.html
-##############################################################################
-
-enable_build_in_RTD_usage () {
-    echo "Usage: $0 <path_to_autorelease> <token> <version_name> <publish>"
-    echo ""
-    echo "    path_to_autorelease:  The path to the autorelease"
-    echo "    token:  Enter Token for RTD authentication"
-    echo "    version_name:  Name of the version to be updated e.g stable-sodium."
-    echo "    publish:  Set to true to publish"
-    echo ""
-}
-
-#Function build_update_version
-#build_update_version <token> <project_name> <version_name>
-#Using APIv3 ReadTheDocs for triggering build and updating version i.e setting version active status true
-#APIv3 : https://docs.readthedocs.io/en/latest/api/v3.html
-build_update_version() {
-    token=$1
-    project=$2
-    version=$3
-    project_name_RTD=$(curl -H "Authorization: Token $token" \
-    https://readthedocs.org/api/v3/projects/?slug__contains="$project");
-    slug_name=$(echo "$project_name_RTD" \
-    | python3 -c "import sys, json; print(json.load(sys.stdin)['results'][0]['slug'])");
-
-    echo "Triggering build of $version in $slug_name"
-        curl -d -X POST -H "Authorization: Token $token" \
-        https://readthedocs.org/api/v3/projects/"$slug_name"/versions/"$version"/builds/;
-
-    echo "Enabling RTD $version for $slug_name"
-        curl --request PATCH \
-        "https://readthedocs.org/api/v3/projects/$slug_name/versions/$version/" \
-        --header "Content-Type: application/json"  \
-        --header "Accept: application/json"  \
-        --header "Authorization: Token $token"  \
-        --data "{\"active\": true,\"privacy_level\":\"public\"}";
-}
-
-while getopts :h: opts; do
-    case "$opts" in
-        h)
-            enable_build_in_RTD_usage
-            exit 0
-            ;;
-        [?])
-            enable_build_in_RTD_usage
-            exit 1
-            ;;
-    esac
-done
-
-# User input
-path_to_autorelease="$1"
-token="$2"
-version_name="$3"
-publish="$4"
-
-################
-# Start script #
-###############
-cd "$path_to_autorelease"/ || exit
-git submodule update
-list_submodule=$(git submodule | awk '{ print $2 }')
-# echo $list_submodule
-if [ "$publish" == "true" ]
-then
-        for submodule_name in $list_submodule
-            do
-                submodule_name="$(cut -d'/' -f2 <<<"$submodule_name")"
-                build_update_version "$token" "$submodule_name" "$version_name"
-            done
-fi