Skip to content

Commit

Permalink
Update Quarkus vs: Allow to hardcode branch (apache#595)
Browse files Browse the repository at this point in the history
  • Loading branch information
radtriste authored Aug 25, 2022
1 parent 8819c09 commit fa3a7d2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 15 deletions.
11 changes: 6 additions & 5 deletions .ci/jenkins/Jenkinsfile.ecosystem.update-quarkus-all
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pipeline {
stage('Update quarkus version in branch config') {
steps {
script {
String prBranch = getPRBranch("${SEED_BRANCH_CONFIG_FILE_GIT_BRANCH}")
String prBranch = getSeedPRBranch("${SEED_BRANCH_CONFIG_FILE_GIT_BRANCH}")
dir("${SEED_BRANCH_CONFIG_FILE_GIT_REPOSITORY}") {
deleteDir()
checkout(githubscm.resolveRepository("${SEED_BRANCH_CONFIG_FILE_GIT_REPOSITORY}", "${SEED_BRANCH_CONFIG_FILE_GIT_AUTHOR_NAME}", "${SEED_BRANCH_CONFIG_FILE_GIT_BRANCH}", false, "${SEED_BRANCH_CONFIG_FILE_GIT_AUTHOR_CREDS_ID}"))
Expand Down Expand Up @@ -64,7 +64,7 @@ pipeline {
stage('Update quarkus version in seed repo') {
steps {
script {
String prBranch = getPRBranch("${SEED_BRANCH}")
String prBranch = getSeedPRBranch("${SEED_BRANCH}")
dir("${SEED_REPO}") {
deleteDir()
checkout(githubscm.resolveRepository("${SEED_REPO}", "${SEED_AUTHOR_NAME}", "${SEED_BRANCH}", false, "${SEED_AUTHOR_CREDS_ID}"))
Expand All @@ -86,7 +86,7 @@ pipeline {
if ("${SEED_REPO}" != "${SEED_BRANCH_CONFIG_FILE_GIT_REPOSITORY}" ||
"${SEED_AUTHOR_NAME}" != "${SEED_BRANCH_CONFIG_FILE_GIT_AUTHOR_NAME}" ||
"${SEED_BRANCH}" != "${SEED_BRANCH_CONFIG_FILE_GIT_BRANCH}") {
String prLink = githubscm.createPR(commitMsg, 'Please review and merge', "${SEED_BRANCH}", "${SEED_AUTHOR_CREDS_ID}")
String prLink = githubscm.createPR(commitMsg, 'Please review and merge', "${SEED_BRANCH}", "${SEED_AUTHOR_CREDS_ID}")
echo "Created PR ${prLink}"

sendNotification("PR was created to update quarkus version in seed repo to ${getNewVersion()}.\nPlease review and merge ${prLink}")
Expand Down Expand Up @@ -139,6 +139,7 @@ void launchUpdateQuarkusJob(String repo) {
String jobName = "update-quarkus-${repo}"
List jobParams = []
jobParams.add(stringParam(name: 'NEW_VERSION', value: getNewVersion()))
jobParams.add(stringParam(name: 'PR_BRANCH', value: params.PR_BRANCH))

echo "Build ./${jobName} with parameters ${jobParams}"
build(job: "./${jobName}", parameters: jobParams, wait: false)
Expand All @@ -157,8 +158,8 @@ String getBuildBranch() {
return "${BUILD_BRANCH_NAME}"
}

String getPRBranch(String branch) {
return "bump-seed-${branch}-quarkus-${getNewVersion()}"
String getSeedPRBranch(String branch) {
return params.PR_BRANCH ? "${params.PR_BRANCH}-seed" : "bump-seed-${branch}-quarkus-${getNewVersion()}"
}

String getNotificationJobName() {
Expand Down
43 changes: 33 additions & 10 deletions .ci/jenkins/Jenkinsfile.tools.update-dependency-version
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import org.kie.jenkins.MavenCommand

branchCreated = false

pipeline {
agent {
label 'kie-rhel7 && !master'
Expand Down Expand Up @@ -38,7 +40,7 @@ pipeline {

dir(getRepoName()) {
deleteDir()
checkout(githubscm.resolveRepository(getRepoName(), getGitAuthor(), getBuildBranch(), false))
checkout(githubscm.resolveRepository(getRepoName(), getGitAuthor(), getBuildBranch(), false, getGitAuthorCredsId()))
}
}
}
Expand All @@ -47,7 +49,7 @@ pipeline {
steps {
script {
dir(getRepoName()) {
githubscm.createBranch(getPRBranch())
branchCreated = getOrCreateGitBranch(getPRBranch(), getGitAuthorCredsId())
}
}
}
Expand Down Expand Up @@ -130,12 +132,15 @@ pipeline {
dir(getRepoName()) {
String commitMsg = "[${getBuildBranch()}] Bump ${getDependencyName()} version to ${getNewVersion()}"
githubscm.commitChanges(commitMsg)
githubscm.pushObject('origin', getPRBranch(), getAuthorCredsId())

String prLink = githubscm.createPR(commitMsg, 'Please review and merge', getBuildBranch(), getAuthorCredsId())
echo "Created PR ${prLink}"

sendNotification("PR was created to update ${getDependencyName()} version to ${getNewVersion()}.\nPlease review and merge ${prLink}")
githubscm.pushObject('origin', getPRBranch(), getGitAuthorCredsId())

if (branchCreated) {
String prLink = githubscm.createPR(commitMsg, 'Please review and merge', getBuildBranch(), getGitAuthorCredsId())
echo "Created PR ${prLink}"
sendNotification("PR was created to update ${getDependencyName()} version to ${getNewVersion()}.\nPlease review and merge ${prLink}")
} else {
echo "Branch ${getPRBranch()} was already created so assuming the PR exists alrerady ..."
}
}
}
}
Expand Down Expand Up @@ -175,12 +180,12 @@ String getGitAuthor() {
return "${GIT_AUTHOR}"
}

String getAuthorCredsId() {
String getGitAuthorCredsId() {
return "${AUTHOR_CREDS_ID}"
}

String getPRBranch() {
return "bump-${getPRPrefixBranch() ?: getBuildBranch()}-${getDependencyName().toLowerCase()}-${getNewVersion()}"
return params.PR_BRANCH ?: "bump-${getPRPrefixBranch() ?: getBuildBranch()}-${getDependencyName().toLowerCase()}-${getNewVersion()}"
}

String getPRPrefixBranch() {
Expand Down Expand Up @@ -218,3 +223,21 @@ List getGradleRegex() {
List getFilepathReplaceRegex() {
return env.FILEPATH_REPLACE_REGEX ? readJSON(text: env.FILEPATH_REPLACE_REGEX) : []
}

/**
* Return true if the branch was created
*/
boolean getOrCreateGitBranch(String branch, String credentialsId) {
sh 'git fetch origin'
String branchRemoteResult = sh(script: "git ls-remote origin ${branch} | wc -l", returnStdout: true).trim()
if (Integer.parseInt(branchRemoteResult) > 0) {
echo "Branch ${branch} already exist ... will not create it. Checking out !"
sh "git checkout origin/${branch} -b ${branch}"
return false
} else {
echo "Branch ${branch} does not exist ... gonna create it"
githubscm.createBranch(branch)
githubscm.pushObject('origin', branch, credentialsId)
return true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class KogitoJobUtils {
return job.with {
parameters {
stringParam('NEW_VERSION', '', 'Which version to set ?')
stringParam('PR_BRANCH', '', '(Optional) Which PR branch name to use ? If none given, a name will be generated automatically.')
}
}
}
Expand Down Expand Up @@ -152,6 +153,7 @@ class KogitoJobUtils {
KogitoJobTemplate.createPipelineJob(script, jobParams)?.with {
parameters {
stringParam('NEW_VERSION', '', 'Which version to set ?')
stringParam('PR_BRANCH', '', '(Optional) Which PR branch name to use ? If none given, a name will be generated automatically.')
}
}
}
Expand Down

0 comments on commit fa3a7d2

Please sign in to comment.