diff --git a/JenkinsJobs/Releng/prepareNextDevCycle.jenkinsfile b/JenkinsJobs/Releng/prepareNextDevCycle.jenkinsfile index 691f5102e35..03239d7945e 100644 --- a/JenkinsJobs/Releng/prepareNextDevCycle.jenkinsfile +++ b/JenkinsJobs/Releng/prepareNextDevCycle.jenkinsfile @@ -87,6 +87,7 @@ pipeline { checkout scm script { // Always load the script from the very same state this pipeline is loaded (to ensure consistency) utilities = load "JenkinsJobs/shared/utilities.groovy" + utilities.setDryRun(params.DRY_RUN) githubAPI = load "JenkinsJobs/shared/githubAPI.groovy" githubAPI.setDryRun(params.DRY_RUN) } @@ -344,28 +345,14 @@ pipeline { } stage('Push preparation branches') { steps { - sshagent (['github-bot-ssh']) { - sh '''#!/bin/bash -xe - function pushNewCommitsToPreparationBranch() { - pushURL=$(git config remote.origin.url) - # Switch to SSH, if the configured URL uses HTTPS (we can only push with SSH) - if [[ "$pushURL" == http* ]]; then - pushURL=$(echo $pushURL|sed --expression 's|https://github.com/|git@github.com:|') - fi - if [[ ${DRY_RUN} == 'true' ]]; then - dryRunFlag='--dry-run' - fi - git push ${dryRunFlag} ${pushURL} "master:refs/heads/prepare-R${NEXT_RELEASE_VERSION}" - git push ${dryRunFlag} ${pushURL} "${MAINTENANCE_BRANCH}:refs/heads/${MAINTENANCE_BRANCH}" - } - pushNewCommitsToPreparationBranch - export -f pushNewCommitsToPreparationBranch - git submodule foreach 'pushNewCommitsToPreparationBranch' - - # Push preparation of the maintenance to a separate branch (not directly to the maintenance branch), - # to enable creating a PR against the maintenance branch from it. - git push ${dryRunFlag} ${pushURL} "prepareMaintenance:refs/heads/prepare-${MAINTENANCE_BRANCH}" - ''' + script { + utilities.runHereAndForEachGitSubmodule{ + utilities.gitPushBranch('master', "prepare-R${NEXT_RELEASE_VERSION}") + utilities.gitPushBranch("${MAINTENANCE_BRANCH}", "${MAINTENANCE_BRANCH}") + } + // Push preparation of the maintenance to a separate branch (not directly to the maintenance branch), + // to enable creating a PR against the maintenance branch from it. + utilities.gitPushBranch('prepareMaintenance', "prepare-${MAINTENANCE_BRANCH}") } } } @@ -382,14 +369,13 @@ pipeline { - Updating the previous release version to the current Release-Candidate: `${PREVIOUS_RELEASE_CANDIDATE_ID}` """.stripIndent(), prBranch) - def submodulePaths = sh(script: "git submodule --quiet foreach 'echo \$sm_path'", returnStdout: true).trim().split('\\s') - for (submodulePath in submodulePaths) { - def diff = sh(script:"cd ${submodulePath} && git diff master origin/master --shortstat", returnStdout: true).trim() + utilities.forEachGitSubmodule{ submodulePath -> + def diff = sh(script:"git diff master origin/master --shortstat", returnStdout: true).trim() if (diff.isEmpty()) { echo "Skipping submodule without changes: ${submodulePath}" - continue + return } - def submoduleURL = sh(script: "cd ${submodulePath} && git config remote.origin.url", returnStdout: true).trim() + def submoduleURL = sh(script: "git config remote.origin.url", returnStdout: true).trim() // Extract repository path from e.g.: https://github.com/eclipse-platform/eclipse.platform.git def expectedPrefix = 'https://github.com/' def expectedSuffix = '.git' diff --git a/JenkinsJobs/Releng/promoteBuild.jenkinsfile b/JenkinsJobs/Releng/promoteBuild.jenkinsfile index 3f310a98a62..7b8ae5422ff 100644 --- a/JenkinsJobs/Releng/promoteBuild.jenkinsfile +++ b/JenkinsJobs/Releng/promoteBuild.jenkinsfile @@ -88,6 +88,7 @@ pipeline { checkout scm script { // Always load the script from the very same state this pipeline is loaded (to ensure consistency) utilities = load "JenkinsJobs/shared/utilities.groovy" + utilities.setDryRun(params.DRY_RUN) githubAPI = load "JenkinsJobs/shared/githubAPI.groovy" githubAPI.setDryRun(params.DRY_RUN) } @@ -144,25 +145,12 @@ pipeline { } steps { dir("${WORKSPACE}/repository") { - sshagent(['github-bot-ssh']) { - sh '''#!/bin/bash -xe - function tagBuild() { - pushURL=$(git config remote.origin.url) - if [[ "$pushURL" == http* ]]; then - # Change to SSH, if the configured URL uses HTTPS (we can only push with SSH) - pushURL=$(echo $pushURL|sed --expression 's|https://github.com/|git@github.com:|') - fi - if [[ ${DRY_RUN} == 'true' ]]; then - dryRunFlag='--dry-run' - fi - # Enforce the (re-)creation of the tag in case of a very late respin - git tag --force -a -m "${SIGNOFF_BUG}" ${TAG} HEAD - git push --force --verbose ${dryRunFlag} ${pushURL} tag ${TAG} - } - tagBuild - export -f tagBuild - git submodule foreach 'tagBuild' - ''' + script { + utilities.runHereAndForEachGitSubmodule{ + // Enforce the (re-)creation of the tag in case of a very late respin + sh 'git tag --force --annotate --message="${SIGNOFF_BUG}" ${TAG} HEAD' + utilities.gitPushTag("${TAG}", /*force*/ true) + } } } } @@ -263,21 +251,10 @@ pipeline { git log origin/master..master --patch-with-stat --summary git log origin/${MAINTENANCE_BRANCH}..updateMaintenance --patch-with-stat --summary ''' - sshagent(['github-bot-ssh']) { - sh '''#!/bin/bash -xe - pushURL=$(git config remote.origin.url) - # Switch to SSH, if the configured URL uses HTTPS (we can only push with SSH) - if [[ "$pushURL" == http* ]]; then - pushURL=$(echo $pushURL|sed --expression 's|https://github.com/|git@github.com:|') - fi - if [[ ${DRY_RUN} == 'true' ]]; then - dryRunFlag='--dry-run' - fi - git push --force ${dryRunFlag} ${pushURL} "master:refs/heads/update-build-to-R${BUILD_MAJOR}.${BUILD_MINOR}" - git push --force ${dryRunFlag} ${pushURL} "updateMaintenance:refs/heads/update-${MAINTENANCE_BRANCH}" - ''' - } - script { // Create PRs agains the master and maintenance branch + script { // Push branches and create PRs agains the master and maintenance branch + utilities.gitPushBranch('master', "update-build-to-R${BUILD_MAJOR}.${BUILD_MINOR}", /*force*/ true) + utilities.gitPushBranch('updateMaintenance', "update-${MAINTENANCE_BRANCH}", /*force*/ true) + def masterPR = githubAPI.createPullRequest('eclipse-platform/eclipse.platform.releng.aggregator', "Update previous release version to ${BUILD_MAJOR}.${BUILD_MINOR} GA across build scripts", """\ Update the the `${MAINTENANCE_BRANCH}` branch with final ${BUILD_MAJOR}.${BUILD_MINOR} release version. diff --git a/JenkinsJobs/shared/utilities.groovy b/JenkinsJobs/shared/utilities.groovy index a13bfd5a81f..ae8cb760d22 100644 --- a/JenkinsJobs/shared/utilities.groovy +++ b/JenkinsJobs/shared/utilities.groovy @@ -1,4 +1,11 @@ +@groovy.transform.Field +def boolean IS_DRY_RUN = true + +def setDryRun(boolean isDryRun) { + IS_DRY_RUN = isDryRun +} + def replaceInFile(String filePath, Map replacements) { replaceAllInFile(filePath, replacements.collectEntries{ k, v -> [java.util.regex.Pattern.quote(k), v] }); } @@ -15,6 +22,20 @@ def replaceAllInFile(String filePath, Map replacements) { writeFile(file:filePath, text: content) } +def runHereAndForEachGitSubmodule(Closure task) { + task.call() + forEachGitSubmodule(task) +} + +def forEachGitSubmodule(Closure task) { + def submodulePaths = sh(script: "git submodule --quiet foreach 'echo \$sm_path'", returnStdout: true).trim().split('\\s') + for (submodulePath in submodulePaths) { + dir("${submodulePath}") { + task.call(submodulePath) + } + } +} + def gitCommitAllExcludingSubmodules(String commitMessage) { withEnv(["COMMIT_MESSAGE=${commitMessage}"]) { sh ''' @@ -26,4 +47,24 @@ def gitCommitAllExcludingSubmodules(String commitMessage) { } } +def gitPushBranch(String localBranch, String remoteTargetBranch, boolean force = false) { + gitPush("${localBranch}:refs/heads/${remoteTargetBranch}", force) +} + +def gitPushTag(String tagName, boolean force = false) { + gitPush("tag ${tagName}", force) +} + +private void gitPush(String refSpec, boolean force) { + def dryRunOption = IS_DRY_RUN ? '--dry-run' : '' + def forceOption = force ? '--force' : '' + sshagent(['github-bot-ssh']) { + sh """#!/bin/bash -xe + # Switch to SSH, if the configured URL uses HTTPS (we can only push with SSH) + pushURL=\$(git config remote.origin.url | sed --expression 's|https://github.com/|git@github.com:|') + git push ${dryRunOption} ${forceOption} "\${pushURL}" ${refSpec} + """ + } +} + return this