-
Notifications
You must be signed in to change notification settings - Fork 1
/
antora_libraries_1
408 lines (370 loc) · 16.3 KB
/
antora_libraries_1
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
pipeline {
// agent {
// node {
// label 'jenkinspool1'
// }
// }
agent {
docker {
image 'cppalliance/boost_superproject_build:24.04-v3'
args '-v /var/lib/jenkins/jenkinsfilecache:/jenkinsfilecache'
// label 'jenkinspool1'
}
}
stages {
stage('Preclean Workspace') {
steps {
sh """#!/bin/bash
set -xe
ls -al || true
rm -rf * .*
ls -al || true
"""
checkout scm
}
}
stage('Set Variables') {
steps {
sh '''#!/bin/bash -xe
echo "" > jenkinsjobinfo.sh
chmod 777 jenkinsjobinfo.sh
REPONAME=$(basename -s .git "$(git config --get remote.origin.url)")
# REPONAME=$(basename `git rev-parse --show-toplevel`)
DNSREPONAME=$(echo $REPONAME | tr '_' '-')
ORGANIZATION=$(basename $(dirname "${GIT_URL}"))
if [[ "${GIT_URL}" =~ sdarwin ]]; then
# testing environment
echo "export JENKINS_CI_REPO=sdarwin/jenkins-ci" >> jenkinsjobinfo.sh
echo "export JENKINS_CI_REPO_BRANCH=testing" >> jenkinsjobinfo.sh
else
# standard
echo "export JENKINS_CI_REPO=cppalliance/jenkins-ci" >> jenkinsjobinfo.sh
echo "export JENKINS_CI_REPO_BRANCH=master" >> jenkinsjobinfo.sh
fi
echo "export PRTEST=prtest" >> jenkinsjobinfo.sh
echo "export REPONAME=${REPONAME}" >> jenkinsjobinfo.sh
echo "export DNSREPONAME=${DNSREPONAME}" >> jenkinsjobinfo.sh
echo "export ORGANIZATION=${ORGANIZATION}" >> jenkinsjobinfo.sh
echo "export ONLY_BUILD_ON_DOCS_MODIFICATION=false" >> jenkinsjobinfo.sh
echo "export PATH_TO_DOCS=doc/build/site" >> jenkinsjobinfo.sh
'''
}
}
stage('Diagnostics') {
steps {
sh '''#!/bin/bash
set -x
# not set -e. errors may occur in diagnostics
cat jenkinsjobinfo.sh
. jenkinsjobinfo.sh
ls -al
cat /etc/os-release
pwd
env
whoami
touch $(date "+%A-%B-%d-%T-%y")
mount | grep ^/dev/ | grep -v /etc | awk '{print \$3}'
git branch
git branch -avv
true
'''
}
}
stage('Prebuild script') {
when {
anyOf{
branch 'develop'
branch 'master'
expression { env.CHANGE_ID != null }
}
}
steps {
sh '''#!/bin/bash
set -xe
. jenkinsjobinfo.sh
curl -f -o jenkins_prebuild_script.sh https://raw.githubusercontent.com/${JENKINS_CI_REPO}/${JENKINS_CI_REPO_BRANCH}/scripts/${ORGANIZATION}_${REPONAME}_prebuild.sh || true
if [ -f jenkins_prebuild_script.sh ]; then
chmod 755 jenkins_prebuild_script.sh
./jenkins_prebuild_script.sh
fi
'''
}
}
stage('Check if docs were modified') {
when {
anyOf{
expression { env.CHANGE_ID != null }
}
}
steps {
sh '''#!/bin/bash
set -xe
. jenkinsjobinfo.sh
if [ "$ONLY_BUILD_ON_DOCS_MODIFICATION" == "true" ]; then
echo "Starting check to see if docs have been updated."
git config remote.origin.fetch '+refs/heads/*:refs/remotes/origin/*'
git fetch origin develop
mergebase=$(git merge-base HEAD remotes/origin/develop)
counter=0
for i in $(git diff --name-only HEAD $mergebase)
do
echo "file is $i"
if [[ $i =~ ^doc/ ]]; then
counter=$((counter+1))
fi
done
if [ "$counter" -eq "0" ]; then
echo "No docs found. Exiting."
# exit 1
echo "export AUTOCANCEL=true" >> jenkinsjobinfo.sh
else
echo "Found $counter docs. Proceeding."
fi
else
echo "Not checking if docs were updated. Always build."
fi
'''
}
}
stage('Determine if the job should exit') {
when {
anyOf{
expression { env.CHANGE_ID != null }
}
}
environment {
// See https://www.jenkins.io/doc/book/pipeline/jenkinsfile/#using-environment-variables
AUTOCANCEL = """${sh(
returnStdout: true,
script: '#!/bin/bash \n' + 'source jenkinsjobinfo.sh; echo -n "${AUTOCANCEL}"'
)}"""
}
steps {
script {
if (env.AUTOCANCEL == "true") {
currentBuild.result = 'ABORTED'
error("Aborting the build.")
}
}
}
}
// To skip this step, and actually all steps, adjust the job's Filter regex in the Jenkins UI
// (develop|master|PR-.*) will build all branches
// (PR-.*) will build pull requests. Etc.
stage('Build docs') {
when {
anyOf{
branch 'develop'
branch 'master'
expression { env.CHANGE_ID != null }
}
}
steps {
sh '''#!/bin/bash
set -xe
. jenkinsjobinfo.sh
export pythonvirtenvpath=/opt/venvboostdocs
if [ -f ${pythonvirtenvpath}/bin/activate ]; then
source ${pythonvirtenvpath}/bin/activate
fi
# Is there a custom build script? Often not. But let's check:
curl -f -o jenkins_build_script.sh https://raw.githubusercontent.com/${JENKINS_CI_REPO}/${JENKINS_CI_REPO_BRANCH}/scripts/${ORGANIZATION}_${REPONAME}_build.sh || true
if [ -f jenkins_build_script.sh ]; then
chmod 755 jenkins_build_script.sh
./jenkins_build_script.sh
exit 0
fi
# Otherwise, proceed using standard build steps:
curl -s -S --retry 10 -L -o linuxdocs.sh https://github.com/boostorg/release-tools/raw/develop/build_docs/linuxdocs.sh
chmod 755 linuxdocs.sh
# 2024-11 Antora requires a full copy of boostorg/boost which is 2GB. Not ideal. Let us provide that directory here.
# Since some implementations of antora/mrdocs seem to be using boost-root, symlink the filecache to the boost-root,
# so it will use the cache no-matter-what (hopefully).
savedworkspacedir=$(pwd)
cd /jenkinsfilecache
if [[ "${JOB_BASE_NAME}" =~ PR ]]; then
CACHE_FOLDER="PR"
BOOST_BRANCH="develop"
else
CACHE_FOLDER=${JOB_BASE_NAME}
BOOST_BRANCH=${BRANCH_NAME}
fi
mkdir -p ${REPONAME}/${CACHE_FOLDER}
cd ${REPONAME}/${CACHE_FOLDER}
if [ ! -d boost ]; then
git clone https://github.com/boostorg/boost -b ${BOOST_BRANCH}
fi
cd boost
# not 'exporting' this, just for the following section.
BOOST_ROOT=$(pwd)
git checkout ${BOOST_BRANCH}
rm -rf libs/${REPONAME}/* || true
rm -rf libs/${REPONAME}/.* || true
rm -rf tools/${REPONAME}/* || true
rm -rf tools/${REPONAME}/.* || true
git pull
git submodule update --init
FILECACHE_PATH=$(pwd)
# Formatted such as "cppalliance/buffers cppalliance/http_proto"
if [ -z "${EXTRA_BOOST_LIBRARIES}" ]; then
EXTRA_BOOST_LIBRARIES="cppalliance/buffers cppalliance/http_proto"
fi
for EXTRA_LIB in ${EXTRA_BOOST_LIBRARIES}; do
EXTRA_LIB_REPO=`basename $EXTRA_LIB`
if [ ! -d "$BOOST_ROOT/libs/${EXTRA_LIB_REPO}" ]; then
pushd $BOOST_ROOT/libs
git clone https://github.com/${EXTRA_LIB} -b $BOOST_BRANCH --depth 1
popd
else
# refresh extra lib:
pushd $BOOST_ROOT/libs/${EXTRA_LIB_REPO}
git checkout $BOOST_BRANCH || true
git pull || true
popd
fi
done
cd ..
cd $savedworkspacedir
ln -s ${FILECACHE_PATH} boost-root || true
export BOOST_SRC_DIR=$(pwd)/boost-root
# </done> 2024-11 Antora requires a full copy of boostorg/boost which is 2GB. Not ideal. Let us provide that directory here.
./linuxdocs.sh --debug --boostrootsubdir
# Another issue, if boost-root is now a symlink, it disappears when the docker container is gone
# Copy the docs "locally"
cp -rp boost-root/libs/${REPONAME}/doc/* doc/
'''
}
}
stage('Postbuild script') {
when {
anyOf{
branch 'develop'
branch 'master'
expression { env.CHANGE_ID != null }
}
}
steps {
sh '''#!/bin/bash
set -xe
. jenkinsjobinfo.sh
curl -f -o jenkins_postbuild_script.sh https://raw.githubusercontent.com/${JENKINS_CI_REPO}/${JENKINS_CI_REPO_BRANCH}/scripts/${ORGANIZATION}_${REPONAME}_postbuild.sh || true
if [ -f jenkins_postbuild_script.sh ]; then
chmod 755 jenkins_postbuild_script.sh
./jenkins_postbuild_script.sh
fi
'''
}
}
stage('Main branches: Upload to S3') {
when {
anyOf{
branch 'develop'
branch 'master'
}
}
environment {
// See https://www.jenkins.io/doc/book/pipeline/jenkinsfile/#using-environment-variables
REPONAME = """${sh(
returnStdout: true,
script: '#!/bin/bash \n' + 'source jenkinsjobinfo.sh; echo -n "${REPONAME}"'
)}"""
DNSREPONAME = """${sh(
returnStdout: true,
script: '#!/bin/bash \n' + 'source jenkinsjobinfo.sh; echo -n "${DNSREPONAME}"'
)}"""
PATH_TO_DOCS = """${sh(
returnStdout: true,
script: '#!/bin/bash \n' + 'source jenkinsjobinfo.sh; echo -n "${PATH_TO_DOCS}"'
)}"""
}
steps {
withAWS(region:'us-east-1', credentials: 'cppalliance-bot-aws-user') {
s3Upload(bucket:"cppalliance-websites", path:"${BRANCH_NAME}.${DNSREPONAME}.cpp.al", workingDir: "${PATH_TO_DOCS}", includePathPattern:"**")
}
}
}
stage('Pull requests: Upload to S3') {
when {
anyOf{
expression { env.CHANGE_ID != null }
}
}
environment {
// See https://www.jenkins.io/doc/book/pipeline/jenkinsfile/#using-environment-variables
REPONAME = """${sh(
returnStdout: true,
script: '#!/bin/bash \n' + 'source jenkinsjobinfo.sh; echo -n "${REPONAME}"'
)}"""
DNSREPONAME = """${sh(
returnStdout: true,
script: '#!/bin/bash \n' + 'source jenkinsjobinfo.sh; echo -n "${DNSREPONAME}"'
)}"""
PRTEST = """${sh(
returnStdout: true,
script: '#!/bin/bash \n' + 'source jenkinsjobinfo.sh; echo -n "${PRTEST}"'
)}"""
PATH_TO_DOCS = """${sh(
returnStdout: true,
script: '#!/bin/bash \n' + 'source jenkinsjobinfo.sh; echo -n "${PATH_TO_DOCS}"'
)}"""
DIFF2HTML = """${sh(
returnStdout: true,
script: '#!/bin/bash \n' + 'source jenkinsjobinfo.sh; echo -n "${DIFF2HTML}"'
)}"""
}
steps {
withAWS(region:'us-east-1', credentials: 'cppalliance-bot-aws-user') {
s3Upload(bucket:"cppalliance-previews", path:"${DNSREPONAME}/${CHANGE_ID}/", workingDir: "${PATH_TO_DOCS}", includePathPattern:"**")
}
script {
commenttext = "An automated preview of the documentation is available at [https://${env.CHANGE_ID}.${env.DNSREPONAME}.${env.PRTEST}.cppalliance.org/index.html](https://${env.CHANGE_ID}.${env.DNSREPONAME}.${env.PRTEST}.cppalliance.org/index.html)"
pullRequest.comment(commenttext)
}
}
}
stage('Post Diagnostics') {
steps {
sh '''#!/bin/bash
set -x
# not set -e. errors may occur in diagnostics
cat jenkinsjobinfo.sh
. jenkinsjobinfo.sh
ls -al
cat /etc/os-release
pwd
env
whoami
touch $(date "+%A-%B-%d-%T-%y")
mount | grep ^/dev/ | grep -v /etc | awk '{print \$3}'
git branch
git branch -avv
true
'''
}
}
}
post {
always {
echo 'This will always run'
}
success {
echo 'This will run only if successful'
// no email on success
// mail bcc: '', body: "<b>Example</b><br>Project: ${env.JOB_NAME} <br>Build Number: ${env.BUILD_NUMBER} <br> URL of the build: ${env.BUILD_URL}", cc: '', charset: 'UTF-8', from: '', mimeType: 'text/html', replyTo: '', subject: "SUCCESS CI: Project name -> ${env.JOB_NAME}", to: "[email protected]";
}
failure {
echo 'This will run only if failure'
mail bcc: '', body: "<b>Example</b><br>Project: ${env.JOB_NAME} <br>Build Number: ${env.BUILD_NUMBER} <br> URL of the build: ${env.BUILD_URL}", cc: '', charset: 'UTF-8', from: '', mimeType: 'text/html', replyTo: '', subject: "ERROR CI: Project name -> ${env.JOB_NAME}", to: "[email protected]";
}
unstable {
echo 'This will run only if the run was marked as unstable'
mail bcc: '', body: "<b>Example</b><br>Project: ${env.JOB_NAME} <br>Build Number: ${env.BUILD_NUMBER} <br> URL of the build: ${env.BUILD_URL}", cc: '', charset: 'UTF-8', from: '', mimeType: 'text/html', replyTo: '', subject: "UNSTABLE STATUS CI: Project name -> ${env.JOB_NAME}", to: "[email protected]";
}
changed {
echo 'This will run only if the state of the Pipeline has changed'
echo 'For example, if the Pipeline was previously failing but is now successful'
// no email on changed status
// mail bcc: '', body: "<b>Example</b><br>Project: ${env.JOB_NAME} <br>Build Number: ${env.BUILD_NUMBER} <br> URL of the build: ${env.BUILD_URL}", cc: '', charset: 'UTF-8', from: '', mimeType: 'text/html', replyTo: '', subject: "CHANGED STATUS CI: Project name -> ${env.JOB_NAME}", to: "[email protected]";
}
}
}