forked from stan-dev/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
94 lines (83 loc) · 4.29 KB
/
Jenkinsfile
File metadata and controls
94 lines (83 loc) · 4.29 KB
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
#!/usr/bin/env groovy
pipeline {
agent none
options {
preserveStashes(buildCount: 5)
}
parameters {
string(defaultValue: '', name: 'major_version', description: "Major version of the docs to be built")
string(defaultValue: '', name: 'minor_version', description: "Minor version of the docs to be built")
string(defaultValue: '', name: 'last_docs_version_dir', description: "Last docs version found in /docs. Example: 2_21")
booleanParam(defaultValue: true, description: 'Link docs to latest?', name: 'linkDocs')
}
environment {
GITHUB_TOKEN = credentials('6e7c1e8f-ca2c-4b11-a70e-d934d3f6b681')
}
stages {
stage("Checkout docs, build and create PR") {
agent {
dockerfile {
filename 'docker/docs/Dockerfile'
dir '.'
label 'linux && triqs'
additionalBuildArgs '--build-arg PUID=\$(id -u) --build-arg PGID=\$(id -g)'
}
}
steps{
checkout([$class: 'GitSCM',
branches: [[name: '*/master']],
doGenerateSubmoduleConfigurations: false,
extensions: [[$class: 'SubmoduleOption',
disableSubmodules: false,
parentCredentials: false,
recursiveSubmodules: true,
reference: '',
trackingSubmodules: false]],
submoduleCfg: [],
userRemoteConfigs: [[url: "https://github.com/stan-dev/docs.git", credentialsId: 'a630aebc-6861-4e69-b497-fd7f496ec46b']]]
)
sh "ls -lhart"
script {
if (params.linkDocs) {
sh "python3 add_old_links.py $major_version $minor_version"
}
}
/* Build docs */
sh """
rm -rf ./docs/$major_version"_"$minor_version
python3 build.py $major_version $minor_version
"""
/* copy to the top-level (unversioned) directories */
sh """
rm -rf ./docs/functions-reference ./docs/reference-manual ./docs/stan-users-guide/ ./docs/cmdstan-guide ./docs/img ./docs/site_libs
cp -r ./docs/$major_version"_"$minor_version/* ./docs/
rm ./docs/*.pdf
python3 src/quarto-config/generate_redirects.py redirects.txt --output_dir=.
"""
script {
if (params.linkDocs) {
/* Link docs to latest */
sh "ls -lhart docs"
sh "chmod +x add_links.sh"
sh "./add_links.sh $last_docs_version_dir"
}
}
/* Create Pull Request */
withCredentials([usernamePassword(credentialsId: 'a630aebc-6861-4e69-b497-fd7f496ec46b',
usernameVariable: 'GIT_USERNAME', passwordVariable: 'GIT_PASSWORD')]) {
sh """
git config user.email "mc.stanislaw@gmail.com"
git config user.name "Stan Jenkins"
git config auth.token ${GITHUB_TOKEN}
git checkout -b docs-$major_version-$minor_version
git add .
git commit -m "Documentation generated from Jenkins for docs-$major_version-$minor_version"
git push https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/stan-dev/docs.git docs-$major_version-$minor_version --force
curl -s -H "Authorization: token ${GITHUB_TOKEN}" -X POST -d '{"title": "Docs generated by Jenkins for v$major_version-$minor_version", "head":"docs-$major_version-$minor_version", "base":"master", "body":"Docs generated through the [Jenkins Job](https://jenkins.flatironinstitute.org/job/Stan/job/BuildDocs/)"}' "https://api.github.com/repos/stan-dev/docs/pulls"
"""
}
deleteDir()
}
}
}
}