Skip to content

Commit

Permalink
[Backport 6.x] Add bwc.checkout.align parameter support in gradle-che…
Browse files Browse the repository at this point in the history
…ck (#452)

Signed-off-by: Rishabh Singh <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 168a549 commit 0af56a7
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ jacocoTestReport {
}
}

String version = '6.5.2'
String version = '6.6.0'

task updateVersion {
doLast {
Expand Down
50 changes: 50 additions & 0 deletions tests/jenkins/TestRunGradleCheck.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import jenkins.tests.BuildPipelineTest
import org.junit.Before
import org.junit.Test

import static com.lesfurets.jenkins.unit.MethodCall.callArgsToString
import static org.hamcrest.CoreMatchers.containsString
import static org.hamcrest.CoreMatchers.hasItem
import static org.hamcrest.MatcherAssert.assertThat


class TestRunGradleCheck extends BuildPipelineTest {

Expand All @@ -19,6 +24,7 @@ class TestRunGradleCheck extends BuildPipelineTest {
this.registerLibTester(new RunGradleCheckLibTester(
'https://github.com/opensearch-project/OpenSearch',
'main',
'false'
)
)
super.setUp()
Expand All @@ -27,5 +33,49 @@ class TestRunGradleCheck extends BuildPipelineTest {
@Test
void testRunGradleCheck() {
super.testPipeline("tests/jenkins/jobs/RunGradleCheck_Jenkinsfile")

}

@Test
void testNoAlignParamInGradleCommand() {
runScript("tests/jenkins/jobs/RunGradleCheck_Jenkinsfile")

def gradleCommands = getCommandExecutions('sh', 'gradle').findAll {
shCommand -> shCommand.contains('gradle')
}
assertThat(gradleCommands, hasItem(containsString("./gradlew clean && ./gradlew check -Dtests.coverage=true --no-daemon --no-scan || GRADLE_CHECK_STATUS=1")
))
}

@Test
void testRunGradleCheckBwcAlign() {
super.testPipeline("tests/jenkins/jobs/RunGradleCheckBwcAlign_Jenkinsfile")
}

@Test
void testAlignParamInGradleCommand() {
runScript("tests/jenkins/jobs/RunGradleCheckBwcAlign_Jenkinsfile")

def gradleCommands = getCommandExecutions('sh', 'gradle').findAll {
shCommand -> shCommand.contains('gradle')
}
assertThat(gradleCommands, hasItem(containsString("./gradlew clean && ./gradlew check -Dtests.coverage=true -Dbwc.checkout.align=true --no-daemon --no-scan || GRADLE_CHECK_STATUS=1")
))
}

def getCommandExecutions(methodName, command) {
def shCommands = helper.callStack.findAll {
call ->
call.methodName == methodName
}.
collect {
call ->
callArgsToString(call)
}.findAll {
shCommand ->
shCommand.contains(command)
}

return shCommands
}
}
25 changes: 25 additions & 0 deletions tests/jenkins/jobs/RunGradleCheckBwcAlign_Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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.
*/

pipeline {
agent none
stages {
stage('gradle-check') {
steps {
script {
runGradleCheck(
gitRepoUrl: "https://github.com/opensearch-project/OpenSearch",
gitReference: "main",
bwcCheckoutAlign: "true"
)
}
}
}
}
}
67 changes: 67 additions & 0 deletions tests/jenkins/jobs/RunGradleCheckBwcAlign_Jenkinsfile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
RunGradleCheckBwcAlign_Jenkinsfile.run()
RunGradleCheckBwcAlign_Jenkinsfile.pipeline(groovy.lang.Closure)
RunGradleCheckBwcAlign_Jenkinsfile.echo(Executing on agent [label:none])
RunGradleCheckBwcAlign_Jenkinsfile.stage(gradle-check, groovy.lang.Closure)
RunGradleCheckBwcAlign_Jenkinsfile.script(groovy.lang.Closure)
RunGradleCheckBwcAlign_Jenkinsfile.runGradleCheck({gitRepoUrl=https://github.com/opensearch-project/OpenSearch, gitReference=main, bwcCheckoutAlign=true})
runGradleCheck.legacySCM(groovy.lang.Closure)
runGradleCheck.library({[email protected], retriever=null})
runGradleCheck.usernamePassword({credentialsId=jenkins-gradle-check-s3-aws-credentials, usernameVariable=amazon_s3_access_key, passwordVariable=amazon_s3_secret_key})
runGradleCheck.usernamePassword({credentialsId=jenkins-gradle-check-s3-aws-resources, usernameVariable=amazon_s3_base_path, passwordVariable=amazon_s3_bucket})
runGradleCheck.withCredentials([[amazon_s3_access_key, amazon_s3_secret_key], [amazon_s3_base_path, amazon_s3_bucket]], groovy.lang.Closure)
runGradleCheck.sh(
#!/bin/bash

set -e
set +x

echo "Git clone: https://github.com/opensearch-project/OpenSearch with ref: main"
rm -rf search
git clone https://github.com/opensearch-project/OpenSearch search
cd search/
git checkout -f main
git rev-parse HEAD

echo "Get Major Version"
OS_VERSION=`cat buildSrc/version.properties | grep opensearch | cut -d= -f2 | grep -oE '[0-9.]+'`
JDK_MAJOR_VERSION=`cat buildSrc/version.properties | grep "bundled_jdk" | cut -d= -f2 | grep -oE '[0-9]+' | head -n 1`
OS_MAJOR_VERSION=`echo $OS_VERSION | grep -oE '[0-9]+' | head -n 1`
echo "Version: $OS_VERSION, Major Version: $OS_MAJOR_VERSION"

echo "Using JAVA $JDK_MAJOR_VERSION"
eval export JAVA_HOME='$JAVA'$JDK_MAJOR_VERSION'_HOME'

env | grep JAVA | grep HOME

echo "Gradle clean cache and stop existing gradledaemon"
./gradlew --stop
rm -rf ~/.gradle

if command -v docker > /dev/null; then
echo "Check existing dockercontainer"
docker ps -a
docker stop `docker ps -qa` > /dev/null 2>&1 || echo
docker rm --force `docker ps -qa` > /dev/null 2>&1 || echo
echo "Stop existing dockercontainer"
docker ps -a

echo "Check docker-compose version"
docker-compose version
fi

echo "Check existing processes"
ps -ef | grep [o]pensearch | wc -l
echo "Cleanup existing processes"
kill -9 `ps -ef | grep [o]pensearch | awk '{print $2}'` > /dev/null 2>&1 || echo
ps -ef | grep [o]pensearch | wc -l

echo "Start gradlecheck"
GRADLE_CHECK_STATUS=0
./gradlew clean && ./gradlew check -Dtests.coverage=true -Dbwc.checkout.align=true --no-daemon --no-scan || GRADLE_CHECK_STATUS=1

if [ "$GRADLE_CHECK_STATUS" != 0 ]; then
echo Gradle Check Failed!
exit 1
fi

)
3 changes: 2 additions & 1 deletion tests/jenkins/jobs/RunGradleCheck_Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ pipeline {
script {
runGradleCheck(
gitRepoUrl: "https://github.com/opensearch-project/OpenSearch",
gitReference: "main"
gitReference: "main",
bwcCheckoutAlign: "false"
)
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/jenkins/jobs/RunGradleCheck_Jenkinsfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
RunGradleCheck_Jenkinsfile.echo(Executing on agent [label:none])
RunGradleCheck_Jenkinsfile.stage(gradle-check, groovy.lang.Closure)
RunGradleCheck_Jenkinsfile.script(groovy.lang.Closure)
RunGradleCheck_Jenkinsfile.runGradleCheck({gitRepoUrl=https://github.com/opensearch-project/OpenSearch, gitReference=main})
RunGradleCheck_Jenkinsfile.runGradleCheck({gitRepoUrl=https://github.com/opensearch-project/OpenSearch, gitReference=main, bwcCheckoutAlign=false})
runGradleCheck.legacySCM(groovy.lang.Closure)
runGradleCheck.library({[email protected], retriever=null})
runGradleCheck.usernamePassword({credentialsId=jenkins-gradle-check-s3-aws-credentials, usernameVariable=amazon_s3_access_key, passwordVariable=amazon_s3_secret_key})
Expand Down Expand Up @@ -57,7 +57,7 @@

echo "Start gradlecheck"
GRADLE_CHECK_STATUS=0
./gradlew clean && ./gradlew check -Dtests.coverage=true --no-daemon --no-scan || GRADLE_CHECK_STATUS=1
./gradlew clean && ./gradlew check -Dtests.coverage=true --no-daemon --no-scan || GRADLE_CHECK_STATUS=1

if [ "$GRADLE_CHECK_STATUS" != 0 ]; then
echo Gradle Check Failed!
Expand Down
5 changes: 4 additions & 1 deletion tests/jenkins/lib-testers/RunGradleCheckLibTester.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ class RunGradleCheckLibTester extends LibFunctionTester {

private String gitRepoUrl
private String gitReference
private String bwcCheckoutAlign

public RunGradleCheckLibTester(gitRepoUrl, gitReference){
public RunGradleCheckLibTester(gitRepoUrl, gitReference, bwcCheckoutAlign){
this.gitRepoUrl = gitRepoUrl
this.gitReference = gitReference
this.bwcCheckoutAlign = bwcCheckoutAlign
}

void configure(helper, binding) {
Expand All @@ -27,6 +29,7 @@ class RunGradleCheckLibTester extends LibFunctionTester {
void parameterInvariantsAssertions(call) {
assertThat(call.args.gitRepoUrl.first(), notNullValue())
assertThat(call.args.gitReference.first(), notNullValue())
assertThat(call.args.bwcCheckoutAlign.first(), notNullValue())
}

boolean expectedParametersMatcher(call) {
Expand Down
9 changes: 8 additions & 1 deletion vars/runGradleCheck.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,16 @@ void call(Map args = [:]) {
def lib = library(identifier: '[email protected]', retriever: legacySCM(scm))
def git_repo_url = args.gitRepoUrl ?: 'null'
def git_reference = args.gitReference ?: 'null'
def bwc_checkout_align = args.bwcCheckoutAlign ?: 'false'
def bwc_checkout_align_param = ''

println("Git Repo: ${git_repo_url}")
println("Git Reference: ${git_reference}")
println("Bwc Checkout Align: ${bwc_checkout_align}")

if (Boolean.parseBoolean(bwc_checkout_align)) {
bwc_checkout_align_param = '-Dbwc.checkout.align=true'
}

if (git_repo_url.equals('null') || git_reference.equals('null')) {
println("No git repo url or git reference to checkout the commit, exit 1")
Expand Down Expand Up @@ -71,7 +78,7 @@ void call(Map args = [:]) {
echo "Start gradlecheck"
GRADLE_CHECK_STATUS=0
./gradlew clean && ./gradlew check -Dtests.coverage=true --no-daemon --no-scan || GRADLE_CHECK_STATUS=1
./gradlew clean && ./gradlew check -Dtests.coverage=true ${bwc_checkout_align_param} --no-daemon --no-scan || GRADLE_CHECK_STATUS=1
if [ "\$GRADLE_CHECK_STATUS" != 0 ]; then
echo Gradle Check Failed!
Expand Down

0 comments on commit 0af56a7

Please sign in to comment.