Fix OS_CLOUD export for image validation
[releng/global-jjb.git] / shell / rtdv3.sh
1 #!/bin/bash -l
2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2017 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 echo "---> rtdv3.sh"
12 set -euo pipefail
13
14 project_dashed="${PROJECT////-}"
15 umbrella="$(echo "$GERRIT_URL" | awk -F"." '{print $2}')"
16 if [[ "$SILO" == "sandbox" ]]; then
17   rtdproject="$umbrella-$project_dashed-test"
18 else
19   rtdproject="$umbrella-$project_dashed"
20 fi
21
22 #MASTER_RTD_PROJECT as a global jenkins cnt
23 masterproject="$umbrella-$MASTER_RTD_PROJECT"
24
25 echo "INFO:"
26 echo "INFO: Project: $PROJECT"
27 echo "INFO: Read the Docs Project: https://$rtdproject.readthedocs.io"
28 echo "INFO: Read the Docs master Project: https://$masterproject.readthedocs.io"
29
30
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"
34   fi
35
36 echo "INFO: Verify job completed"
37
38 fi
39
40 if [[ "$JOB_NAME" =~ "merge" ]]; then
41 echo "INFO: Running merge job"
42
43   # This retuns null if project exists.
44   project_exists=false
45   project_created=false
46
47   declare -i cnt=0
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"
55         fi
56         echo "INFO sleeping for 30 seconds $cnt times"
57       sleep 30
58       ((cnt+=1))
59       if (( cnt >= 20 )); then
60         echo "INFO: Job has timed out"
61         exit 1
62       fi
63     else
64       echo "INFO: Project exists in read the docs as https://$rtdproject.readthedocs.io"
65       project_exists="true"
66     fi
67   done
68
69   if [[ "$rtdproject" != "$masterproject" ]]; then
70     subproject_exists=false
71     while read -r subproject; do
72         if [[ "$subproject" == "$rtdproject" ]]; then
73           subproject_exists=true
74           break
75         fi
76     done < <(lftools rtd subproject-list "$masterproject")
77
78     if $subproject_exists; then
79       echo "INFO: subproject relationship already created"
80     else
81       echo "INFO: Need to create subproject relationship"
82       lftools rtd subproject-create "$masterproject" "$rtdproject"
83       echo "INFO sleeping for 10 seconds"
84       sleep 10
85     fi
86   fi
87
88   lftools rtd project-build-trigger "$rtdproject" "$STREAM"
89 fi