Skip to content

Commit 9eda991

Browse files
committed
[RelEng] Unify git push and submodule iteration in RelEng pipelines
1 parent 5de62f7 commit 9eda991

File tree

3 files changed

+65
-61
lines changed

3 files changed

+65
-61
lines changed

JenkinsJobs/Releng/prepareNextDevCycle.jenkinsfile

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ pipeline {
8787
checkout scm
8888
script { // Always load the script from the very same state this pipeline is loaded (to ensure consistency)
8989
utilities = load "JenkinsJobs/shared/utilities.groovy"
90+
utilities.setDryRun(params.DRY_RUN)
9091
githubAPI = load "JenkinsJobs/shared/githubAPI.groovy"
9192
githubAPI.setDryRun(params.DRY_RUN)
9293
}
@@ -344,28 +345,14 @@ pipeline {
344345
}
345346
stage('Push preparation branches') {
346347
steps {
347-
sshagent (['github-bot-ssh']) {
348-
sh '''#!/bin/bash -xe
349-
function pushNewCommitsToPreparationBranch() {
350-
pushURL=$(git config remote.origin.url)
351-
# Switch to SSH, if the configured URL uses HTTPS (we can only push with SSH)
352-
if [[ "$pushURL" == http* ]]; then
353-
pushURL=$(echo $pushURL|sed --expression 's|https://github.com/|[email protected]:|')
354-
fi
355-
if [[ ${DRY_RUN} == 'true' ]]; then
356-
dryRunFlag='--dry-run'
357-
fi
358-
git push ${dryRunFlag} ${pushURL} "master:refs/heads/prepare-R${NEXT_RELEASE_VERSION}"
359-
git push ${dryRunFlag} ${pushURL} "${MAINTENANCE_BRANCH}:refs/heads/${MAINTENANCE_BRANCH}"
360-
}
361-
pushNewCommitsToPreparationBranch
362-
export -f pushNewCommitsToPreparationBranch
363-
git submodule foreach 'pushNewCommitsToPreparationBranch'
364-
365-
# Push preparation of the maintenance to a separate branch (not directly to the maintenance branch),
366-
# to enable creating a PR against the maintenance branch from it.
367-
git push ${dryRunFlag} ${pushURL} "prepareMaintenance:refs/heads/prepare-${MAINTENANCE_BRANCH}"
368-
'''
348+
script {
349+
utilities.runHereAndForEachGitSubmodule{
350+
utilities.gitPushBranch('master', "prepare-R${NEXT_RELEASE_VERSION}")
351+
utilities.gitPushBranch("${MAINTENANCE_BRANCH}", "${MAINTENANCE_BRANCH}")
352+
}
353+
// Push preparation of the maintenance to a separate branch (not directly to the maintenance branch),
354+
// to enable creating a PR against the maintenance branch from it.
355+
utilities.gitPushBranch('prepareMaintenance', "prepare-${MAINTENANCE_BRANCH}")
369356
}
370357
}
371358
}
@@ -382,14 +369,13 @@ pipeline {
382369
- Updating the previous release version to the current Release-Candidate: `${PREVIOUS_RELEASE_CANDIDATE_ID}`
383370
""".stripIndent(), prBranch)
384371

385-
def submodulePaths = sh(script: "git submodule --quiet foreach 'echo \$sm_path'", returnStdout: true).trim().split('\\s')
386-
for (submodulePath in submodulePaths) {
387-
def diff = sh(script:"cd ${submodulePath} && git diff master origin/master --shortstat", returnStdout: true).trim()
372+
utilities.forEachGitSubmodule{ submodulePath ->
373+
def diff = sh(script:"git diff master origin/master --shortstat", returnStdout: true).trim()
388374
if (diff.isEmpty()) {
389375
echo "Skipping submodule without changes: ${submodulePath}"
390-
continue
376+
return
391377
}
392-
def submoduleURL = sh(script: "cd ${submodulePath} && git config remote.origin.url", returnStdout: true).trim()
378+
def submoduleURL = sh(script: "git config remote.origin.url", returnStdout: true).trim()
393379
// Extract repository path from e.g.: https://github.com/eclipse-platform/eclipse.platform.git
394380
def expectedPrefix = 'https://github.com/'
395381
def expectedSuffix = '.git'

JenkinsJobs/Releng/promoteBuild.jenkinsfile

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ pipeline {
8888
checkout scm
8989
script { // Always load the script from the very same state this pipeline is loaded (to ensure consistency)
9090
utilities = load "JenkinsJobs/shared/utilities.groovy"
91+
utilities.setDryRun(params.DRY_RUN)
9192
githubAPI = load "JenkinsJobs/shared/githubAPI.groovy"
9293
githubAPI.setDryRun(params.DRY_RUN)
9394
}
@@ -144,25 +145,12 @@ pipeline {
144145
}
145146
steps {
146147
dir("${WORKSPACE}/repository") {
147-
sshagent(['github-bot-ssh']) {
148-
sh '''#!/bin/bash -xe
149-
function tagBuild() {
150-
pushURL=$(git config remote.origin.url)
151-
if [[ "$pushURL" == http* ]]; then
152-
# Change to SSH, if the configured URL uses HTTPS (we can only push with SSH)
153-
pushURL=$(echo $pushURL|sed --expression 's|https://github.com/|[email protected]:|')
154-
fi
155-
if [[ ${DRY_RUN} == 'true' ]]; then
156-
dryRunFlag='--dry-run'
157-
fi
158-
# Enforce the (re-)creation of the tag in case of a very late respin
159-
git tag --force -a -m "${SIGNOFF_BUG}" ${TAG} HEAD
160-
git push --force --verbose ${dryRunFlag} ${pushURL} tag ${TAG}
161-
}
162-
tagBuild
163-
export -f tagBuild
164-
git submodule foreach 'tagBuild'
165-
'''
148+
script {
149+
utilities.runHereAndForEachGitSubmodule{
150+
// Enforce the (re-)creation of the tag in case of a very late respin
151+
sh 'git tag --force --annotate --message="${SIGNOFF_BUG}" ${TAG} HEAD'
152+
utilities.gitPushTag("${TAG}", /*force*/ true)
153+
}
166154
}
167155
}
168156
}
@@ -263,21 +251,10 @@ pipeline {
263251
git log origin/master..master --patch-with-stat --summary
264252
git log origin/${MAINTENANCE_BRANCH}..updateMaintenance --patch-with-stat --summary
265253
'''
266-
sshagent(['github-bot-ssh']) {
267-
sh '''#!/bin/bash -xe
268-
pushURL=$(git config remote.origin.url)
269-
# Switch to SSH, if the configured URL uses HTTPS (we can only push with SSH)
270-
if [[ "$pushURL" == http* ]]; then
271-
pushURL=$(echo $pushURL|sed --expression 's|https://github.com/|[email protected]:|')
272-
fi
273-
if [[ ${DRY_RUN} == 'true' ]]; then
274-
dryRunFlag='--dry-run'
275-
fi
276-
git push --force ${dryRunFlag} ${pushURL} "master:refs/heads/update-build-to-R${BUILD_MAJOR}.${BUILD_MINOR}"
277-
git push --force ${dryRunFlag} ${pushURL} "updateMaintenance:refs/heads/update-${MAINTENANCE_BRANCH}"
278-
'''
279-
}
280-
script { // Create PRs agains the master and maintenance branch
254+
script { // Push branches and create PRs agains the master and maintenance branch
255+
utilities.gitPushBranch('master', "update-build-to-R${BUILD_MAJOR}.${BUILD_MINOR}", /*force*/ true)
256+
utilities.gitPushBranch('updateMaintenance', "update-${MAINTENANCE_BRANCH}", /*force*/ true)
257+
281258
def masterPR = githubAPI.createPullRequest('eclipse-platform/eclipse.platform.releng.aggregator',
282259
"Update previous release version to ${BUILD_MAJOR}.${BUILD_MINOR} GA across build scripts", """\
283260
Update the the `${MAINTENANCE_BRANCH}` branch with final ${BUILD_MAJOR}.${BUILD_MINOR} release version.

JenkinsJobs/shared/utilities.groovy

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11

2+
@groovy.transform.Field
3+
def boolean IS_DRY_RUN = true
4+
5+
def setDryRun(boolean isDryRun) {
6+
IS_DRY_RUN = isDryRun
7+
}
8+
29
def replaceInFile(String filePath, Map<String,String> replacements) {
310
replaceAllInFile(filePath, replacements.collectEntries{ k, v -> [java.util.regex.Pattern.quote(k), v] });
411
}
@@ -15,6 +22,20 @@ def replaceAllInFile(String filePath, Map<String,String> replacements) {
1522
writeFile(file:filePath, text: content)
1623
}
1724

25+
def runHereAndForEachGitSubmodule(Closure task) {
26+
task.call()
27+
forEachGitSubmodule(task)
28+
}
29+
30+
def forEachGitSubmodule(Closure task) {
31+
def submodulePaths = sh(script: "git submodule --quiet foreach 'echo \$sm_path'", returnStdout: true).trim().split('\\s')
32+
for (submodulePath in submodulePaths) {
33+
dir("${submodulePath}") {
34+
task.call(submodulePath)
35+
}
36+
}
37+
}
38+
1839
def gitCommitAllExcludingSubmodules(String commitMessage) {
1940
withEnv(["COMMIT_MESSAGE=${commitMessage}"]) {
2041
sh '''
@@ -26,4 +47,24 @@ def gitCommitAllExcludingSubmodules(String commitMessage) {
2647
}
2748
}
2849

50+
def gitPushBranch(String localBranch, String remoteTargetBranch, boolean force = false) {
51+
gitPush("${localBranch}:refs/heads/${remoteTargetBranch}", force)
52+
}
53+
54+
def gitPushTag(String tagName, boolean force = false) {
55+
gitPush("tag ${tagName}", force)
56+
}
57+
58+
private void gitPush(String refSpec, boolean force) {
59+
def dryRunOption = IS_DRY_RUN ? '--dry-run' : ''
60+
def forceOption = force ? '--force' : ''
61+
sshagent(['github-bot-ssh']) {
62+
sh """#!/bin/bash -xe
63+
# Switch to SSH, if the configured URL uses HTTPS (we can only push with SSH)
64+
pushURL=\$(git config remote.origin.url | sed --expression 's|https://github.com/|[email protected]:|')
65+
git push ${dryRunOption} ${forceOption} "\${pushURL}" ${refSpec}
66+
"""
67+
}
68+
}
69+
2970
return this

0 commit comments

Comments
 (0)