Update download page for Chlorine SR3
[docs.git] / activate-projects-rtd-branch.sh
1 #!/bin/sh
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
13 #activate project docs versions for all supported ODL projects.
14 #This script needs to be run either manually by a docs maintainer with a valid RTD API token
15 #or automatically by Jenkins or any CI with a common hidden token.
16
17
18 usage() {
19     echo "Usage: $0 <token>"
20     echo
21     echo "    token:  RTD API Token"
22     echo
23 }
24
25 # Activate project docs version in RTD
26 activate_version() {
27     token=$1
28     project_name=$2
29     version_name=$3
30
31     echo "Activating $project_name $version_name"
32     curl -X PATCH "https://readthedocs.org/api/v3/projects/$project_name/versions/$version_name/" \
33         -H "Authorization: Token $token"  \
34         -H "Content-Type: application/json" \
35         --data "{\"active\": true, \"hidden\": false}"
36     echo
37 }
38
39 # Build "latest" to force RTD to update available versions
40 update_available_versions() {
41     token=$1
42     project_name=$2
43
44     echo "Forcing RTD to update available versions"
45     curl -X POST "https://readthedocs.org/api/v3/projects/$project_name/versions/latest/builds/" \
46         -H "Authorization: Token $token" \
47         -H "Content-Length: 0"
48     echo
49 }
50
51 # Build  to force RTD to update available versions
52 build_version() {
53     token=$1
54     project_name=$2
55     version_name=$3
56
57     echo "Forcing RTD to update available versions"
58     curl -X POST "https://readthedocs.org/api/v3/projects/$project_name/versions/$version_name/builds/" \
59         -H "Authorization: Token $token" \
60         -H "Content-Length: 0"
61     echo
62 }
63
64 while getopts :h: opts; do
65     case "$opts" in
66         h)
67             usage
68             exit 0
69             ;;
70         [?])
71             usage
72             exit 1
73             ;;
74     esac
75 done
76
77 if [ -z $1 ]; then
78     usage
79     exit 1
80 fi
81
82 ################
83 # Start script #
84 ################
85
86 token="$1"
87
88 for project in $(grep -v ^# projects_list.tsv | cut -f1); do
89     update_available_versions "$token" "odl-$project"
90 done
91
92 echo
93 echo "Waiting 60 seconds for available versions to update"
94 echo
95 sleep 60  # Wait a minute for RTD to update available versions
96
97 for project in $(grep -v ^# projects_list.tsv | cut -f1); do
98     version_name=$(grep $project projects_list.tsv | grep -v ^# | cut -f2)
99     activate_version "$token" "odl-$project" "$version_name"
100     build_version "$token" "odl-$project" "$version_name"
101 done