2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2019 The Linux Foundation and others.
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 ##############################################################################
12 enable_build_in_RTD_usage () {
13 echo "Usage: $0 <path_to_autorelease> <token> <version_name> <publish>"
15 echo " path_to_autorelease: The path to the autorelease"
16 echo " token: Enter Token for RTD authentication"
17 echo " version_name: Name of the version to be updated e.g stable-sodium."
18 echo " publish: Set to true to publish"
22 #Function build_update_version
23 #build_update_version <token> <project_name> <version_name>
24 #Using APIv3 ReadTheDocs for triggering build and updating version i.e setting version active status true
25 #APIv3 : https://docs.readthedocs.io/en/latest/api/v3.html
26 build_update_version() {
30 project_name_RTD=$(curl -H "Authorization: Token $token" \
31 https://readthedocs.org/api/v3/projects/?slug__contains="$project");
32 slug_name=$(echo "$project_name_RTD" \
33 | python3 -c "import sys, json; print(json.load(sys.stdin)['results'][0]['slug'])");
35 echo "Triggering build of $version in $slug_name"
36 curl -d -X POST -H "Authorization: Token $token" \
37 https://readthedocs.org/api/v3/projects/"$slug_name"/versions/"$version"/builds/;
39 echo "Enabling RTD $version for $slug_name"
40 curl --request PATCH \
41 "https://readthedocs.org/api/v3/projects/$slug_name/versions/$version/" \
42 --header "Content-Type: application/json" \
43 --header "Accept: application/json" \
44 --header "Authorization: Token $token" \
45 --data "{\"active\": true,\"privacy_level\":\"public\"}";
48 while getopts :h: opts; do
51 enable_build_in_RTD_usage
55 enable_build_in_RTD_usage
62 path_to_autorelease="$1"
70 cd "$path_to_autorelease"/ || exit
72 list_submodule=$(git submodule | awk '{ print $2 }')
73 # echo $list_submodule
74 if [ "$publish" == "true" ]
76 for submodule_name in $list_submodule
78 submodule_name="$(cut -d'/' -f2 <<<"$submodule_name")"
79 build_update_version "$token" "$submodule_name" "$version_name"