Update release downloads
[docs.git] / activate-projects-rtd-branch.sh
1 #!/bin/bash
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 usage() {
13     echo "Usage: $0 <token> <version_name>"
14     echo ""
15     echo "    token:  RTD API Token"
16     echo "    version_name:  Name of the version to be activated e.g stable-aluminium."
17     echo ""
18 }
19
20 # Activate project docs version in RTD
21 activate_version() {
22     token=$1
23     project_name=$2
24     version_name=$3
25
26     echo "Activating $project_name $version_name"
27     curl -X PATCH "https://readthedocs.org/api/v3/projects/$project_name/versions/$version_name/" \
28         -H "Authorization: Token $token"  \
29         -H "Content-Type: application/json" \
30         --data "{\"active\": true, \"hidden\": false}"
31 }
32
33 # Build "latest" to force RTD to update available versions
34 update_available_versions() {
35     token=$1
36     project_name=$2
37
38     echo "Forcing RTD to update available versions"
39     curl -X POST "https://readthedocs.org/api/v3/projects/$project_name/versions/latest/builds/" \
40         -H "Authorization: Token $token" \
41         -H "Content-Length: 0"
42 }
43
44 while getopts :h: opts; do
45     case "$opts" in
46         h)
47             usage
48             exit 0
49             ;;
50         [?])
51             usage
52             exit 1
53             ;;
54     esac
55 done
56
57 if [ -z $2 ]; then
58     usage
59     exit 1
60 fi
61
62 ################
63 # Start script #
64 ################
65
66 token="$1"
67 version_name="$2"
68
69 supported_projects=(
70     odl-aaa
71     odl-bgpcep
72     odl-daexim
73     odl-genius
74     opendaylight-distribution
75     odl-jsonrpc
76     odl-lispflowmapping
77     odl-netconf
78     odl-netvirt
79     odl-openflowplugin
80     opendaylight-ovsdb
81     opendaylight-serviceutils
82 )
83
84 for project in ${supported_projects[@]}; do
85     update_available_versions "$token" "$project" "$version_name"
86 done
87
88 echo ""
89 echo ""
90 echo "Waiting 60 seconds for available versions to update"
91 sleep 60  # Wait a minute for RTD to update available versions
92
93 for project in ${supported_projects[@]}; do
94     activate_version "$token" "$project" "$version_name"
95 done