Skip to content

Commit

Permalink
Upgrade groovy library for Validation Workflow (#388)
Browse files Browse the repository at this point in the history
Signed-off-by: Divya Madala <[email protected]>
  • Loading branch information
Divyaasm authored Feb 23, 2024
1 parent 120cc3a commit 8fe1005
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 31 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ jacocoTestReport {
}
}

String version = '6.3.1'
String version = '6.3.2'

task updateVersion {
doLast {
Expand Down
14 changes: 1 addition & 13 deletions tests/jenkins/TestValidateArtifacts.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class TestValidateArtifacts extends BuildPipelineTest {
@Before
void setUp() {

this.registerLibTester(new ValidateArtifactsLibTester('1.0.0', 'foo'))
this.registerLibTester(new ValidateArtifactsLibTester('1.0.0', 'tar', 'x64', 'linux', 'opensearch'))

super.setUp()
}
Expand All @@ -28,16 +28,4 @@ class TestValidateArtifacts extends BuildPipelineTest {
void validateArtifacts() {
super.testPipeline('tests/jenkins/jobs/ValidateArtifacts_Jenkinsfile')
}

@Test
void checkScriptcall(){
runScript('tests/jenkins/jobs/ValidateArtifacts_Jenkinsfile')
def shcommand = helper.callStack.findAll { call ->
call.methodName == 'sh'
}.collect { call ->
callArgsToString(call)
}
assertThat(shcommand.size(), equalTo(1))
assertThat(shcommand, hasItem('/tmp/workspace/validation.sh --version 1.0.0 --project foo'))
}
}
5 changes: 4 additions & 1 deletion tests/jenkins/jobs/ValidateArtifacts_Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ pipeline {
script {
validateArtifacts(
version: '1.0.0',
project: 'foo'
distribution: 'tar',
arch: 'x64',
platform: 'linux',
projects: 'opensearch'
)
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/jenkins/jobs/ValidateArtifacts_Jenkinsfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
ValidateArtifacts_Jenkinsfile.echo(Executing on agent [label:none])
ValidateArtifacts_Jenkinsfile.stage(validate, groovy.lang.Closure)
ValidateArtifacts_Jenkinsfile.script(groovy.lang.Closure)
ValidateArtifacts_Jenkinsfile.validateArtifacts({version=1.0.0, project=foo})
ValidateArtifacts_Jenkinsfile.validateArtifacts({version=1.0.0, distribution=tar, arch=x64, platform=linux, projects=opensearch})
validateArtifacts.fileExists(/tmp/workspace/validation.sh)
validateArtifacts.sh(/tmp/workspace/validation.sh --version 1.0.0 --project foo)
validateArtifacts.sh(./validation.sh --version 1.0.0 --distribution tar --platform linux --arch x64 --projects opensearch)
17 changes: 12 additions & 5 deletions tests/jenkins/lib-testers/ValidateArtifactsLibTester.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,18 @@ import static org.hamcrest.MatcherAssert.assertThat
class ValidateArtifactsLibTester extends LibFunctionTester {

private String version
private String project
private String distribution
private String arch
private String platform
private String projects

public ValidateArtifactsLibTester(version, project) {
public ValidateArtifactsLibTester(version, distribution, arch, platform, projects) {
this.version = version
this.project = project
this.distribution = distribution
this.arch = arch
this.platform = platform
this.projects = projects

}

void configure(helper, binding) {
Expand All @@ -25,12 +32,12 @@ class ValidateArtifactsLibTester extends LibFunctionTester {

void parameterInvariantsAssertions(call) {
assertThat(call.args.version.first(), notNullValue())
assertThat(call.args.project.first(), notNullValue())
assertThat(call.args.projects.first(), notNullValue())
}

boolean expectedParametersMatcher(call) {
return call.args.version.first().toString().equals(this.version)
&& call.args.project.first().toString().equals(this.project)
&& call.args.projects.first().toString().equals(this.projects)
}

String libFunctionName() {
Expand Down
39 changes: 30 additions & 9 deletions vars/validateArtifacts.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,41 @@

/**
Wrapper that runs validation.sh script with provided args.
@param Map[<any>] <Required> - Any arguments that you want to be passed to validation.sh script. eg: version: 1.0.0 will be passed as --version 1.0.0
[
@param Map[version] <Required> - Version of the opensearch artifact that needs to be validated.
@param Map[file_path] <Required> - Url paths to Opensearch or OpenSearch DashBoards artifacts.
Note: These parameters are mutually exclusive. Provide either of 'version' or 'file_path' parameters, to proceed with the validation.
]
@param Map[distribution] <Optional> - Choose distribution type among [tar(default),rpm,yum,docker].
@param Map[architecture] <Optional> - Select the architecture type among [x64(default) and arm64].
@param Map[platform] <Optional> - The distribution platform.
@param Map[projects] <Optional> - Specify the project type OpenSearch or Both(OpenSearch and OpenSearch-DashBoards).
@param Map[docker_source] <Optional> - Specify the docker source from [DockerHub(default), ECR] to pull the docker image.
@param Map[os_build_number]<Optional> - Specify Opensearch build number from opensearchstaging if required.
@param Map[osd_build_number]<Optional> - Specify Opensearch-Dashboard build number from opensearchstaging if required.
@param Map[artifact_type] <Optional> - Select the artifact type among [staging and production].
@param Map[allow_http] <Optional> - Supports validation of artifacts in which security plugin is absent.architecture.
@param Map[docker_args] <Optional> - Select either of [using-staging-artifact-only', 'validate-digest-only] for docker validation.
*/
void call(Map args = [:]) {
if (!fileExists("$WORKSPACE/validation.sh")) {
println("Validation.sh script not found in the workspace: ${WORKSPACE}, exit 1")
System.exit(1)
}
String arguments = generateArguments(args)
sh "${WORKSPACE}/validation.sh ${arguments}"
}

String generateArguments(args) {
String arguments = ''
// generate of command line arguments
args.each { key, value -> arguments += " --${key } ${value }" }
return arguments
sh([
'./validation.sh',
args.version ? "--version ${args.version}" : "",
args.file_path ? "--file-path ${args.file_path}" : "",
args.distribution ? "--distribution ${args.distribution}" : "",
args.platform ? "--platform ${args.platform}" : "",
args.arch ? "--arch ${args.arch}" : "",
args.projects ? "--projects ${args.projects}" : "",
args.docker_source ? "--docker-source ${args.docker_source}" : "",
args.os_build_number ? "--os-build-number ${args.os_build_number}" : "",
args.osd_build_number ? "--osd-build-number ${args.osd_build_number}" : "",
args.artifact_type ? "--artifact-type ${args.artifact_type}" : "",
args.allow_http ? '--allow-http' : "",
args.docker_args ? "--${args.docker_args}" : "",
].join(' ').trim())
}

0 comments on commit 8fe1005

Please sign in to comment.