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"
45 echo "INFO: Project: $PROJECT"
46 echo "INFO: Read the Docs Sub Project: https://$rtdproject.readthedocs.io"
47 echo "INFO: Read the Docs Master Project: https://$masterproject.readthedocs.io"
50 if [[ "$JOB_NAME" =~ "verify" ]]; then
51 if [[ "$(lftools rtd project-details "$rtdproject" | yq -r '.detail')" == "Not found." ]]; then
52 echo "INFO: Project not found, merge will create project https://$rtdproject.readthedocs.io"
55 echo "INFO: Verify job completed"
59 if [[ "$JOB_NAME" =~ "merge" ]]; then
60 echo "INFO: Performing merge action"
62 # This retuns null if project exists.
67 while [[ $project_exists == "false" ]]; do
68 if [[ "$(lftools rtd project-details "$rtdproject" | yq -r '.detail')" == "Not found." ]]; then
69 echo "INFO: Project not found"
70 if [[ $project_created == "false" ]]; then
71 echo "INFO: Creating project https://$rtdproject.readthedocs.io"
72 lftools rtd project-create "$rtdproject" "$GERRIT_URL/$PROJECT" git "https://$rtdproject.readthedocs.io" py en
73 project_created="true"
75 echo "INFO sleeping for 30 seconds $cnt times"
78 if (( cnt >= 20 )); then
79 echo "INFO: Job has timed out"
83 echo "INFO: Project exists in read the docs as https://$rtdproject.readthedocs.io"
88 if [[ "$rtdproject" != "$masterproject" ]]; then
89 subproject_exists=false
90 while read -r subproject; do
91 if [[ "$subproject" == "$rtdproject" ]]; then
92 subproject_exists=true
95 done < <(lftools rtd subproject-list "$masterproject")
97 if $subproject_exists; then
98 echo "INFO: subproject $rtdproject relationship already created"
100 echo "INFO: Creating subproject relationship"
101 lftools rtd subproject-create "$masterproject" "$rtdproject"
102 echo "INFO sleeping for 10 seconds"
107 # api v3 method does not update /latest/ when master is triggered.
108 # Also, when we build anything other than master we want to trigger /stable/ as well.
109 # allow projects to change their landing page from latest to branch_name
111 current_version="$(lftools rtd project-details "$rtdproject" | yq -r .default_version)"
112 if [[ -z ${DEFAULT_VERSION:-} ]]; then
113 echo "DEFAULT_VERSION (default-version) value cannot be empty"
116 default_version="${DEFAULT_VERSION}"
118 echo "INFO: current default version $current_version"
119 if [[ $current_version != "$default_version" ]]; then
120 echo "INFO: Setting rtd landing page to $default_version"
121 lftools rtd project-update "$rtdproject" default_version="$default_version"
124 if [[ $GERRIT_BRANCH == "master" ]]; then
125 echo "INFO: triggering $rtdproject latest"
129 #read the docs only understands lower case branch names
130 branch=$(echo "$GERRIT_BRANCH" | tr '[:upper:]' '[:lower:]')
131 echo "INFO: Checking if read the docs has seen branch $branch"
133 #if this is 404. then run discover branch
134 if ! lftools rtd project-version-details "$rtdproject" "$branch" | jq '.active'; then
135 echo "INFO: read the docs has not seen branch $branch for project $rtdproject"
136 echo "INFO: triggering $rtdproject latest to instantiate new branch discovery"
140 echo "INFO: triggering $rtdproject $branch"
143 #Make newly discovered branches visible in the u/i
144 isactive=$(lftools rtd project-version-details "$rtdproject" "$branch" | jq '.active')
145 if [[ "$isactive" == false ]]; then
146 echo "INFO: Marking $branch as active for project $rtdproject"
147 lftools rtd project-version-update "$rtdproject" "$branch" true