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 ##############################################################################
14 # shellcheck disable=SC1090
17 lf-activate-venv --python python3 lftools yq
20 echo "INFO: Running build against branch $1"
23 buildid=$(lftools rtd project-build-trigger "$rtdproject" "$1" | jq '.build.id')
26 while [[ "$result" == null ]]; do
28 result=$(lftools rtd project-build-details "$rtdproject" "$buildid" | jq '.success')
29 echo "INFO Current result of running build $result"
30 if [[ $result == failed ]]; then
31 echo "INFO: read the docs build completed with status: $result"
35 echo "INFO: read the docs build completed with status: $result"
38 project_dashed="${PROJECT////-}"
39 umbrella=$(echo "$GERRIT_URL" | awk -F'.' '{print $2}')
40 if [[ "$SILO" == "sandbox" ]]; then
41 rtdproject="$umbrella-$project_dashed-test"
43 rtdproject="$umbrella-$project_dashed"
46 #MASTER_RTD_PROJECT as a global jenkins cnt
47 masterproject="$umbrella-$MASTER_RTD_PROJECT"
49 #Exceptions needed for onap, due to importing their old docs.
50 if [[ $masterproject == "onap-doc" ]]; then
53 if [[ $rtdproject == "onap-doc" ]]; then
59 echo "INFO: Project: $PROJECT"
60 echo "INFO: Read the Docs Sub Project: https://$rtdproject.readthedocs.io"
61 echo "INFO: Read the Docs Master Project: https://$masterproject.readthedocs.io"
64 if [[ "$JOB_NAME" =~ "verify" ]]; then
65 if [[ "$(lftools rtd project-details "$rtdproject" | yq -r '.detail')" == \
66 "No Project matches the given query." ]]; then
67 echo "INFO: Project not found, merge will create project https://$rtdproject.readthedocs.io"
69 echo "INFO: Verify job completed"
72 if [[ "$JOB_NAME" =~ "merge" ]]; then
73 echo "INFO: Performing merge action"
75 # This retuns null if project exists.
80 while [[ $project_exists == "false" ]]; do
81 if [[ "$(lftools rtd project-details "$rtdproject" | yq -r '.detail')" == \
82 "No Project matches the given query." ]]; then
83 echo "INFO: Project not found"
84 if [[ $project_created == "false" ]]; then
85 echo "INFO: Creating project https://$rtdproject.readthedocs.io"
86 lftools rtd project-create "$rtdproject" "$GERRIT_URL/$PROJECT" \
87 git "https://$rtdproject.readthedocs.io" py en
88 project_created="true"
90 echo "INFO sleeping for 30 seconds $cnt times"
93 if (( cnt >= 20 )); then
94 echo "INFO: Job has timed out"
98 echo "INFO: Project exists in read the docs as https://$rtdproject.readthedocs.io"
103 if [[ "$rtdproject" != "$masterproject" ]]; then
104 subproject_exists=false
105 while read -r subproject; do
106 if [[ "$subproject" == "$rtdproject" ]]; then
107 subproject_exists=true
110 done < <(lftools rtd subproject-list "$masterproject")
112 if $subproject_exists; then
113 echo "INFO: subproject $rtdproject relationship already created"
115 echo "INFO: Creating subproject relationship"
116 lftools rtd subproject-create "$masterproject" "$rtdproject"
117 echo "INFO sleeping for 10 seconds"
122 # api v3 method does not update /latest/ when master is triggered.
123 # Also, when we build anything other than master we want to trigger /stable/ as well.
124 # allow projects to change their landing page from latest to branch_name
126 current_version="$(lftools rtd project-details "$rtdproject" | yq -r .default_version)"
127 if [[ -z ${DEFAULT_VERSION:-} ]]; then
128 echo "DEFAULT_VERSION (default-version) value cannot be empty"
131 default_version="${DEFAULT_VERSION}"
133 echo "INFO: current default version $current_version"
134 if [[ $current_version != "$default_version" ]]; then
135 echo "INFO: Setting rtd landing page to $default_version"
136 lftools rtd project-update "$rtdproject" default_version="$default_version"
139 if [[ $GERRIT_BRANCH == "master" ]]; then
140 echo "INFO: triggering $rtdproject latest"
144 #read the docs only understands lower case branch names
145 branch=$(echo "$GERRIT_BRANCH" | tr '[:upper:]' '[:lower:]')
146 echo "INFO: Checking if read the docs has seen branch $branch"
148 #if this is 200 "null" Then run discover branch
149 if [[ $(lftools rtd project-version-details "$rtdproject" "$branch" | jq '.active') == "null" ]]; then
150 echo "INFO: read the docs has not seen branch $branch for project $rtdproject"
151 echo "INFO: triggering $rtdproject latest to instantiate new branch discovery"
155 echo "INFO: triggering $rtdproject $branch"
158 #Make newly discovered branches visible in the u/i
159 isactive=$(lftools rtd project-version-details "$rtdproject" "$branch" | jq '.active')
160 if [[ "$isactive" == false ]]; then
161 echo "INFO: Marking $branch as active for project $rtdproject"
162 lftools rtd project-version-update "$rtdproject" "$branch" true