Skip to content

Commit

Permalink
KOGITO-9671 CI: Remove bot account usage (#2921)
Browse files Browse the repository at this point in the history
* KOGITO-9671 CI: Remove bot account usage

* review comments
  • Loading branch information
radtriste committed Aug 2, 2023
1 parent 96f5594 commit dcbd113
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 39 deletions.
31 changes: 13 additions & 18 deletions .ci/jenkins/Jenkinsfile.deploy
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pipeline {

MAVEN_OPTS = '-Xms1024m -Xmx4g'

BOT_BRANCH_HASH = "${util.generateHash(10)}"
PR_BRANCH_HASH = "${util.generateHash(10)}"

// Maven configuration
MAVEN_DEPLOY_LOCAL_DIR = "${WORKSPACE}/maven_deploy_dir"
Expand Down Expand Up @@ -221,8 +221,8 @@ pipeline {
post {
success {
script {
setDeployPropertyIfNeeded("${optaplannerRepository}.pr.source.uri", "https://github.com/${getBotAuthor()}/${optaplannerRepository}")
setDeployPropertyIfNeeded("${optaplannerRepository}.pr.source.ref", getBotBranch())
setDeployPropertyIfNeeded("${optaplannerRepository}.pr.source.uri", "https://github.com/${getGitAuthor()}/${optaplannerRepository}")
setDeployPropertyIfNeeded("${optaplannerRepository}.pr.source.ref", getPRBranch())
setDeployPropertyIfNeeded("${optaplannerRepository}.pr.target.uri", "https://github.com/${getGitAuthor()}/${optaplannerRepository}")
setDeployPropertyIfNeeded("${optaplannerRepository}.pr.target.ref", getBuildBranch())
}
Expand Down Expand Up @@ -345,8 +345,7 @@ String getFallbackBranch(String repo) {

void prepareForPR(String repo) {
dir(repo) {
githubscm.forkRepo(getBotAuthorCredsID())
githubscm.createBranch(getBotBranch())
githubscm.createBranch(getPRBranch())
}
}

Expand All @@ -365,10 +364,10 @@ void commitAndCreatePR(String repo, String buildBranch) {
githubscm.findAndStageNotIgnoredFiles('build.gradle')
githubscm.findAndStageNotIgnoredFiles('antora.yml')
})
githubscm.pushObject('origin', getBotBranch(), getBotAuthorCredsID())
githubscm.pushObject('origin', getPRBranch(), getGitAuthorCredsID())
deployProperties["${repo}.pr.link"] = isRelease() ?
githubscm.createPRWithLabels(commitMsg, prBody, buildBranch, ['DO_NOT_MERGE'] as String[], getBotAuthorCredsID()) :
githubscm.createPR(commitMsg, prBody, buildBranch, getBotAuthorCredsID())
githubscm.createPRWithLabels(commitMsg, prBody, buildBranch, ['DO_NOT_MERGE'] as String[], getGitAuthorCredsID()) :
githubscm.createPR(commitMsg, prBody, buildBranch, getGitAuthorCredsID())
}
}

Expand Down Expand Up @@ -477,6 +476,10 @@ String getGitAuthor() {
return "${GIT_AUTHOR}"
}

String getGitAuthorCredsID() {
retrun env.AUTHOR_CREDS_ID
}

String getBuildBranch() {
return params.BUILD_BRANCH_NAME
}
Expand All @@ -489,16 +492,8 @@ String getDroolsVersion() {
return params.DROOLS_VERSION
}

String getBotBranch() {
return "${getProjectVersion()}-${env.BOT_BRANCH_HASH}"
}

String getBotAuthor() {
return env.GIT_AUTHOR_BOT
}

String getBotAuthorCredsID() {
return env.BOT_CREDENTIALS_ID
String getPRBranch() {
return "${getProjectVersion()}-${env.PR_BRANCH_HASH}"
}

void setDeployPropertyIfNeeded(String key, def value) {
Expand Down
15 changes: 5 additions & 10 deletions .ci/jenkins/Jenkinsfile.promote
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pipeline {

OPTAPLANNER_CI_EMAIL_TO = credentials("${JENKINS_EMAIL_CREDS_ID}")

BOT_BRANCH_HASH = "${util.generateHash(10)}"
PR_BRANCH_HASH = "${util.generateHash(10)}"
}

stages {
Expand Down Expand Up @@ -118,7 +118,7 @@ pipeline {
script {
String nextMicroSnapshotVersion = getNextMicroSnapshotVersion(getProjectVersion())

dir("${optaplannerRepository}-bot") {
dir("${optaplannerRepository}-pr") {
prepareForPR(optaplannerRepository)
String nextSnapshotVersion = getNextMicroSnapshotVersion(getProjectVersion())

Expand Down Expand Up @@ -272,10 +272,6 @@ String getGitAuthorCredsID() {
return env.AUTHOR_CREDS_ID
}

String getBotAuthorCredsID() {
return env.BOT_CREDENTIALS_ID
}

String getDeployPrLink(String repo) {
return getDeployProperty("${repo}.pr.link")
}
Expand All @@ -289,7 +285,7 @@ void setPipelinePrLink(String repo, String value) {
}

String getSnapshotBranch() {
return "${getNextMicroSnapshotVersion(getProjectVersion()).toLowerCase()}-${env.BOT_BRANCH_HASH}"
return "${getNextMicroSnapshotVersion(getProjectVersion()).toLowerCase()}-${env.PR_BRANCH_HASH}"
}

//////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -333,16 +329,15 @@ void tagLatest() {

void prepareForPR(String repo) {
checkoutRepo(repo)
githubscm.forkRepo(getBotAuthorCredsID())
githubscm.createBranch(getSnapshotBranch())
}

String commitAndCreatePR(String commitMsg, Closure precommit, String localBranch, String targetBranch) {
def prBody = "Generated by build ${BUILD_TAG}: ${BUILD_URL}"

githubscm.commitChanges(commitMsg, precommit)
githubscm.pushObject('origin', localBranch, getBotAuthorCredsID())
return githubscm.createPR(commitMsg, prBody, targetBranch, getBotAuthorCredsID())
githubscm.pushObject('origin', localBranch, getGitAuthorCredsID())
return githubscm.createPR(commitMsg, prBody, targetBranch, getGitAuthorCredsID())
}

String commitAndCreatePR(String commitMsg) {
Expand Down
3 changes: 0 additions & 3 deletions .ci/jenkins/config/branch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ git:
name: kiegroup
credentials_id: kie-ci5
token_credentials_id: kie-ci5-token
bot_author:
name: bsig-gh-bot
credentials_id: bsig-gh-bot
fork_author:
name: kie-ci
credentials_id: kie-ci
Expand Down
4 changes: 0 additions & 4 deletions .ci/jenkins/dsl/jobs.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,6 @@ void setupDeployJob(JobType jobType, String envName = '') {

AUTHOR_CREDS_ID: "${GIT_AUTHOR_CREDENTIALS_ID}",
GITHUB_TOKEN_CREDS_ID: "${GIT_AUTHOR_TOKEN_CREDENTIALS_ID}",
GIT_AUTHOR_BOT: "${GIT_BOT_AUTHOR_NAME}",
BOT_CREDENTIALS_ID: "${GIT_BOT_AUTHOR_CREDENTIALS_ID}",

MAVEN_DEPENDENCIES_REPOSITORY: "${MAVEN_ARTIFACTS_REPOSITORY}",
MAVEN_DEPLOY_REPOSITORY: "${MAVEN_ARTIFACTS_REPOSITORY}",
Expand Down Expand Up @@ -348,8 +346,6 @@ void setupPromoteJob(JobType jobType) {

AUTHOR_CREDS_ID: "${GIT_AUTHOR_CREDENTIALS_ID}",
GITHUB_TOKEN_CREDS_ID: "${GIT_AUTHOR_TOKEN_CREDENTIALS_ID}",
GIT_AUTHOR_BOT: "${GIT_BOT_AUTHOR_NAME}",
BOT_CREDENTIALS_ID: "${GIT_BOT_AUTHOR_CREDENTIALS_ID}",

MAVEN_SETTINGS_CONFIG_FILE_ID: "${MAVEN_SETTINGS_FILE_ID}",
MAVEN_DEPENDENCIES_REPOSITORY: "${MAVEN_ARTIFACTS_REPOSITORY}",
Expand Down
8 changes: 4 additions & 4 deletions .ci/jenkins/project/Jenkinsfile.post-release
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pipeline {

OPTAPLANNER_CI_EMAIL_TO = credentials("${JENKINS_EMAIL_CREDS_ID}")

BOT_BRANCH_HASH = "${util.generateHash(10)}"
PR_BRANCH_HASH = "${util.generateHash(10)}"
}

stages {
Expand Down Expand Up @@ -98,8 +98,8 @@ pipeline {
script {
final String websiteRepository = 'optaplanner-website'
String prLink = null
String prBranchName = "${getProjectVersion().toLowerCase()}-${env.BOT_BRANCH_HASH}"
dir("$websiteRepository-bot") {
String prBranchName = "${getProjectVersion().toLowerCase()}-${env.PR_BRANCH_HASH}"
dir("$websiteRepository-pr") {
checkoutRepo(websiteRepository, 'main') // there is no other branch
githubscm.createBranch(prBranchName)

Expand Down Expand Up @@ -182,7 +182,7 @@ String getGitAuthorCredsID() {
}

String getSnapshotBranch() {
return "${getNextMicroSnapshotVersion(getProjectVersion()).toLowerCase()}-${env.BOT_BRANCH_HASH}"
return "${getNextMicroSnapshotVersion(getProjectVersion()).toLowerCase()}-${env.PR_BRANCH_HASH}"
}

//////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit dcbd113

Please sign in to comment.