-
Notifications
You must be signed in to change notification settings - Fork 9
245 lines (223 loc) · 9.4 KB
/
gerrit-compose-required-rtdv3-merge.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
---
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: 2023 The Linux Foundation
name: Compose rtdv3 Merge
# yamllint disable-line rule:truthy
on:
workflow_call:
inputs:
GERRIT_BRANCH:
description: "Branch that change is against"
required: true
type: string
GERRIT_CHANGE_ID:
description: "The ID for the change"
required: true
type: string
GERRIT_CHANGE_NUMBER:
description: "The Gerrit number"
required: true
type: string
GERRIT_CHANGE_URL:
description: "URL to the change"
required: true
type: string
GERRIT_EVENT_TYPE:
description: "Type of Gerrit event"
required: true
type: string
GERRIT_PATCHSET_NUMBER:
description: "The patch number for the change"
required: true
type: string
GERRIT_PATCHSET_REVISION:
description: "The revision sha"
required: true
type: string
GERRIT_PROJECT:
description: "Project in Gerrit"
required: true
type: string
GERRIT_REFSPEC:
description: "Gerrit refspec of change"
required: true
type: string
TARGET_REPO:
# yamllint disable-line rule:line-length
description: "The target GitHub repository needing the required workflow"
required: false
default: ${{ github.repository }}
type: string
secrets:
RTD_TOKEN:
description: "RTD API user token"
required: true
concurrency:
# yamllint disable-line rule:line-length
group: compose-rtdv3-merge-${{ github.workflow }}-${{ github.event.inputs.GERRIT_BRANCH}}-${{ github.event.inputs.GERRIT_CHANGE_ID || github.run_id }}
cancel-in-progress: true
env:
READTHEDOCS_FOUND: true
TOX_ENVS: docs,docs-linkcheck
TOX_DIR: docs/
DOC_DIR: _build/html
PARALLEL: true
DEFAULT_VERSION: latest
MASTER_RTD_PROJECT: doc
jobs:
rtd-merge:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.GERRIT_BRANCH }}
repository: ${{ inputs.TARGET_REPO }}
submodules: "true"
# yamllint disable-line rule:line-length
- uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0
id: setup-python
with:
python-version: "3.8"
- name: Install graphviz
# yamllint disable-line rule:line-length
uses: tlylt/install-graphviz@b2201200d85f06f0189cb74d9b69208504cf12cd # v1.0.0
- name: Verify If readthedocs Config exists
run: |
echo "Verifying if readthedocs.yaml config file exists"
if [ ! -f .readthedocs.yaml ] ; then
echo "INFO Config file not found. Skipping further checks."
echo "READTHEDOCS_FOUND=false" >> "$GITHUB_ENV"
fi
- name: Installing dependencies
if: ${{ env.READTHEDOCS_FOUND == 'true' }}
run: |
python -m pip install --upgrade pip
pip install lftools 'niet~=1.4.2' 'cryptography<3.4' yq tox
# urllib3 needs to be pinned to avoid timeouts
pip install --upgrade urllib3~=1.26.15
- name: Running rtdv3
# yamllint disable rule:line-length
if: ${{ env.READTHEDOCS_FOUND == 'true' }}
run: |
echo "---> Running rtdv3"
set -euo pipefail
# Creating lftools config file
mkdir -p "${HOME}/.config/lftools"
cat << EOF > "${HOME}/.config/lftools/lftools.ini"
[rtd]
endpoint=https://readthedocs.org/api/v3/
token=${{ secrets.RTD_TOKEN }}
EOF
watchbuild(){
echo "INFO: Running build against branch $1"
local buildid
local result
buildid=$(lftools rtd project-build-trigger "$rtdproject" "$1" | jq '.build.id')
result=null
while [[ "$result" == null ]]; do
sleep 10
result=$(lftools rtd project-build-details "$rtdproject" "$buildid" | jq '.success')
echo "INFO Current result of running build $result"
if [[ $result == failed ]]; then
echo "INFO: read the docs build completed with status: $result"
exit 1
fi
done
echo "INFO: read the docs build completed with status: $result"
}
project_original=${{ inputs.GERRIT_PROJECT }}
project_dashed="${project_original////-}"
umbrella=$(echo ${{ inputs.GERRIT_CHANGE_URL }} | awk -F'.' '{print $2}')
rtdproject="$umbrella-$project_dashed"
masterproject=${umbrella}-${{ env.MASTER_RTD_PROJECT }}
#Exceptions needed for onap, due to importing their old docs.
if [[ $masterproject == "onap-doc" ]]; then
masterproject="onap"
fi
if [[ $rtdproject == "onap-doc" ]]; then
rtdproject="onap"
fi
echo "INFO:"
echo "INFO: Project: ${{ inputs.GERRIT_PROJECT }}"
echo "INFO: Read the Docs Sub Project: https://$rtdproject.readthedocs.io"
echo "INFO: Read the Docs Master Project: https://$masterproject.readthedocs.io"
echo "INFO: Performing merge action"
# This retuns null if project exists.
project_exists=false
project_created=false
declare -i cnt=0
while [[ $project_exists == "false" ]]; do
if [[ "$(lftools rtd project-details "$rtdproject" | yq -r '.detail')" == "No Project matches the given query." ]]; then
echo "INFO: Project not found"
if [[ $project_created == "false" ]]; then
echo "INFO: Creating project https://$rtdproject.readthedocs.io"
lftools rtd project-create "$rtdproject" "${{ inputs.GERRIT_CHANGE_URL }}" \
git "https://$rtdproject.readthedocs.io" py en
project_created="true"
fi
echo "INFO sleeping for 30 seconds $cnt times"
sleep 30
cnt=$((cnt+1))
if (( cnt >= 20 )); then
echo "INFO: Job has timed out"
exit 1
fi
else
echo "INFO: Project exists in read the docs as https://$rtdproject.readthedocs.io"
project_exists="true"
fi
done
if [[ "$rtdproject" != "$masterproject" ]]; then
subproject_exists=false
while read -r subproject; do
if [[ "$subproject" == "$rtdproject" ]]; then
subproject_exists=true
break
fi
done < <(lftools rtd subproject-list "$masterproject")
if $subproject_exists; then
echo "INFO: subproject $rtdproject relationship already created"
else
echo "INFO: Creating subproject relationship"
lftools rtd subproject-create "$masterproject" "$rtdproject"
echo "INFO sleeping for 10 seconds"
sleep 10
fi
fi
# api v3 method does not update /latest/ when master is triggered.
# Also, when we build anything other than master we want to trigger /stable/ as well.
# allow projects to change their landing page from latest to branch_name
current_version="$(lftools rtd project-details "$rtdproject" | yq -r .default_version)"
if [[ -z ${{ env.DEFAULT_VERSION }} ]]; then
echo "DEFAULT_VERSION (default-version) value cannot be empty"
exit 1
fi
default_version="${{ env.DEFAULT_VERSION }}"
echo "INFO: current default version $current_version"
if [[ $current_version != "$default_version" ]]; then
echo "INFO: Setting rtd landing page to $default_version"
lftools rtd project-update "$rtdproject" default_version="$default_version"
fi
if [[ ${{ inputs.GERRIT_BRANCH }} == "master" ]]; then
echo "INFO: triggering $rtdproject latest"
watchbuild latest
else
#read the docs only understands lower case branch names
branch=$(echo "${{ inputs.GERRIT_BRANCH }}" | tr '[:upper:]' '[:lower:]')
echo "INFO: Checking if read the docs has seen branch $branch"
#if this is 200 "null" Then run discover branch
if [[ $(lftools rtd project-version-details "$rtdproject" "$branch" | jq '.active') == "null" ]]; then
echo "INFO: read the docs has not seen branch $branch for project $rtdproject"
echo "INFO: triggering $rtdproject latest to instantiate new branch discovery"
watchbuild latest
fi
echo "INFO: triggering $rtdproject $branch"
watchbuild "$branch"
#Make newly discovered branches visible in the u/i
isactive=$(lftools rtd project-version-details "$rtdproject" "$branch" | jq '.active')
if [[ "$isactive" == false ]]; then
echo "INFO: Marking $branch as active for project $rtdproject"
lftools rtd project-version-update "$rtdproject" "$branch" true
fi
fi
echo "INFO: Merge job completed"