Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automate release branch update through manifest-commit-lock #5290

Merged
merged 2 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ pipeline {
trim: true
)
choice(
choices: ['MATCH_BUILD_MANIFEST', 'UPDATE_TO_RECENT_COMMITS', 'UPDATE_TO_TAGS'],
choices: ['MATCH_BUILD_MANIFEST', 'UPDATE_TO_RECENT_COMMITS', 'UPDATE_TO_TAGS', 'UPDATE_TO_RELEASE_BRANCH'],
name: 'MANIFEST_LOCK_ACTION',
description: 'The manifest lock action to choose.<br>MATCH_BUILD_MANIFEST: Will update the manifest with commit ID from release candidate build manifest.<br>UPDATE_TO_RECENT_COMMITS: Will update the manifest with component repo release branch head commit.<br>UPDATE_TO_TAGS: Will update the manifest with ref tags',
description: 'The manifest lock action to choose.<br>MATCH_BUILD_MANIFEST: Will update the manifest with commit ID from release candidate build manifest.<br>UPDATE_TO_RECENT_COMMITS: Will update the manifest with component repo release branch head commit.<br>UPDATE_TO_TAGS: Will update the manifest with ref tags.<br>UPDATE_TO_RELEASE_BRANCH: Will update the manifest ref with release branch',
)
string(
name: 'COMPONENTS',
Expand Down Expand Up @@ -176,6 +176,35 @@ pipeline {
}
}
}
stage('UPDATE_TO_RELEASE_BRANCH') {
when {
expression { params.MANIFEST_LOCK_ACTION == 'UPDATE_TO_RELEASE_BRANCH' }
}
steps {
script {
def updateManifest = { String productName ->
def existingManifest = readYaml file: "manifests/${params.RELEASE_VERSION}/${productName}-${params.RELEASE_VERSION}.yml"
def selectedComponents = params.COMPONENTS.isEmpty() ? existingManifest.components : existingManifest.components.findAll { component ->
params.COMPONENTS.split(',').any { it.trim() == component.name }
}
selectedComponents.each { componentName ->
def existingComponent = existingManifest.components.find { it.name == componentName.name }
if (existingComponent) {
def branchRef = params.RELEASE_VERSION.toString().split('\\.')[0..1].join('.')
existingComponent.ref = "${branchRef}"
}
}
writeYaml file: "manifests/${params.RELEASE_VERSION}/${productName}-${params.RELEASE_VERSION}.yml", data: existingManifest, overwrite: true
sh """
yq eval -i '.' manifests/${params.RELEASE_VERSION}/${productName}-${params.RELEASE_VERSION}.yml
sed -i '1s/^/---\\n/' manifests/${params.RELEASE_VERSION}/${productName}-${params.RELEASE_VERSION}.yml
"""
}
updateManifest("opensearch")
updateManifest("opensearch-dashboards")
}
}
}
stage('Create Pull Request') {
steps {
script {
Expand Down
13 changes: 13 additions & 0 deletions tests/jenkins/TestReleaseManifestCommitLock.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,19 @@ class TestReleaseManifestCommitLock extends BuildPipelineTest {
assertCallStack().contains("release-manifest-commit-lock.readYaml({file=manifests/2.0.0/opensearch-dashboards-2.0.0.yml})")
}

@Test
public void testUpdateToReleaseBranch() {
addParam('MANIFEST_LOCK_ACTION', 'UPDATE_TO_RELEASE_BRANCH')
super.testPipeline('jenkins/release-workflows/release-manifest-commit-lock.jenkinsfile',
'tests/jenkins/jenkinsjob-regression-files/release-workflows/testUpdateToReleaseBranch')
assertCallStack().contains('release-manifest-commit-lock.readYaml({file=manifests/2.0.0/opensearch-dashboards-2.0.0.yml})')
assertCallStack().contains("release-manifest-commit-lock.writeYaml({file=manifests/2.0.0/opensearch-2.0.0.yml, data={schema-version=1.0, build={name=OpenSearch, version=2.0.0, qualifier=alpha1}, ci={image={name=opensearchstaging/ci-runner:ci-runner-centos7-opensearch-build-v2, args=-e JAVA_HOME=/opt/java/openjdk-17}}, components=[{name=OpenSearch, ref=2.0, repository=https://github.com/opensearch-project/OpenSearch.git, checks=[gradle:publish, gradle:properties:version]}, {name=common-utils, repository=https://github.com/opensearch-project/common-utils.git, ref=2.0, checks=[gradle:publish, gradle:properties:version]}, {name=job-scheduler, repository=https://github.com/opensearch-project/job-scheduler.git, ref=2.0, checks=[gradle:properties:version, gradle:dependencies:opensearch.version]}]}, overwrite=true})")
assertCallStack().contains("release-manifest-commit-lock.readYaml({file=manifests/2.0.0/opensearch-2.0.0.yml})")
assertCallStack().contains("release-manifest-commit-lock.echo(Skipping stage MATCH_BUILD_MANIFEST)")
assertCallStack().contains("release-manifest-commit-lock.echo(Skipping stage UPDATE_TO_RECENT_COMMITS)")
assertCallStack().contains("release-manifest-commit-lock.echo(Skipping stage UPDATE_TO_TAGS)")
}

@Test
public void testMatchBuildManifest() {
addParam('MANIFEST_LOCK_ACTION', 'MATCH_BUILD_MANIFEST')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ ccc})
)
release-manifest-commit-lock.echo(Skipping stage UPDATE_TO_RECENT_COMMITS)
release-manifest-commit-lock.echo(Skipping stage UPDATE_TO_TAGS)
release-manifest-commit-lock.echo(Skipping stage UPDATE_TO_RELEASE_BRANCH)
release-manifest-commit-lock.stage(Create Pull Request, groovy.lang.Closure)
release-manifest-commit-lock.script(groovy.lang.Closure)
release-manifest-commit-lock.usernamePassword({credentialsId=jenkins-github-bot-token, passwordVariable=GITHUB_TOKEN, usernameVariable=GITHUB_USER})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ ccc})
)
release-manifest-commit-lock.echo(Skipping stage UPDATE_TO_RECENT_COMMITS)
release-manifest-commit-lock.echo(Skipping stage UPDATE_TO_TAGS)
release-manifest-commit-lock.echo(Skipping stage UPDATE_TO_RELEASE_BRANCH)
release-manifest-commit-lock.stage(Create Pull Request, groovy.lang.Closure)
release-manifest-commit-lock.script(groovy.lang.Closure)
release-manifest-commit-lock.usernamePassword({credentialsId=jenkins-github-bot-token, passwordVariable=GITHUB_TOKEN, usernameVariable=GITHUB_USER})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ ccc, repository=https://github.com/opensearch-project/OpenSearch.git, checks=[gr
sed -i '1s/^/---\n/' manifests/2.0.0/opensearch-dashboards-2.0.0.yml
)
release-manifest-commit-lock.echo(Skipping stage UPDATE_TO_TAGS)
release-manifest-commit-lock.echo(Skipping stage UPDATE_TO_RELEASE_BRANCH)
release-manifest-commit-lock.stage(Create Pull Request, groovy.lang.Closure)
release-manifest-commit-lock.script(groovy.lang.Closure)
release-manifest-commit-lock.usernamePassword({credentialsId=jenkins-github-bot-token, passwordVariable=GITHUB_TOKEN, usernameVariable=GITHUB_USER})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
yq eval -i '.' manifests/2.0.0/opensearch-dashboards-2.0.0.yml
sed -i '1s/^/---\n/' manifests/2.0.0/opensearch-dashboards-2.0.0.yml
)
release-manifest-commit-lock.echo(Skipping stage UPDATE_TO_RELEASE_BRANCH)
release-manifest-commit-lock.stage(Create Pull Request, groovy.lang.Closure)
release-manifest-commit-lock.script(groovy.lang.Closure)
release-manifest-commit-lock.usernamePassword({credentialsId=jenkins-github-bot-token, passwordVariable=GITHUB_TOKEN, usernameVariable=GITHUB_USER})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ ccc})
)
release-manifest-commit-lock.echo(Skipping stage UPDATE_TO_RECENT_COMMITS)
release-manifest-commit-lock.echo(Skipping stage UPDATE_TO_TAGS)
release-manifest-commit-lock.echo(Skipping stage UPDATE_TO_RELEASE_BRANCH)
release-manifest-commit-lock.stage(Create Pull Request, groovy.lang.Closure)
release-manifest-commit-lock.script(groovy.lang.Closure)
release-manifest-commit-lock.usernamePassword({credentialsId=jenkins-github-bot-token, passwordVariable=GITHUB_TOKEN, usernameVariable=GITHUB_USER})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ ccc, repository=https://github.com/opensearch-project/OpenSearch.git, checks=[gr
sed -i '1s/^/---\n/' manifests/2.0.0/opensearch-dashboards-2.0.0.yml
)
release-manifest-commit-lock.echo(Skipping stage UPDATE_TO_TAGS)
release-manifest-commit-lock.echo(Skipping stage UPDATE_TO_RELEASE_BRANCH)
release-manifest-commit-lock.stage(Create Pull Request, groovy.lang.Closure)
release-manifest-commit-lock.script(groovy.lang.Closure)
release-manifest-commit-lock.usernamePassword({credentialsId=jenkins-github-bot-token, passwordVariable=GITHUB_TOKEN, usernameVariable=GITHUB_USER})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
sed -i '1s/^/---\n/' manifests/2.0.0/opensearch-dashboards-2.0.0.yml
)
release-manifest-commit-lock.echo(Skipping stage UPDATE_TO_TAGS)
release-manifest-commit-lock.echo(Skipping stage UPDATE_TO_RELEASE_BRANCH)
release-manifest-commit-lock.stage(Create Pull Request, groovy.lang.Closure)
release-manifest-commit-lock.script(groovy.lang.Closure)
release-manifest-commit-lock.usernamePassword({credentialsId=jenkins-github-bot-token, passwordVariable=GITHUB_TOKEN, usernameVariable=GITHUB_USER})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
release-manifest-commit-lock.run()
release-manifest-commit-lock.modernSCM({$class=GitSCMSource, remote=https://github.com/opensearch-project/opensearch-build-libraries.git})
release-manifest-commit-lock.library({identifier=jenkins@6.4.0, retriever=null})
release-manifest-commit-lock.pipeline(groovy.lang.Closure)
release-manifest-commit-lock.timeout({time=2, unit=HOURS})
release-manifest-commit-lock.echo(Executing on agent [docker:[alwaysPull:true, args:, containerPerStageRoot:false, label:Jenkins-Agent-AL2023-X64-M54xlarge-Docker-Host, image:opensearchstaging/ci-runner:ci-runner-centos7-opensearch-build-v3, reuseNode:false, registryUrl:https://public.ecr.aws/, stages:[:]]])
release-manifest-commit-lock.stage(Parameters Check, groovy.lang.Closure)
release-manifest-commit-lock.script(groovy.lang.Closure)
release-manifest-commit-lock.echo(Skipping stage MATCH_BUILD_MANIFEST)
release-manifest-commit-lock.echo(Skipping stage UPDATE_TO_RECENT_COMMITS)
release-manifest-commit-lock.echo(Skipping stage UPDATE_TO_TAGS)
release-manifest-commit-lock.stage(UPDATE_TO_RELEASE_BRANCH, groovy.lang.Closure)
release-manifest-commit-lock.script(groovy.lang.Closure)
release-manifest-commit-lock.readYaml({file=manifests/2.0.0/opensearch-2.0.0.yml})
release-manifest-commit-lock.writeYaml({file=manifests/2.0.0/opensearch-2.0.0.yml, data={schema-version=1.0, build={name=OpenSearch, version=2.0.0, qualifier=alpha1}, ci={image={name=opensearchstaging/ci-runner:ci-runner-centos7-opensearch-build-v2, args=-e JAVA_HOME=/opt/java/openjdk-17}}, components=[{name=OpenSearch, ref=2.0, repository=https://github.com/opensearch-project/OpenSearch.git, checks=[gradle:publish, gradle:properties:version]}, {name=common-utils, repository=https://github.com/opensearch-project/common-utils.git, ref=2.0, checks=[gradle:publish, gradle:properties:version]}, {name=job-scheduler, repository=https://github.com/opensearch-project/job-scheduler.git, ref=2.0, checks=[gradle:properties:version, gradle:dependencies:opensearch.version]}]}, overwrite=true})
release-manifest-commit-lock.sh(
yq eval -i '.' manifests/2.0.0/opensearch-2.0.0.yml
sed -i '1s/^/---\n/' manifests/2.0.0/opensearch-2.0.0.yml
)
release-manifest-commit-lock.readYaml({file=manifests/2.0.0/opensearch-dashboards-2.0.0.yml})
release-manifest-commit-lock.writeYaml({file=manifests/2.0.0/opensearch-dashboards-2.0.0.yml, data={schema-version=1.0, build={name=OpenSearch, version=2.0.0, qualifier=alpha1}, ci={image={name=opensearchstaging/ci-runner:ci-runner-centos7-opensearch-build-v2, args=-e JAVA_HOME=/opt/java/openjdk-17}}, components=[{name=OpenSearch, ref=2.0, repository=https://github.com/opensearch-project/OpenSearch.git, checks=[gradle:publish, gradle:properties:version]}, {name=common-utils, repository=https://github.com/opensearch-project/common-utils.git, ref=2.0, checks=[gradle:publish, gradle:properties:version]}, {name=job-scheduler, repository=https://github.com/opensearch-project/job-scheduler.git, ref=2.0, checks=[gradle:properties:version, gradle:dependencies:opensearch.version]}]}, overwrite=true})
release-manifest-commit-lock.sh(
yq eval -i '.' manifests/2.0.0/opensearch-dashboards-2.0.0.yml
sed -i '1s/^/---\n/' manifests/2.0.0/opensearch-dashboards-2.0.0.yml
)
release-manifest-commit-lock.stage(Create Pull Request, groovy.lang.Closure)
release-manifest-commit-lock.script(groovy.lang.Closure)
release-manifest-commit-lock.usernamePassword({credentialsId=jenkins-github-bot-token, passwordVariable=GITHUB_TOKEN, usernameVariable=GITHUB_USER})
release-manifest-commit-lock.withCredentials([[GITHUB_USER, GITHUB_TOKEN]], groovy.lang.Closure)
release-manifest-commit-lock.sh(
git remote set-url origin "https://opensearch-ci:GITHUB_TOKEN@github.com/opensearch-project/opensearch-build"
git config user.email "opensearch-infra@amazon.com"
git config user.name "opensearch-ci"
git checkout -b manifest-lock
)
release-manifest-commit-lock.sh({returnStdout=true, script=git status --porcelain})
release-manifest-commit-lock.sh(
git status --porcelain | grep '^ M' | cut -d " " -f3 | xargs git add
git commit -sm "Manifest Commit Lock for Release 2.0.0"
git push origin manifest-lock --force
gh pr create --title '[2.0.0] Manifest Commit Lock with action UPDATE_TO_RELEASE_BRANCH' --body 'Manifest Commit Lock for Release 2.0.0 ' -H manifest-lock -B main
)
release-manifest-commit-lock.script(groovy.lang.Closure)
release-manifest-commit-lock.postCleanup()
postCleanup.cleanWs({disableDeferredWipeout=true, deleteDirs=true})