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

Comp check #7899

Closed
wants to merge 5 commits into from
Closed
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
66 changes: 66 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import org.gradle.plugins.ide.eclipse.model.EclipseJdt
import org.gradle.plugins.ide.eclipse.model.SourceFolder
import org.gradle.api.Project;
import org.gradle.process.ExecResult;
import groovy.json.JsonSlurper

import static org.opensearch.gradle.util.GradleUtils.maybeConfigure

Expand All @@ -57,6 +58,7 @@ plugins {
id "org.gradle.test-retry" version "1.5.3" apply false
id "test-report-aggregation"
id 'jacoco-report-aggregation'
id "com.dorongold.task-tree" version "2.1.1"
}

apply from: 'gradle/build-complete.gradle'
Expand Down Expand Up @@ -643,3 +645,67 @@ tasks.withType(TestTaskReports).configureEach {
tasks.named(JavaBasePlugin.CHECK_TASK_NAME) {
dependsOn tasks.named('testAggregateTestReport', TestReport)
}

task checkCompatibility {
description('Checks code compatibility with remote component')
ext.getPluginRepoURL = { jsonUrl->
def url = new URL(jsonUrl)
def json = new JsonSlurper().parseText(url.text)
def labels = json.projects.values()
return labels
}
ext.getGradleExec = {
if(System.properties['os.name'].toLowerCase().contains('windows')){
return 'gradlew.bat'
}
return './gradlew'
}
ArrayList repositoryUrls = new ArrayList<String>()
if (project.hasProperty('repositoryUrls')) {
repositoryUrls = project.property('repositoryUrls').split(',')
} else {
logger.info('repositoryUrls property was not provided, using components list from https://raw.githubusercontent.com/opensearch-project/opensearch-plugins/main/plugins/.meta ')
repositoryUrls = getPluginRepoURL('https://raw.githubusercontent.com/opensearch-project/opensearch-plugins/main/plugins/.meta')
};
String ref = project.hasProperty('ref') ? project.property('ref'): 'main'
def failedComponents = []
doLast {
println("Checking compability for: $repositoryUrls for $ref")
repositoryUrls.parallelStream().forEach { repositoryUrl ->
def tempDir = File.createTempDir()
exec {
logger.info('Cloning repo:', repositoryUrl)
commandLine 'git', 'clone', repositoryUrl, tempDir
}
try {
exec {
workingDir = tempDir
def stdout = new ByteArrayOutputStream()
def gradleScript = getGradleExec()
logger.info('Checking out:', ref)
commandLine 'git', 'checkout', ref
commandLine gradleScript, 'assemble'
standardOutput stdout
}
} catch (ex) {
failedComponents.add(repositoryUrl)
logger.info("Gradle assemble failed for component: ", repositoryUrl, "Error logs:", ex)
} finally {
tempDir.deleteDir()
}
}
if (!failedComponents.isEmpty()) {
println("Components incompatible with this change: $failedComponents")
} else {
println('All components are compatible with this change')
}
}
}

allprojects {project ->
project.afterEvaluate {
if (project.tasks.findByName('publishToMavenLocal')){
checkCompatibility.dependsOn(project.tasks.publishToMavenLocal)
}
}
}