forked from stan-dev/docs
-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathJenkinsfile
161 lines (143 loc) · 7.81 KB
/
Jenkinsfile
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
#!/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: 'Build docs and create a PR ?', name: 'buildDocs')
booleanParam(defaultValue: true, description: 'Change docs version for stan-dev.github.io ?', name: 'docsStanDev')
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)'
}
}
when {
expression {
params.buildDocs
}
}
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()
}
}
stage('Checkout stan-dev.github.io and update docs version') {
agent {
dockerfile {
filename 'docker/docs/Dockerfile'
dir '.'
label 'linux && triqs'
additionalBuildArgs '--build-arg PUID=\$(id -u) --build-arg PGID=\$(id -g)'
}
}
when {
expression {
params.docsStanDev
}
}
steps {
checkout([$class: 'GitSCM',
branches: [[name: '*/master']],
doGenerateSubmoduleConfigurations: false,
extensions: [],
submoduleCfg: [],
userRemoteConfigs: [[url: "https://github.com/stan-dev/stan-dev.github.io.git", credentialsId: 'a630aebc-6861-4e69-b497-fd7f496ec46b']]]
)
/* Format version numbers with dot and underscore then replace the old values */
script {
def last_version_parts = last_docs_version_dir.split("_")
def last_version_dot = last_version_parts[0] + "." + last_version_parts[1]
def new_version_underscore = major_version + "_" + minor_version
def new_version_dot = major_version + "." + minor_version
/* Linux Version */
sh """
sed -i 's/$last_docs_version_dir/$new_version_underscore/g' users/documentation/index.md
sed -i 's/$last_version_dot/$new_version_dot/g' users/documentation/index.md
sed -i 's/$last_docs_version_dir/$new_version_underscore/g' users/interfaces/cmdstan.md
sed -i 's/$last_version_dot/$new_version_dot/g' users/interfaces/cmdstan.md
"""
}
/* Create a merge 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/stan-dev.github.io.git docs-$major_version-$minor_version
curl -s -H "Authorization: token ${GITHUB_TOKEN}" -X POST -d '{"title": "Docs updated by Jenkins for v$major_version-$minor_version", "head":"docs-$major_version-$minor_version", "base":"master", "body":"Docs updated through the [Jenkins Job](https://jenkins.flatironinstitute.org/job/Stan/job/BuildDocs/)"}' "https://api.github.com/repos/stan-dev/stan-dev.github.io/pulls"
"""
}
deleteDir()
}
}
}
}