This repository has been archived by the owner on Apr 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Jenkinsfile
483 lines (429 loc) · 20.6 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
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
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
pipeline {
agent {
kubernetes {
label 'migration'
}
}
parameters {
string(name: 'SOURCE_BRANCH', defaultValue: 'master', description: 'Source Git Branch')
string(name: 'TARGET_BRANCH', description: 'Target Git Branch. Leave empty to derive the branch name from UPDATE_TYPE choice.')
choice(name: 'UPDATE_TYPE', choices: [
'XTEXT_VERSION',
'XTEXT_BOOTSTRAP_VERSION',
'GRADLE_WRAPPE_VERSION',
'GRADLE_VERSIONS_PROPERTY',
'ORBIT_URL',
'TYCHO_VERSION',
'GENERATE_XTEXT_LANGUAGE',
'GENERATE_TEST_LANGUAGES'
]
, description: '''
The type of update to perform. The options are:
<ul>
<li><b>XTEXT_VERSION:</b> Set Xtext version. Modifies MANIFEST.MF, POM files, versions.gradle</li>
<li><b>XTEXT_BOOTSTRAP_VERSION:</b> The Xtext version against which is bootstrapped. Especially important to use the bootstrap Xtend version.</li>
<li><b>GRADLE_WRAPPER_VERSION:</b> Set the Gradle Wrapper version to use. Modifies project roots and wizards.</li>
<li><b>GRADLE_VERSIONS_PROPERTY:</b> A property defined in <code>gradle.versions</code> to update, e.g. a Gradle plugin version. <br>
Possible values:
<ul>
<li><code>gradle_plugins</code></li>
<li><code>xtext_gradle_plugin</code></li>
</ul>
</li>
<li><b>ORBIT_URL:</b> Set SimRel Orbit repository URL in .target files and project wizard.</li>
<li><b>TYCHO_VERSION:</b> Set Eclipse Tycho version.</li>
<li><b>GENERATE_XTEXT_LANGUAGE:</b> Regenerate the Xtext grammar language</li>
<li><b>GENERATE_TEST_LANGUAGES:</b> Regenerate the Xtext test languages in xtext-core</li>
</ul>
'''
)
string(name: 'UPDATE_VALUE', description: '''
The new value to set, dependent on the selected <code>UPDATE_TYPE</code> option:
<ul>
<li><b>XTEXT_VERSION:</b> New Xtext version to set (major.minor.micro, without SNAPSHOT)</li>
<li><b>XTEXT_BOOTSTRAP_VERSION:</b> Bootstrap version (Maven format)</li>
<li><b>GRADLE_WRAPPER_VERSION:</b> <a href="https://gradle.org/releases/">Gradle release version</a> (without 'v' prefix)</li>
<li><b>GRADLE_VERSIONS_PROPERTY:</b> Name and value, format <code>NAME=VALUE</code> (e.g. 'xtext_gradle_plugin=2.0.8'</li>
<li><b>ORBIT_URL:</b> URL of the Eclipse Orbit p2 repository, e.g. <a href="https://download.eclipse.org/tools/orbit/downloads/2019-09">https://download.eclipse.org/tools/orbit/downloads/2019-09</a></li>
<li><b>TYCHO_VERSION:</b> Tycho release version</li>
<li><b>GENERATE_XTEXT_LANGUAGE:</b> <i>NO VALUE NEEDED</i></li>
<li><b>GENERATE_TEST_LANGUAGES:</b> <i>NO VALUE NEEDED</i></li>
</ul>
''')
string(name: 'GITHUB_PR_REVIEWERS', defaultValue: '"kthoms","cdietrich"', description: 'Comma seperated list of GitHub users to assign as reviewers for the PR. Each value must be double-quoted.')
booleanParam(name: 'PUSH_UNCHANGED_BRANCH', defaultValue: false, description: 'Push the target branch even when no changes were done. Usually useful in combination with enabling ADJUST_PIPELINES.')
booleanParam(name: 'OPEN_PULL_REQUEST', defaultValue: true, description: 'Create Pull Requests for repositories that have changes.')
booleanParam(name: 'ADJUST_PIPELINES', defaultValue: false, description: 'If set modify .target and pom.xml files to work against the upstream branches.')
booleanParam(name: 'DRY_RUN', defaultValue: false, description: 'Dry run mode. When set no changes are pushed to GitHub (skips "Publish" stage).')
}
options {
buildDiscarder(logRotator(numToKeepStr:'5'))
disableConcurrentBuilds()
}
environment {
//REPOSITORY_NAMES = 'xtext-lib,xtext-core,xtext-extras,xtext-eclipse,xtext-xtend,xtext-maven,xtext-web,xtext-umbrella'
// For debugging purpose limit to single repositories
REPOSITORY_NAMES = 'xtext-eclipse'
SCRIPTS = "$WORKSPACE/build-tools/releng/jenkins/bot-updates"
GENIE_XTEXT_CREDENTIALS = 'github-bot-ssh'
GITHUB_API_CREDENTIALS_ID = 'github-bot-token'
TARGET_BRANCH = "${params.TARGET_BRANCH.trim() ? params.TARGET_BRANCH.trim() : 'bot_update_'+params.UPDATE_TYPE.toLowerCase()}"
UPDATE_VALUE_REQUIRED = "${params.UPDATE_TYPE != 'GENERATE_XTEXT_LANGUAGE' && params.UPDATE_TYPE != 'GENERATE_TEST_LANGUAGES'}"
}
stages {
stage('Checkout') {
steps {
checkout scm
script {
// Check preconditions
if (env.TARGET_BRANCH == 'master') {
currentBuild.result = 'ABORTED'
error('TARGET_BRANCH \'master\' is disallowed...')
}
if (!UPDATE_VALUE.trim() && env.UPDATE_VALUE_REQUIRED=='true') {
currentBuild.result = 'ABORTED'
error('Parameter UPDATE_VALUE is required.')
}
// checkout source branch for each repository and create the target branch
sshagent([GENIE_XTEXT_CREDENTIALS]) {
wrap([$class: 'BuildUser']) {
REPOSITORY_NAMES.split(',').each {
sh """
git clone --branch ${params.SOURCE_BRANCH} --depth 1 git@github.com:eclipse/${it}.git ${it}
cd ${it}
git config user.name "${env.BUILD_USER}"
git config user.email "${env.BUILD_USER_EMAIL}"
# create target branch
git checkout -b ${env.TARGET_BRANCH}
"""
} // for each repo
} // BuildUser
} // sshagent
// read versions.gradle and grep the Xtext version without qualifier
// grep: select first line containing 'version ='
// cut#1: split text amongst single quotes, get content of version attribute
// cut#2: strip off '-SNAPSHOT' when present
// remove trailing newline from result
env.SOURCE_XTEXT_VERSION = sh (returnStdout: true, script: """curl -s https://raw.githubusercontent.com/eclipse/xtext-lib/${params.SOURCE_BRANCH}/gradle/versions.gradle | grep -m 1 "version =" | cut -d "'" -f 2 | cut -d '-' -f 1""").trim()
// It is expected that a milestone with label 'Release_<MAJOR>.<MINOR>' exists. Compute the name.
env.MILESTONE_NAME = "Release_"+env.SOURCE_XTEXT_VERSION.substring(0,env.SOURCE_XTEXT_VERSION.lastIndexOf('.'))
} // script
} // steps
} // stage
// Do the modifications to the checked out sources
stage('Update Xtext version') {
when {
expression { params.UPDATE_TYPE == 'XTEXT_VERSION' }
}
steps {
script {
if (!UPDATE_VALUE?.matches('\\d\\.\\d+\\.\\d+')) {
currentBuild.result = 'ABORTED'
error("UPDATE_VALUE '${params.UPDATE_VALUE}' Invalid...")
}
// We have the source version now, so display the update in the build's label
currentBuild.displayName = "#${env.BUILD_NUMBER} (${env.SOURCE_XTEXT_VERSION}->${params.UPDATE_VALUE})";
// set pull request title message
env.PR_TITLE="[releng] Update Xtext version to ${params.UPDATE_VALUE}"
// This change is for the new version, update the env var
env.MILESTONE_NAME = "Release_"+params.UPDATE_VALUE.substring(0,params.UPDATE_VALUE.lastIndexOf('.'))
// adjust Xtext version on all repositories
REPOSITORY_NAMES.split(',').each {
dir(it) {
sh """
# Perform version updates by external script
$SCRIPTS/fixVersions.sh -f ${env.SOURCE_XTEXT_VERSION} -t $UPDATE_VALUE -b StoS
"""
} // dir
} // for each repo
commitChanges(env.PR_TITLE)
} // script
} // steps
} // stage
stage('Update Xtext bootstrap version') {
when {
expression { params.UPDATE_TYPE == 'XTEXT_BOOTSTRAP_VERSION' }
}
steps {
script {
// set pull request title message
env.PR_TITLE="[releng] Bootstrap against ${params.UPDATE_VALUE}"
currentBuild.displayName = "#${env.BUILD_NUMBER} (Bootstrap ${params.UPDATE_VALUE})";
REPOSITORY_NAMES.split(',').each {
dir (it) {
sh """
if [ -f "gradle/versions.gradle" ]; then
sed -i -e "s|'xtext_bootstrap': '[^']*'|'xtext_bootstrap': '${params.UPDATE_VALUE}'|" gradle/versions.gradle
fi
"""
} // dir
} // for each repository
if (fileExists('xtext-eclipse')) { // for the case that we test without xtext-eclipse repo; would fail otherwise
dir ('xtext-eclipse') {
sh """
sed -i -e "s|<xtend-maven-plugin-version>.*</xtend-maven-plugin-version>|<xtend-maven-plugin-version>${params.UPDATE_VALUE}</xtend-maven-plugin-version>|" releng/org.eclipse.xtext.tycho.parent/pom.xml
"""
}}
if (fileExists('xtext-xtend')) {
dir ('xtext-xtend') {
sh """
sed -i -e "s|<xtend-maven-plugin-version>.*</xtend-maven-plugin-version>|<xtend-maven-plugin-version>${params.UPDATE_VALUE}</xtend-maven-plugin-version>|" releng/org.eclipse.xtend.tycho.parent/pom.xml
sed -i -e "s|<xtextBOMVersion>.*</xtextBOMVersion>|<xtextBOMVersion>${params.UPDATE_VALUE}</xtextBOMVersion>|" org.eclipse.xtend.maven.plugin/src/test/resources/it/pom.xml
"""
}}
commitChanges(env.PR_TITLE)
} // script
} // steps
} // stage 'Update Xtext bootstrap version'
stage('Update Gradle Wrapper') {
when {
expression { params.UPDATE_TYPE == 'GRADLE_WRAPPER_VERSION' }
}
steps {
script {
// set pull request title message
env.PR_TITLE="[releng] Update Gradle Wrapper to ${params.UPDATE_VALUE}"
currentBuild.displayName = "#${env.BUILD_NUMBER} (Gradle Wrapper ${params.UPDATE_VALUE})";
REPOSITORY_NAMES.split(',').each {
dir (it) { if (fileExists('gradlew')) {
sh label: "Update Gradle wrapper in ${it}", script: "./gradlew wrapper --gradle-version ${params.UPDATE_VALUE}"
}}
}
if (fileExists('xtext-core')) { dir('xtext-core') {
sh """
# copy to wizard resource dir
cp -f ./gradlew ./gradlew.bat gradle/wrapper/* org.eclipse.xtext.xtext.wizard/resources/gradlew/
# update wrapper for all relevant wizard projects
for f in \$(find org.eclipse.xtext.tests/testdata/wizard-expectations -name gradlew -type f);
do
pushd .
cd \$(dirname "\$f")
./gradlew wrapper --gradle-version ${params.UPDATE_VALUE}
popd
done
"""
}}
commitChanges(env.PR_TITLE)
} // script
} // steps
} // stage 'Update Gradle Wrapper'
stage('Bump versions.gradle value') {
when {
expression { params.UPDATE_TYPE == 'GRADLE_VERSIONS_PROPERTY' }
}
steps {
script {
// set pull request title message
env.PROP_NAME = "${params.UPDATE_VALUE.split(':')[0]}"
env.PROP_VALUE = "${params.UPDATE_VALUE.split(':')[1]}"
env.PR_TITLE="[releng] Bump ${env.PROP_NAME} to ${env.PROP_VALUE}"
currentBuild.displayName = "#${env.BUILD_NUMBER} (Bump ${env.PROP_VALUE})";
REPOSITORY_NAMES.split(',').each {
dir (it) {
sh """
if [ -f "gradle/versions.gradle" ]; then
sed -i -e "s|'${env.PROP_VALUE}': '[^']*'|'${env.PROP_VALUE}': '${env.PROP_VALUE}'|" gradle/versions.gradle
fi
"""
} // dir
} // for each repository
commitChanges(env.PR_TITLE)
} // script
} // steps
} // stage 'Bump versions.gradle value'
stage('Update Orbit URL') {
when {
expression { params.UPDATE_TYPE == 'ORBIT_URL' }
}
steps {
script {
// set pull request title message
env.PR_TITLE="[releng] Update Orbit URL to ${params.UPDATE_VALUE}"
currentBuild.displayName = "#${env.BUILD_NUMBER} (Orbit URL)";
REPOSITORY_NAMES.split(',').each {
dir (it) {
sh """
for f in \$(find . -name *.target -type f);
do
sed -i -e 's|https://.*/orbit/[^"]*"|${params.UPDATE_VALUE}|' \$f
done
"""
} // dir
} // for each repository
if (fileExists('xtext-core')) { // for the case that we test without xtext-core repo; would fail otherwise
dir ('xtext-core') {
sh """
sed -i -e 's|https://.*/orbit/[^"]*|${params.UPDATE_VALUE}|' org.eclipse.xtext.xtext.wizard/src/org/eclipse/xtext/xtext/wizard/TargetPlatformProject.xtend
sed -i -e 's|https://.*/orbit/[^\\]*|${params.UPDATE_VALUE}|' org.eclipse.xtext.xtext.wizard/xtend-gen/org/eclipse/xtext/xtext/wizard/TargetPlatformProject.java
"""
}}
if (fileExists('xtext-eclipse')) {
dir ('xtext-eclipse') {
sh """
sed -i -e 's|https://.*/orbit/[^"]*|${params.UPDATE_VALUE}|' releng/org.eclipse.xtext.contributor/Xtext.setup
"""
}}
commitChanges(env.PR_TITLE)
} // script
} // steps
} // stage 'Update Orbit URL'
stage('Update Tycho Version') {
when {
expression { params.UPDATE_TYPE == 'TYCHO_VERSION' }
}
steps {
script {
// set pull request title message
env.PR_TITLE="[releng] Update Tycho to ${params.UPDATE_VALUE}"
currentBuild.displayName = "#${env.BUILD_NUMBER} (Tycho ${params.UPDATE_VALUE})";
REPOSITORY_NAMES.split(',').each {
dir (it) {
sh """
for f in \$(find . -name pom.xml -type f);
do
sed -i -e 's|<tycho-version>.*</tycho-version>|<tycho-version>${params.UPDATE_VALUE}</tycho-version>"|' \$f
done
"""
} // dir
} // for each repository
commitChanges(env.PR_TITLE)
} // script
} // steps
} // stage 'Update Tycho Version'
stage('Generate Xtext Language') {
when {
expression { params.UPDATE_TYPE == 'GENERATE_XTEXT_LANGUAGE' }
}
steps {
script {
// set pull request title message
env.PR_TITLE="[releng] Regenerate Xtext Language"
currentBuild.displayName = "#${env.BUILD_NUMBER} (Xtext Language)";
dir ('xtext-core') {
sh """
./gradlew generateTestLanguages
"""
} // dir
commitChanges(env.PR_TITLE)
} // script
} // steps
} // stage 'Generate Xtext Language'
stage('Generate Test Languages') {
when {
expression { params.UPDATE_TYPE == 'GENERATE_TEST_LANGUAGES' }
}
steps {
script {
// set pull request title message
env.PR_TITLE="[releng] Regenerate Test Languages"
currentBuild.displayName = "#${env.BUILD_NUMBER} (Test Languages)";
dir ('xtext-core') {
sh """
./gradlew generateTestLanguages
"""
} // dir
commitChanges(env.PR_TITLE)
} // script
} // steps
} // stage 'Generate Test Languages'
stage('Adjust Pipelines') {
when {
expression { params.ADJUST_PIPELINES }
}
steps {
script {
// create 'locations.properties' file in xtext-umbrella and call adjustPipelines.sh then
println ("Adjusting upstream pipeline for target and parent pom.xml")
// set pull request title message
env.PR_TITLE="[releng] Adjust pipelines to branch ${params.TARGET_BRANCH}"
currentBuild.displayName = "#${env.BUILD_NUMBER} (Adjust Pipelines)";
// adjustPipelines has to be invoked within xtext-umbrella
dir ('xtext-umbrella') {
REPOSITORY_NAMES.split(',').each {
sh "echo git.clone.xtext.${it}=$WORKSPACE/${it} >> locations.properties"
}
// call script
sh "bash ./adjustPipelines.sh ${params.TARGET_BRANCH}"
}
commitChanges(env.PR_TITLE)
} // script
} // steps
} // stage 'Adjust Pipelines'
stage('Publish') {
when {
expression { !params.DRY_RUN }
}
environment {
GITHUB_API_TOKEN = credentials("${GITHUB_API_CREDENTIALS_ID}")
}
steps {
script {
sshagent([GENIE_XTEXT_CREDENTIALS]) {
// publish for each repo
REPOSITORY_NAMES.split(',').each {
dir (it) {
env.it = "${it}"
HAS_CHANGES = sh label: "Evaluate if changes have been made to ${it}", returnStatus: true, script: "git diff ${env.TARGET_BRANCH}..${params.SOURCE_BRANCH} --quiet"
if ("${HAS_CHANGES}" != "0" || params.PUSH_UNCHANGED_BRANCH) {
sh label: "Push changes for ${it}", script: """
git push --force origin ${env.TARGET_BRANCH}
"""
}
// Create a pull request, but only when there were changes made on the target branch
// see https://developer.github.com/v3/pulls/#create-a-pull-request
if (OPEN_PULL_REQUEST && "${HAS_CHANGES}" != "0") {
env.CREATE_PR_RESULT = sh (
label: "Open Pull Request",
returnStdout: true,
script: '''
curl -X "POST" -s "https://api.github.com/repos/eclipse/${it}/pulls" \
-H "Cookie: logged_in=no" -H "Content-Type: text/plain; charset=utf-8" \
-H "Authorization: token $GITHUB_API_TOKEN" \
-d '{"title": "[releng] Bootstrap against 5.0.0", "body": "This change was brought to you by your friendly Xtext Genie.", "maintainer_can_modify": false, "head": "'$TARGET_BRANCH'", "base": "'$SOURCE_BRANCH'" }'
'''
)
// Update PR with reviewers, labels, milestone
// get the first line containing 'number' and from there the value
//env.PR_NUMBER = sh (label: "Get PR number", returnStdout: true, script: """echo "${env.CREATE_PR_RESULT}" | grep -m 1 number | sed -e 's|.*: \\(.*\\),|\\1|'""").trim()
// see https://developer.github.com/v3/pulls/review_requests/#create-a-review-request
// TODO: Use team_reviewers?
//env.ADD_REVIEWERS_RESULT = sh label: "Request reviewers", returnStdout: true, script: '''
// curl -X "POST" -s "https://api.github.com/repos/eclipse/${it}/pulls/$PR_NUMBER/requested_reviewers" $GITHUB_API_REQUEST_HEADERS \
// -d '{ "reviewers": [ $GITHUB_PR_REVIEWERS ] }'
//'''
// get the open milestones for the repository
// grep for the expected milestone name 'Release_<MAJOR>.<MINOR>' and get attributes around that line
// grep for the number attribute value
//env.MILESTONE_NUMBER = sh (label: "Get number of milestone ${env.MILESTONE_NAME}", returnStdout: true, script: """curl -s https://api.github.com/repos/eclipse/${it}/milestones | grep -b4 -a4 ${env.MILESTONE_NAME} | grep number | sed -e 's|.*: \\(.*\\),|\\1|'""").trim()
// env.UPDATE_PR_RESULT = sh label: "Set labels, milestone ${env.MILESTONE_NUMBER} and assign to bot", returnStdout: true, script: '''
// curl -X "PATCH" -s "https://api.github.com/repos/eclipse/$it/issues/$PR_NUMBER" $GITHUB_API_REQUEST_HEADERS \
// -d '{ "labels": [ "bot", "releng"], "assignees": [ "genie-xtext"], "milestone": $MILESTONE_NUMBER }'
// '''
} // if has changes
} // dir
} // for each repository
} // sshagent
} // script
} // steps
} // stage
} // stages
} // pipeline
/**
* On all repositories: Commit pending changes, if any.
* When performing a DRY_RUN then print the diff.
*/
def commitChanges (String commitMessage) {
REPOSITORY_NAMES.split(',').each {
dir (it) {
// Avoid commit when no change has happened. This would make the pipeline fail.
sh """git diff-index --quiet HEAD || git commit --signoff -a -m '${commitMessage}' """
}
}
if (params.DRY_RUN) {
REPOSITORY_NAMES.split(',').each {
dir (it) {
sh "git diff ${params.SOURCE_BRANCH}..${env.TARGET_BRANCH}"
}
}
}
}