Skip to content

Commit

Permalink
kie-issues#776: automate PR merge into protected branches
Browse files Browse the repository at this point in the history
  • Loading branch information
jstastny-cz authored and jstastny-cz committed May 13, 2024
1 parent b1e0d71 commit 0ed6010
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 39 deletions.
32 changes: 14 additions & 18 deletions .ci/jenkins/Jenkinsfile.promote
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ pipeline {
steps {
script {
dir(optaplannerRepository) {
approveAndMergePR(getDeployPrLink(optaplannerRepository))
checkoutRepo(optaplannerRepository)
mergeAndPush(getDeployPrLink(optaplannerRepository))
tagLatest()

if(githubscm.isReleaseExist(getGitTag(), getGitAuthorCredsId())) {
githubscm.deleteRelease(getGitTag(), getGitAuthorCredsId())
if (githubscm.isReleaseExist(getGitTag(), getGitAuthorCredsId())) {
githubscm.deleteRelease(getGitTag(), getGitAuthorPushCredsId())
}
githubscm.createReleaseWithGeneratedReleaseNotes(getGitTag(), getBuildBranch(), githubscm.getPreviousTagFromVersion(getGitTag()), getGitAuthorCredsId())
githubscm.updateReleaseBody(getGitTag(), getGitAuthorCredsId())
githubscm.createReleaseWithGeneratedReleaseNotes(getGitTag(), getBuildBranch(), githubscm.getPreviousTagFromVersion(getGitTag()), getGitAuthorPushCredsId())
githubscm.updateReleaseBody(getGitTag(), getGitAuthorPushCredsId())
}
}
}
Expand All @@ -95,15 +95,15 @@ pipeline {
steps {
script {
dir(quickstartsRepository) {
approveAndMergePR(getDeployPrLink(quickstartsRepository))
checkoutRepo(quickstartsRepository)
mergeAndPush(getDeployPrLink(quickstartsRepository))
tagLatest()

if(githubscm.isReleaseExist(getGitTag(), getGitAuthorCredsId())) {
githubscm.deleteRelease(getGitTag(), getGitAuthorCredsId())
if (githubscm.isReleaseExist(getGitTag(), getGitAuthorCredsId())) {
githubscm.deleteRelease(getGitTag(), getGitAuthorPushCredsId())
}
githubscm.createReleaseWithGeneratedReleaseNotes(getGitTag(), getBuildBranch(), githubscm.getPreviousTagFromVersion(getGitTag()), getGitAuthorCredsId())
githubscm.updateReleaseBody(getGitTag(), getGitAuthorCredsId())
githubscm.createReleaseWithGeneratedReleaseNotes(getGitTag(), getBuildBranch(), githubscm.getPreviousTagFromVersion(getGitTag()), getGitAuthorPushCredsId())
githubscm.updateReleaseBody(getGitTag(), getGitAuthorPushCredsId())
}
}
}
Expand Down Expand Up @@ -238,17 +238,13 @@ void checkoutRepo(String repo) {
sh "git checkout ${getBuildBranch()}"
}

void mergeAndPush(String prLink, String targetBranch) {
if (prLink != '') {
githubscm.mergePR(prLink, getGitAuthorCredsId())
githubscm.pushObject('origin', targetBranch, getGitAuthorPushCredsId())
void approveAndMergePR(String prLink) {
if (prLink?.trim()) {
githubscm.approvePR(prLink, getGitAuthorPushCredsId())
githubscm.mergePR(prLink, getGitAuthorPushCredsId())
}
}

void mergeAndPush(String prLink) {
mergeAndPush(prLink, getBuildBranch())
}

void tagLatest() {
if (getGitTag() != '') {
githubscm.tagLocalAndRemoteRepository('origin', getGitTag(), getGitAuthorPushCredsId(), env.BUILD_TAG, true)
Expand Down
15 changes: 0 additions & 15 deletions .ci/jenkins/Jenkinsfile.setup-branch
Original file line number Diff line number Diff line change
Expand Up @@ -163,18 +163,3 @@ MavenCommand getMavenCommand() {
boolean isMainBranch() {
return env.IS_MAIN_BRANCH ? env.IS_MAIN_BRANCH.toBoolean() : false
}

String commitAndCreatePR(String commitMsg, String localBranch, String targetBranch) {
def prBody = "Generated by build ${BUILD_TAG}: ${BUILD_URL}"
githubscm.setUserConfigFromCreds(getGitAuthorPushCredsId())
githubscm.commitChanges(commitMsg)
githubscm.pushObject('origin', localBranch, getGitAuthorPushCredsId())
return githubscm.createPR(commitMsg, prBody, targetBranch, getGitAuthorCredsId())
}

void mergeAndPush(String prLink, String targetBranch) {
if (prLink?.trim()) {
githubscm.mergePR(prLink, getGitAuthorCredsId())
githubscm.pushObject('origin', targetBranch, getGitAuthorPushCredsId())
}
}
2 changes: 1 addition & 1 deletion .ci/jenkins/project/Jenkinsfile.nightly
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ void checkoutNewBranch(String repo, String originBranch, String newBranch, Strin
dir(dirName) {
deleteDir()
checkout(githubscm.resolveRepository(repo, getGitAuthor(), originBranch, false, getGitAuthorCredsId()))
sh "git checkout -b ${newBranch}"
githubscm.createBranch(newBranch)
}
}

Expand Down
10 changes: 5 additions & 5 deletions .ci/jenkins/project/Jenkinsfile.post-release
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ pipeline {
// }
// dir(websiteRepository) {
// checkoutRepo(websiteRepository, 'main')
// mergeAndPush(prLink, 'main')
// approveAndMergePR(prLink)
// githubscm.removeRemoteBranch('origin', prBranchName, getGitAuthorPushCredsId())
// }
// }
Expand Down Expand Up @@ -228,10 +228,10 @@ void checkoutTag(String repo, String tagName, String localBranchName = tagName)
sh "git checkout tags/${tagName} -b ${localBranchName}"
}

void mergeAndPush(String prLink, String targetBranch) {
if (prLink != '') {
githubscm.mergePR(prLink, getGitAuthorCredsId())
githubscm.pushObject('origin', targetBranch, getGitAuthorPushCredsId())
void approveAndMergePR(String prLink) {
if (prLink?.trim()) {
githubscm.approvePR(prLink, getGitAuthorPushCredsId())
githubscm.mergePR(prLink, getGitAuthorPushCredsId())
}
}

Expand Down

0 comments on commit 0ed6010

Please sign in to comment.