Skip to content

Commit

Permalink
Add release-chores workflow
Browse files Browse the repository at this point in the history
Signed-off-by: Sayali Gaikawad <gaiksaya@amazon.com>
  • Loading branch information
gaiksaya committed Feb 15, 2025
1 parent ca41b1b commit 30a34ab
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/groovy-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
69 changes: 69 additions & 0 deletions jenkins/release-workflows/release-chores.jenkinsfile
Original file line number Diff line number Diff line change
@@ -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()
}
}
}
}
78 changes: 78 additions & 0 deletions tests/jenkins/TestReleaseChores.groovy
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 30a34ab

Please sign in to comment.