Skip to content

Commit

Permalink
KOGITO-9676 CI: Promote call setup-branch job (#1665)
Browse files Browse the repository at this point in the history
  • Loading branch information
radtriste authored Aug 9, 2023
1 parent 217642d commit 3fee623
Showing 1 changed file with 11 additions and 82 deletions.
93 changes: 11 additions & 82 deletions .ci/jenkins/Jenkinsfile.promote
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ pipeline {
OPENSHIFT_CREDS_KEY = 'OPENSHIFT_CREDS'

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

GITHUB_REPO = "${REPO_NAME}" // for github-release cli
}

stages {
Expand All @@ -45,11 +43,8 @@ pipeline {

readDeployProperties()

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

// Login old registry
if (isOldImageInOpenshiftRegistry()) {
Expand All @@ -69,11 +64,11 @@ pipeline {
checkoutRepo()
}

installGitHubReleaseCLI()
cloud.installSkopeo()
}
}
}

stage('Promote images') {
steps {
script {
Expand All @@ -83,10 +78,8 @@ pipeline {
}
}
}

stage('Merge PR and tag') {
when {
expression { return isRelease() }
}
steps {
script {
dir(getRepoName()) {
Expand All @@ -96,47 +89,19 @@ pipeline {
githubscm.mergePR(prLink, getGitAuthorCredsID())
githubscm.pushObject('origin', getBuildBranch(), getGitAuthorCredsID())
}

if (getGitTag()) {
createRelease()
}
}
}
}
}
stage('Set next version')
{
when {
expression { return isRelease() }
}

stage('Create release') {
steps {
script {
String prLink = ''
String nextVersion = getNextVersion()
dir('pr') { // Use different folder from `Update PR with released Maven artifacts` to avoid conflicts
// Prepare PR
checkoutRepo()
githubscm.createBranch(getSnapshotBranch())

// Update version to next snapshot
versionCmd = "python3 scripts/manage-kogito-version.py --bump-to ${nextVersion} --artifacts-version ${getKogitoArtifactsNextVersion()} --confirm"
if (getBuildBranch() != 'main') {
versionCmd += " --examples-ref ${getBuildBranch()}"
}
runPythonCommand(versionCmd)

def commitMsg = "[${getBuildBranch()}] Update snapshot version to ${nextVersion}"
def prBody = "Generated by build ${BUILD_TAG}: ${BUILD_URL}"
githubscm.commitChanges(commitMsg)
githubscm.pushObject('origin', getSnapshotBranch(), getGitAuthorCredsID())
prLink = githubscm.createPR(commitMsg, prBody, getBuildBranch(), getGitAuthorCredsID())
}
dir(getRepoName()) {
if (prLink) {
githubscm.mergePR(prLink, getGitAuthorCredsID())
githubscm.pushObject('origin', getBuildBranch(), getGitAuthorCredsID())
}
if (githubscm.isReleaseExist(getGitTag(), getGitAuthorCredsID())) {
githubscm.deleteReleaseAndTag(getGitTag(), getGitAuthorCredsID())
}
githubscm.createReleaseWithGeneratedReleaseNotes(getGitTag(), getBuildBranch(), githubscm.getPreviousTag(getGitTag()), getGitAuthorCredsID())
githubscm.updateReleaseBody(getGitTag(), getGitAuthorCredsID())
}
}
}
Expand Down Expand Up @@ -169,10 +134,6 @@ String getNotificationSubject() {
return "[${getBuildBranch()}] Kogito Images"
}

void installGitHubReleaseCLI() {
sh 'go install github.com/github-release/github-release@latest'
}

void checkoutRepo() {
deleteDir()
checkout(githubscm.resolveRepository(getRepoName(), getGitAuthor(), getBuildBranch(), false))
Expand Down Expand Up @@ -217,14 +178,6 @@ void makeQuayNewImagesPublic() {
}
}

void createRelease() {
if(githubscm.isReleaseExist(getGitTag(), getGitAuthorCredsID())) {
githubscm.deleteReleaseAndTag(getGitTag(), getGitAuthorCredsID())
}
githubscm.createReleaseWithGeneratedReleaseNotes(getGitTag(), getBuildBranch(), githubscm.getPreviousTag(getGitTag()), getGitAuthorCredsID())
githubscm.updateReleaseBody(getGitTag(), getGitAuthorCredsID())
}

String getOldImageFullTag(String imageName) {
return "${getOldImageRegistry()}/${getOldImageNamespace()}/${getFinalImageName(imageName, getOldImageNameSuffix())}:${getOldImageTag()}"
}
Expand Down Expand Up @@ -269,6 +222,7 @@ void loginContainerRegistry(String registry, String credsId) {
sh "${env.CONTAINER_ENGINE} login -u ${REGISTRY_USER} -p ${REGISTRY_PWD} ${env.CONTAINER_ENGINE_TLS_OPTIONS ?: ''} ${registry}"
}
}

void readDeployProperties() {
String deployUrl = params.DEPLOY_BUILD_URL
if (deployUrl != '') {
Expand Down Expand Up @@ -300,10 +254,6 @@ String getParamOrDeployProperty(String paramKey, String deployPropertyKey) {
// Utils
////////////////////////////////////////////////////////////////////////

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

String getRepoName() {
return env.REPO_NAME
}
Expand All @@ -325,10 +275,6 @@ String getBuildBranch() {
return params.BUILD_BRANCH_NAME
}

String getPRSourceBranch() {
return getDeployProperty("${getRepoName()}.pr.source.ref")
}

String getGitAuthor() {
return env.GIT_AUTHOR
}
Expand All @@ -337,23 +283,6 @@ String getGitAuthorCredsID() {
return env.AUTHOR_CREDS_ID
}

String getMavenArtifactRepository() {
return env.MAVEN_ARTIFACT_REPOSITORY ?: ''
}

String getNextVersion() {
return util.getNextVersion(getProjectVersion(), 'micro', 'snapshot')
}

// To be later changed by artifacts version parameter
String getKogitoArtifactsNextVersion() {
return util.getNextVersion(getKogitoArtifactsVersion(), 'micro', 'SNAPSHOT')
}

String getSnapshotBranch() {
return "${getNextVersion()}-${env.PR_BRANCH_HASH}"
}

boolean isQuayRegistry(String registry) {
return registry == 'quay.io'
}
Expand Down

0 comments on commit 3fee623

Please sign in to comment.