2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2017 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 ##############################################################################
15 echo "INFO: Running build against branch $1"
18 buildid=$(lftools rtd project-build-trigger "$rtdproject" "$1" | jq '.build.id')
21 while [[ "$result" == null ]]; do
23 result=$(lftools rtd project-build-details "$rtdproject" "$buildid" | jq '.success')
24 echo "INFO Current result of running build $result"
25 if [[ $result == failed ]]; then
26 echo "INFO: read the docs build completed with status: $result"
30 echo "INFO: read the docs build completed with status: $result"
33 project_dashed="${PROJECT////-}"
34 umbrella=$(echo "$GERRIT_URL" | awk -F'.' '{print $2}')
35 if [[ "$SILO" == "sandbox" ]]; then
36 rtdproject="$umbrella-$project_dashed-test"
38 rtdproject="$umbrella-$project_dashed"
41 #MASTER_RTD_PROJECT as a global jenkins cnt
42 masterproject="$umbrella-$MASTER_RTD_PROJECT"
44 #Exceptions needed for onap, due to importing their old docs.
45 if [[ $masterproject == "onap-doc" ]]; then
48 if [[ $rtdproject == "onap-doc" ]]; then
54 echo "INFO: Project: $PROJECT"
55 echo "INFO: Read the Docs Sub Project: https://$rtdproject.readthedocs.io"
56 echo "INFO: Read the Docs Master Project: https://$masterproject.readthedocs.io"
59 if [[ "$JOB_NAME" =~ "verify" ]]; then
60 if [[ "$(lftools rtd project-details "$rtdproject" | yq -r '.detail')" == "Not found." ]]; then
61 echo "INFO: Project not found, merge will create project https://$rtdproject.readthedocs.io"
64 echo "INFO: Verify job completed"
68 if [[ "$JOB_NAME" =~ "merge" ]]; then
69 echo "INFO: Performing merge action"
71 # This retuns null if project exists.
76 while [[ $project_exists == "false" ]]; do
77 if [[ "$(lftools rtd project-details "$rtdproject" | yq -r '.detail')" == "Not found." ]]; then
78 echo "INFO: Project not found"
79 if [[ $project_created == "false" ]]; then
80 echo "INFO: Creating project https://$rtdproject.readthedocs.io"
81 lftools rtd project-create "$rtdproject" "$GERRIT_URL/$PROJECT" git "https://$rtdproject.readthedocs.io" py en
82 project_created="true"
84 echo "INFO sleeping for 30 seconds $cnt times"
87 if (( cnt >= 20 )); then
88 echo "INFO: Job has timed out"
92 echo "INFO: Project exists in read the docs as https://$rtdproject.readthedocs.io"
97 if [[ "$rtdproject" != "$masterproject" ]]; then
98 subproject_exists=false
99 while read -r subproject; do
100 if [[ "$subproject" == "$rtdproject" ]]; then
101 subproject_exists=true
104 done < <(lftools rtd subproject-list "$masterproject")
106 if $subproject_exists; then
107 echo "INFO: subproject $rtdproject relationship already created"
109 echo "INFO: Creating subproject relationship"
110 lftools rtd subproject-create "$masterproject" "$rtdproject"
111 echo "INFO sleeping for 10 seconds"
116 # api v3 method does not update /latest/ when master is triggered.
117 # Also, when we build anything other than master we want to trigger /stable/ as well.
118 # allow projects to change their landing page from latest to branch_name
120 current_version="$(lftools rtd project-details "$rtdproject" | yq -r .default_version)"
121 if [[ -z ${DEFAULT_VERSION:-} ]]; then
122 echo "DEFAULT_VERSION (default-version) value cannot be empty"
125 default_version="${DEFAULT_VERSION}"
127 echo "INFO: current default version $current_version"
128 if [[ $current_version != "$default_version" ]]; then
129 echo "INFO: Setting rtd landing page to $default_version"
130 lftools rtd project-update "$rtdproject" default_version="$default_version"
133 if [[ $GERRIT_BRANCH == "master" ]]; then
134 echo "INFO: triggering $rtdproject latest"
138 #read the docs only understands lower case branch names
139 branch=$(echo "$GERRIT_BRANCH" | tr '[:upper:]' '[:lower:]')
140 echo "INFO: Checking if read the docs has seen branch $branch"
142 #if this is 200 "null" Then run discover branch
143 if [[ $(lftools rtd project-version-details "$rtdproject" "$branch" | jq '.active') == "null" ]]; then
144 echo "INFO: read the docs has not seen branch $branch for project $rtdproject"
145 echo "INFO: triggering $rtdproject latest to instantiate new branch discovery"
149 echo "INFO: triggering $rtdproject $branch"
152 #Make newly discovered branches visible in the u/i
153 isactive=$(lftools rtd project-version-details "$rtdproject" "$branch" | jq '.active')
154 if [[ "$isactive" == false ]]; then
155 echo "INFO: Marking $branch as active for project $rtdproject"
156 lftools rtd project-version-update "$rtdproject" "$branch" true