From 30a34ab47374ed940d624130f54ec17c262b1190 Mon Sep 17 00:00:00 2001 From: Sayali Gaikawad Date: Thu, 13 Feb 2025 17:17:07 -0800 Subject: [PATCH] Add release-chores workflow Signed-off-by: Sayali Gaikawad --- .github/workflows/groovy-tests.yml | 2 +- .../release-chores.jenkinsfile | 69 ++++++++++++++++ tests/jenkins/TestReleaseChores.groovy | 78 +++++++++++++++++++ 3 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 jenkins/release-workflows/release-chores.jenkinsfile create mode 100644 tests/jenkins/TestReleaseChores.groovy diff --git a/.github/workflows/groovy-tests.yml b/.github/workflows/groovy-tests.yml index e77f602650..b128276ab6 100644 --- a/.github/workflows/groovy-tests.yml +++ b/.github/workflows/groovy-tests.yml @@ -14,4 +14,4 @@ jobs: - uses: actions/checkout@v3 - name: Run Tests run: | - ./gradlew test --info + ./gradlew test --info -Ppipeline.stack.write=true --tests=TestReleaseChores diff --git a/jenkins/release-workflows/release-chores.jenkinsfile b/jenkins/release-workflows/release-chores.jenkinsfile new file mode 100644 index 0000000000..6bb561af77 --- /dev/null +++ b/jenkins/release-workflows/release-chores.jenkinsfile @@ -0,0 +1,69 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +lib = library(identifier: 'jenkins@refactor-classes', retriever: modernSCM([ + $class: 'GitSCMSource', + remote: 'https://github.com/gaiksaya/opensearch-build-libraries.git', +])) + +pipeline { + options { + timeout(time: 1, unit: 'HOURS') + } + agent { + docker { + label 'Jenkins-Agent-AL2023-X64-M54xlarge-Docker-Host' + image 'opensearchstaging/ci-runner:ci-runner-centos7-opensearch-build-v3' + registryUrl 'https://public.ecr.aws/' + alwaysPull true + } + } + parameters { + string( + name: 'RELEASE_VERSION', + description: "Required: On-going release version, e.g. 2.0.0", + trim: true + ) + string( + name: 'RELEASE_CHORE', + description: "Required: What release chore you wanna do? e.g: 'add_rc_details_comment'", + trim: true + ) + } + stages { + stage('Parameter check') { + steps { + script { + if (!(RELEASE_VERSION && RELEASE_CHORE)) { + error('Required parameters are missing. Please provide the mandatory arguments RELEASE_VERSION and RELEASE_CHORE') + } + } + } + } + stage('Add RC details comment') { + when { + expression { params.RELEASE_CHORE == 'add_rc_details_comment' } + } + steps { + script { + addRcDetailsComment( + version: "${params.RELEASE_VERSION}" + ) + } + } + } + } + post() { + always { + script { + postCleanup() + } + } + } +} diff --git a/tests/jenkins/TestReleaseChores.groovy b/tests/jenkins/TestReleaseChores.groovy new file mode 100644 index 0000000000..e2893071f6 --- /dev/null +++ b/tests/jenkins/TestReleaseChores.groovy @@ -0,0 +1,78 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +import jenkins.tests.BuildPipelineTest +import org.junit.Before +import org.junit.Test +import org.yaml.snakeyaml.Yaml + +import static com.lesfurets.jenkins.unit.MethodCall.callArgsToString +import static org.hamcrest.CoreMatchers.equalTo +import static org.hamcrest.CoreMatchers.hasItem +import static org.hamcrest.MatcherAssert.assertThat + +import static com.lesfurets.jenkins.unit.global.lib.LibraryConfiguration.library +import static com.lesfurets.jenkins.unit.global.lib.GitSource.gitSource + +class TestReleaseChores extends BuildPipelineTest { + + @Override + @Before + void setUp() { + helper.registerSharedLibrary( + library().name('jenkins') + .defaultVersion('refactor-classes') + .allowOverride(true) + .implicit(true) + .targetPath('vars') + .retriever(gitSource('https://github.com/gaiksaya/opensearch-build-libraries.git')) + .build() + ) + + super.setUp() + helper.registerAllowedMethod('withCredentials', [Map]) + binding.setVariable('env', [ + 'METRICS_HOST_URL' : 'sample.url', + 'AWS_ACCESS_KEY_ID' : 'abc', + 'AWS_SECRET_ACCESS_KEY': 'xyz', + 'AWS_SESSION_TOKEN' : 'sampleToken' + ]) + helper.registerAllowedMethod('withCredentials', [Map, Closure], { args, closure -> + closure.delegate = delegate + return helper.callClosure(closure) + }) + helper.registerAllowedMethod('withAWS', [Map, Closure], { args, closure -> + closure.delegate = delegate + return helper.callClosure(closure) + }) + } + + @Test + public void testVerifyParameters() { + addParam('RELEASE_VERSION', '') + addParam('RELEASE_CHORE', 'add_rc_details_comment') + runScript('jenkins/release-workflows/release-chores.jenkinsfile') + assertThat(getCommandExecutions('error', ''), hasItem('Required parameters are missing. Please provide the mandatory arguments RELEASE_VERSION and RELEASE_CHORE')) + } + + def getCommandExecutions(methodName, command) { + def shCommands = helper.callStack.findAll { + call -> + call.methodName == methodName + }. + collect { + call -> + callArgsToString(call) + }.findAll { + shCommand -> + shCommand.contains(command) + } + return shCommands + } +}