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

Rc comment #50

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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
}
}