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 project_dashed="${PROJECT////-}"
15 umbrella=$(echo "$GERRIT_URL" | awk -F'.' '{print $2}')
16 if [[ "$SILO" == "sandbox" ]]; then
17 rtdproject="$umbrella-$project_dashed-test"
19 rtdproject="$umbrella-$project_dashed"
22 #MASTER_RTD_PROJECT as a global jenkins cnt
23 masterproject="$umbrella-$MASTER_RTD_PROJECT"
26 echo "INFO: Project: $PROJECT"
27 echo "INFO: Read the Docs Sub Project: https://$rtdproject.readthedocs.io"
28 echo "INFO: Read the Docs Master Project: https://$masterproject.readthedocs.io"
31 if [[ "$JOB_NAME" =~ "verify" ]]; then
32 if [[ "$(lftools rtd project-details "$rtdproject" | yq -r '.detail')" == "Not found." ]]; then
33 echo "INFO: Project not found, merge will create project https://$rtdproject.readthedocs.io"
36 echo "INFO: Verify job completed"
40 if [[ "$JOB_NAME" =~ "merge" ]]; then
41 echo "INFO: Performing merge action"
43 # This retuns null if project exists.
48 while [[ $project_exists == "false" ]]; do
49 if [[ "$(lftools rtd project-details "$rtdproject" | yq -r '.detail')" == "Not found." ]]; then
50 echo "INFO: Project not found"
51 if [[ $project_created == "false" ]]; then
52 echo "INFO: Creating project https://$rtdproject.readthedocs.io"
53 lftools rtd project-create "$rtdproject" "$GERRIT_URL/$PROJECT" git "https://$rtdproject.readthedocs.io" py en
54 project_created="true"
56 echo "INFO sleeping for 30 seconds $cnt times"
59 if (( cnt >= 20 )); then
60 echo "INFO: Job has timed out"
64 echo "INFO: Project exists in read the docs as https://$rtdproject.readthedocs.io"
69 if [[ "$rtdproject" != "$masterproject" ]]; then
70 subproject_exists=false
71 while read -r subproject; do
72 if [[ "$subproject" == "$rtdproject" ]]; then
73 subproject_exists=true
76 done < <(lftools rtd subproject-list "$masterproject")
78 if $subproject_exists; then
79 echo "INFO: subproject $rtdproject relationship already created"
81 echo "INFO: Creating subproject relationship"
82 lftools rtd subproject-create "$masterproject" "$rtdproject"
83 echo "INFO sleeping for 10 seconds"
88 # api v3 method does not update /latest/ when master is triggered.
89 # Also, when we build anything other than master we want to trigger /stable/ as well.
90 # allow projects to change their landing page from latest to branch_name
92 current_version="$(lftools rtd project-details "$rtdproject" | yq -r .default_version)"
93 if [[ -z ${DEFAULT_VERSION:-} ]]; then
94 echo "DEFAULT_VERSION (default-version) value cannot be empty"
97 default_version="${DEFAULT_VERSION}"
99 echo "INFO: current default version $current_version"
100 if [[ $current_version != "$default_version" ]]; then
101 echo "INFO: Setting rtd landing page to $default_version"
102 lftools rtd project-update "$rtdproject" default_version="$default_version"
105 lftools rtd project-build-trigger "$rtdproject" "$GERRIT_BRANCH"
106 if [[ $GERRIT_BRANCH == "master" ]]; then
107 echo "INFO: triggering latest"
108 lftools rtd project-build-trigger "$rtdproject" latest
110 echo "INFO: triggering stable"
111 lftools rtd project-build-trigger "$rtdproject" stable