Skip to content

Commit

Permalink
KOGITO-9676 Promote calls setup-branch (#2929)
Browse files Browse the repository at this point in the history
* KOGITO-9676 Promote calls setup-branch

* update
  • Loading branch information
radtriste authored Aug 9, 2023
1 parent ac9287f commit a861969
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 166 deletions.
183 changes: 19 additions & 164 deletions .ci/jenkins/Jenkinsfile.promote
Original file line number Diff line number Diff line change
Expand Up @@ -51,53 +51,53 @@ pipeline {

readDeployProperties()

if (isRelease()) {
// Verify version is set and if on right release branch
assert getProjectVersion()

assert getBuildBranch() == util.getReleaseBranchFromVersion(getProjectVersion())
}
// Verify version is set and if on right release branch
assert getProjectVersion()
assert getBuildBranch() == util.getReleaseBranchFromVersion(getProjectVersion())

checkout scm // To make sure the repository containing the script is available on the Jenkins node.
imageUtils = load '.ci/jenkins/scripts/imageUtils.groovy'
}
}
}

stage('Merge OptaPlanner deploy PR and tag') {
when {
expression { return isRelease() }
}
stage('Merge OptaPlanner deploy PR, tag and create release') {
steps {
script {
dir(optaplannerRepository) {
checkoutRepo(optaplannerRepository)
mergeAndPush(getDeployPrLink(optaplannerRepository))
tagLatest()

if(githubscm.isReleaseExist(getGitTag(), getGitAuthorCredsID())) {
githubscm.deleteRelease(getGitTag(), getGitAuthorCredsID())
}
githubscm.createReleaseWithGeneratedReleaseNotes(getGitTag(), getBuildBranch(), githubscm.getPreviousTag(getGitTag()), getGitAuthorCredsID())
githubscm.updateReleaseBody(getGitTag(), getGitAuthorCredsID())
}
}
}
}

stage('Merge OptaPlanner Quickstarts PR and tag') {
when {
expression { return isRelease() }
}
stage('Merge OptaPlanner Quickstarts PR, tag and create release') {
steps {
script {
dir(quickstartsRepository) {
checkoutRepo(quickstartsRepository)
mergeAndPush(getDeployPrLink(quickstartsRepository))
tagLatest()

if(githubscm.isReleaseExist(getGitTag(), getGitAuthorCredsID())) {
githubscm.deleteRelease(getGitTag(), getGitAuthorCredsID())
}
githubscm.createReleaseWithGeneratedReleaseNotes(getGitTag(), getBuildBranch(), githubscm.getPreviousTag(getGitTag()), getGitAuthorCredsID())
githubscm.updateReleaseBody(getGitTag(), getGitAuthorCredsID())
}
}
}
}

stage('Upload OptaPlanner documentation') {
when {
expression { return isRelease() }
}
steps {
script {
getMavenCommand()
Expand All @@ -110,59 +110,7 @@ pipeline {
}
}

stage('Set OptaPlanner next snapshot version') {
when {
expression { return isRelease() }
}
steps {
script {
String nextMicroSnapshotVersion = getNextMicroSnapshotVersion(getProjectVersion())

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

maven.mvnVersionsSet(getMavenCommand(), nextSnapshotVersion, true)

String prLink = commitAndCreatePR("[${getBuildBranch()}] Update snapshot version to ${nextMicroSnapshotVersion}")
setPipelinePrLink(optaplannerRepository, prLink)
}
dir(optaplannerRepository) {
sh "git checkout ${getBuildBranch()}"
mergeAndPush(getPipelinePrLink(optaplannerRepository))
runMavenDeploy(getMavenCommand())
}
}
}
}

stage('Set Quickstarts next snapshot version') {
when {
expression { return isRelease() }
}
steps {
script {
String nextMicroSnapshotVersion = getNextMicroSnapshotVersion(getProjectVersion())
String botQuickstartsRepository = "${quickstartsRepository}-bot"
dir(botQuickstartsRepository) {
prepareForPR(quickstartsRepository)
updateQuickstartsVersions(nextMicroSnapshotVersion)

String prLink = commitAndCreatePR(("[${getBuildBranch()}] Update snapshot version to ${nextMicroSnapshotVersion}"))
setPipelinePrLink(quickstartsRepository, prLink)
}
dir(quickstartsRepository) {
sh "git checkout ${getBuildBranch()}"
mergeAndPush(getPipelinePrLink(quickstartsRepository))
}
}
}
}

stage('Push the final OptaPlanner operator image') {
when {
expression { return isRelease() }
}
steps {
script {
pushOperatorFinalImage()
Expand Down Expand Up @@ -232,30 +180,14 @@ String getParamOrDeployProperty(String paramKey, String deployPropertyKey) {
// Getter / Setter
//////////////////////////////////////////////////////////////////////////////

boolean shouldDeployToRepository() {
return env.MAVEN_DEPLOY_REPOSITORY || isNotTestingBuild()
}

boolean isNotTestingBuild() {
return getGitAuthor() == 'kiegroup'
}

boolean isRelease() {
return env.RELEASE ? env.RELEASE.toBoolean() : false
}

String getProjectVersion() {
return getParamOrDeployProperty('PROJECT_VERSION', 'project.version')
}

String getNextMicroSnapshotVersion(String currentVersion) {
return util.getNextVersion(currentVersion, 'micro')
}

String getNextMinorSnapshotVersion(String currentVersion) {
return util.getNextVersion(currentVersion, 'minor')
}

String getGitTag() {
return params.GIT_TAG != '' ? params.GIT_TAG : getProjectVersion()
}
Expand All @@ -276,38 +208,15 @@ String getDeployPrLink(String repo) {
return getDeployProperty("${repo}.pr.link")
}

String getPipelinePrLink(String repo) {
return pipelineProperties["${repo}.pr.link"]
}

void setPipelinePrLink(String repo, String value) {
pipelineProperties["${repo}.pr.link"] = value
}

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

//////////////////////////////////////////////////////////////////////////////
// Git
//////////////////////////////////////////////////////////////////////////////

void checkoutRepo(String repo, String branch) {
deleteDir()
checkout(githubscm.resolveRepository(repo, getGitAuthor(), branch, false))
// need to manually checkout branch since on a detached branch after checkout command
sh "git checkout ${branch}"
}

void checkoutRepo(String repo) {
checkoutRepo(repo, getBuildBranch())
}

void checkoutTag(String repo, String tagName, String localBranchName) {
deleteDir()
checkout(githubscm.resolveRepository(repo, getGitAuthor(), getBuildBranch(), false))
// Need to manually checkout branch since we are in 'detached HEAD' state after the git checkout command.
sh "git checkout tags/${tagName} -b ${localBranchName}"
// need to manually checkout branch since on a detached branch after checkout command
sh "git checkout ${getBuildBranch()}"
}

void mergeAndPush(String prLink, String targetBranch) {
Expand All @@ -327,26 +236,6 @@ void tagLatest() {
}
}

void prepareForPR(String repo) {
checkoutRepo(repo)
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, getGitAuthorCredsID())
return githubscm.createPR(commitMsg, prBody, targetBranch, getGitAuthorCredsID())
}

String commitAndCreatePR(String commitMsg) {
return commitAndCreatePR(commitMsg, {
githubscm.findAndStageNotIgnoredFiles('pom.xml')
githubscm.findAndStageNotIgnoredFiles('build.gradle')
}, getSnapshotBranch(), getBuildBranch())
}

void uploadDistribution(String directory) {
if (isNotTestingBuild()) {
echo "uploadDistribution for ${directory}"
Expand All @@ -372,32 +261,6 @@ MavenCommand getMavenCommand() {
return mvnCmd
}

void runMavenDeploy(MavenCommand mvnCmd) {
if (shouldDeployToRepository()) {
mvnCmd = mvnCmd.clone()
if (env.MAVEN_DEPLOY_REPOSITORY) {
mvnCmd.withDeployRepository(env.MAVEN_DEPLOY_REPOSITORY)
}
mvnCmd.skipTests(true).run('clean deploy')
} else {
echo 'Testing environment and no specific deploy repository given => no deployment'
}
}

void updateQuickstartsVersions(String newVersion) {
maven.mvnSetVersionProperty('version.org.optaplanner', newVersion)
maven.mvnVersionsUpdateParentAndChildModules(newVersion, true)
gradleVersionsUpdate(newVersion)

assert !sh(script:
"grep -Rn \"${getProjectVersion()}\" --include={pom.xml,build.gradle} | " +
'cat', returnStdout: true)
}

void gradleVersionsUpdate(String newVersion) {
sh "find . -name build.gradle -exec sed -i -E 's/def optaplannerVersion = \"[^\"\\s]+\"/def optaplannerVersion = \"${newVersion}\"/' {} \\;"
}

/* OptaPlanner Operator */

String getOperatorImageRegistry() {
Expand Down Expand Up @@ -446,11 +309,3 @@ void removeOperatorImageTemporaryTag() {
+ "The tag should be removed manually."
}
}

boolean isStream8() {
return env.OPTAPLANNER_LATEST_STREAM == '8'
}

boolean isStream9() {
return env.OPTAPLANNER_LATEST_STREAM == '9'
}
2 changes: 1 addition & 1 deletion .ci/jenkins/dsl/jobs.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void createProjectSetupBranchJob() {
KogitoJobTemplate.createPipelineJob(this, jobParams)?.with {
parameters {
stringParam('OPTAPLANNER_VERSION', '', 'OptaPlanner version')
booleanParam('DEPLOY_ARTIFACTS', true, 'Deploy artifacts')
booleanParam('DEPLOY', true, 'Deploy artifacts')
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions .ci/jenkins/project/Jenkinsfile.release
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@ pipeline {
}
}
}

stage('Setup next snapshot version') {
steps {
script {
def buildParams = []
addStringParam(buildParams, 'OPTAPLANNER_VERSION', util.getNextVersion(getOptaPlannerVersion(), 'micro'))
build(job: '../setup-branch/0-setup-branch', wait: false, parameters: buildParams, propagate: false)
}
}
}
}
post {
always {
Expand Down
2 changes: 1 addition & 1 deletion .ci/jenkins/project/Jenkinsfile.setup-branch
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pipeline {
// Launch the nightly to deploy all artifacts from the branch
stage('Launch the nightly') {
when {
expression { return params.DEPLOY_ARTIFACTS }
expression { return params.DEPLOY }
}
steps {
script {
Expand Down

0 comments on commit a861969

Please sign in to comment.