Skip to content

Commit

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

* review comments

---------

Co-authored-by: radtriste <[email protected]>
  • Loading branch information
radtriste and radtriste authored Aug 2, 2023
1 parent 33753e1 commit bee53d4
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 63 deletions.
33 changes: 12 additions & 21 deletions .ci/jenkins/Jenkinsfile.deploy
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pipeline {
// Keep here for visibility
MAVEN_OPTS = '-Xms1024m -Xmx4g'

BOT_BRANCH_HASH = "${util.generateHash(10)}"
PR_BRANCH_HASH = "${util.generateHash(10)}"
MAVEN_DEPLOY_LOCAL_DIR = "${WORKSPACE}/maven_deploy_dir"
}

Expand Down Expand Up @@ -82,7 +82,7 @@ pipeline {
steps {
script {
dir(getRepoName()) {
prepareForPR()
githubscm.createBranch(getPRBranch())
}
}
}
Expand Down Expand Up @@ -178,8 +178,8 @@ pipeline {
post {
success {
script {
setDeployPropertyIfNeeded("${getRepoName()}.pr.source.uri", "https://github.com/${getBotAuthor()}/${getRepoName()}")
setDeployPropertyIfNeeded("${getRepoName()}.pr.source.ref", getBotBranch())
setDeployPropertyIfNeeded("${getRepoName()}.pr.source.uri", "https://github.com/${getGitAuthor()}/${getRepoName()}")
setDeployPropertyIfNeeded("${getRepoName()}.pr.source.ref", getPRBranch())
setDeployPropertyIfNeeded("${getRepoName()}.pr.target.uri", "https://github.com/${getGitAuthor()}/${getRepoName()}")
setDeployPropertyIfNeeded("${getRepoName()}.pr.target.ref", getBuildBranch())
}
Expand Down Expand Up @@ -215,18 +215,13 @@ void checkoutRepo() {
checkout(githubscm.resolveRepository(getRepoName(), getGitAuthor(), getBuildBranch(), false))
}

void prepareForPR() {
githubscm.forkRepo(getBotAuthorCredsID())
githubscm.createBranch(getBotBranch())
}

void commitAndCreatePR() {
def commitMsg = "[${getBuildBranch()}] Update version to ${getProjectVersion()}"
def prBody = "Generated by build ${BUILD_TAG}: ${BUILD_URL}.\nPlease do not merge, it should be merged automatically."

githubscm.commitChanges(commitMsg, { githubscm.findAndStageNotIgnoredFiles('pom.xml') })
githubscm.pushObject('origin', getBotBranch(), getBotAuthorCredsID())
deployProperties["${getRepoName()}.pr.link"] = githubscm.createPRWithLabels(commitMsg, prBody, getBuildBranch(), ['skip-ci'] as String[], getBotAuthorCredsID())
githubscm.pushObject('origin', getPRBranch(), getGitAuthorCredsID())
deployProperties["${getRepoName()}.pr.link"] = githubscm.createPRWithLabels(commitMsg, prBody, getBuildBranch(), ['skip-ci'] as String[], getGitAuthorCredsID())
}

void sendNotification() {
Expand Down Expand Up @@ -266,6 +261,10 @@ String getGitAuthor() {
return "${GIT_AUTHOR}"
}

String getGitAuthorCredsID() {
retrun env.AUTHOR_CREDS_ID
}

String getBuildBranch() {
return params.BUILD_BRANCH_NAME
}
Expand All @@ -278,16 +277,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
23 changes: 7 additions & 16 deletions .ci/jenkins/Jenkinsfile.promote
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pipeline {

KOGITO_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 @@ -91,8 +91,9 @@ pipeline {
}
steps {
script {
dir('bot') {
prepareForPR()
dir('pr') {
checkoutRepo()
githubscm.createBranch(getSnapshotBranch())

maven.mvnVersionsSet(getMavenCommand(), getSnapshotVersion(), true)
maven.mvnSetVersionProperty(getMavenCommand(), 'version.org.kie', getDroolsSnapshotVersion())
Expand Down Expand Up @@ -219,10 +220,6 @@ String getGitAuthorCredsID() {
return env.AUTHOR_CREDS_ID
}

String getBotAuthorCredsID() {
return env.BOT_CREDENTIALS_ID
}

String getDeployPrLink() {
return getDeployProperty("${getRepoName()}.pr.link")
}
Expand All @@ -236,7 +233,7 @@ void setPipelinePrLink(String value) {
}

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

//////////////////////////////////////////////////////////////////////////////
Expand All @@ -263,19 +260,13 @@ void tagLatest() {
}
}

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

void commitAndCreatePR() {
def commitMsg = "[${getBuildBranch()}] Update project version to ${getSnapshotVersion()}"
def prBody = "Generated by build ${BUILD_TAG}: ${BUILD_URL}.\nPlease do not merge, it should be merged automatically."

githubscm.commitChanges(commitMsg, { githubscm.findAndStageNotIgnoredFiles('pom.xml') })
githubscm.pushObject('origin', getSnapshotBranch(), getBotAuthorCredsID())
setPipelinePrLink(githubscm.createPR(commitMsg, prBody, getBuildBranch(), getBotAuthorCredsID()))
githubscm.pushObject('origin', getSnapshotBranch(), getGitAuthorCredsID())
setPipelinePrLink(githubscm.createPR(commitMsg, prBody, getBuildBranch(), getGitAuthorCredsID()))
}

MavenCommand getMavenCommand(String directory = '') {
Expand Down
5 changes: 1 addition & 4 deletions .ci/jenkins/dsl/jobs.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,7 @@ 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_UPLOAD_REPOSITORY_URL}",
MAVEN_REPO_CREDS_ID: "${MAVEN_ARTIFACTS_UPLOAD_REPOSITORY_CREDS_ID}",
Expand Down Expand Up @@ -232,8 +231,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
24 changes: 3 additions & 21 deletions .ci/jenkins/tests/src/test/vars/JenkinsfileDeploy.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -53,32 +53,14 @@ class JenkinsfileDeploy extends JenkinsPipelineSpecification {
output == 'VERSION'
}
def '[Jenkinsfile.deploy] getBotBranch with version param' () {
def '[Jenkinsfile.deploy] getPRBranch with version param' () {
setup:
Jenkinsfile.getBinding().setVariable('env', ['BOT_BRANCH_HASH' : 'HASH'])
Jenkinsfile.getBinding().setVariable('env', ['PR_BRANCH_HASH' : 'HASH'])
Jenkinsfile.getBinding().setVariable('params', ['PROJECT_VERSION' : 'VERSION'])
when:
def output = Jenkinsfile.getBotBranch()
def output = Jenkinsfile.getPRBranch()
then:
output == 'VERSION-HASH'
}
def '[Jenkinsfile.deploy] getBotAuthor with env' () {
setup:
Jenkinsfile.getBinding().setVariable('env', ['GIT_AUTHOR_BOT' : 'AUTHOR_BOT'])
when:
def output = Jenkinsfile.getBotAuthor()
then:
output == 'AUTHOR_BOT'
}
def '[Jenkinsfile.deploy] getBotAuthorCredsID with env' () {
setup:
Jenkinsfile.getBinding().setVariable('env', ['BOT_CREDENTIALS_ID' : 'CREDS_BOT_ID'])
when:
def output = Jenkinsfile.getBotAuthorCredsID()
then:
output == 'CREDS_BOT_ID'
}
}
2 changes: 1 addition & 1 deletion .ci/jenkins/tests/src/test/vars/JenkinsfilePromote.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ class JenkinsfilePromote extends JenkinsPipelineSpecification {
Jenkinsfile.getBinding().setVariable('params', ['PROJECT_VERSION' : '1.0.0'])
explicitlyMockPipelineVariable('util')
getPipelineMock('util.getNextVersion')('1.0.0', 'micro') >> { return '1.0.1-SNAPSHOT' }
Jenkinsfile.getBinding().setVariable('env', ['BOT_BRANCH_HASH' : 'anything'])
Jenkinsfile.getBinding().setVariable('env', ['PR_BRANCH_HASH' : 'anything'])
when:
def value = Jenkinsfile.getSnapshotBranch()
then:
Expand Down

0 comments on commit bee53d4

Please sign in to comment.