Skip to content

Commit

Permalink
[Build] Make checkPart4 configuration cache compatible (elastic#117250)
Browse files Browse the repository at this point in the history
This makes checkPart4 tasks in general configuration cache compliant. 

We do not enable it by default in our pipelines yet. That will
eventually be done in separate PRs. To track any regressions we cover
the checkPart4 task in the weekly gradle cache validation build job
  • Loading branch information
breskeby authored Dec 15, 2024
1 parent ce2a7de commit ba52a22
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 23 deletions.
6 changes: 3 additions & 3 deletions .buildkite/scripts/gradle-configuration-cache-validation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
set -euo pipefail

# This is a workaround for https://github.com/gradle/gradle/issues/28159
.ci/scripts/run-gradle.sh --no-daemon precommit
.ci/scripts/run-gradle.sh --no-daemon $@

.ci/scripts/run-gradle.sh --configuration-cache precommit -Dorg.gradle.configuration-cache.inputs.unsafe.ignore.file-system-checks=build/*.tar.bz2
.ci/scripts/run-gradle.sh --configuration-cache -Dorg.gradle.configuration-cache.inputs.unsafe.ignore.file-system-checks=build/*.tar.bz2 $@

# Create a temporary file
tmpOutputFile=$(mktemp)
trap "rm $tmpOutputFile" EXIT

echo "2nd run"
.ci/scripts/run-gradle.sh --configuration-cache precommit -Dorg.gradle.configuration-cache.inputs.unsafe.ignore.file-system-checks=build/*.tar.bz2 | tee $tmpOutputFile
.ci/scripts/run-gradle.sh --configuration-cache -Dorg.gradle.configuration-cache.inputs.unsafe.ignore.file-system-checks=build/*.tar.bz2 $@ | tee $tmpOutputFile

# Check if the command was successful
if grep -q "Configuration cache entry reused." $tmpOutputFile; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.gradle.api.Action;
import org.gradle.api.GradleException;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.logging.LogLevel;
import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.Property;
Expand Down Expand Up @@ -103,10 +104,16 @@ private static TaskProvider<LoggedExec> createRunBwcGradleTask(
loggedExec.dependsOn("checkoutBwcBranch");
loggedExec.getWorkingDir().set(checkoutDir.get());

loggedExec.getNonTrackedEnvironment().put("JAVA_HOME", providerFactory.of(JavaHomeValueSource.class, spec -> {
spec.getParameters().getVersion().set(unreleasedVersionInfo.map(it -> it.version()));
spec.getParameters().getCheckoutDir().set(checkoutDir);
}).flatMap(s -> getJavaHome(objectFactory, toolChainService, Integer.parseInt(s))));
loggedExec.doFirst(new Action<Task>() {
@Override
public void execute(Task task) {
Provider<String> minimumCompilerVersionValueSource = providerFactory.of(JavaHomeValueSource.class, spec -> {
spec.getParameters().getVersion().set(unreleasedVersionInfo.map(it -> it.version()));
spec.getParameters().getCheckoutDir().set(checkoutDir);
}).flatMap(s -> getJavaHome(objectFactory, toolChainService, Integer.parseInt(s)));
loggedExec.getNonTrackedEnvironment().put("JAVA_HOME", minimumCompilerVersionValueSource.get());
}
});

if (isCi && OS.current() != OS.WINDOWS) {
// TODO: Disabled for now until we can figure out why files are getting corrupted
Expand Down Expand Up @@ -169,14 +176,6 @@ private static Provider<String> getJavaHome(ObjectFactory objectFactory, JavaToo
.map(launcher -> launcher.getMetadata().getInstallationPath().getAsFile().getAbsolutePath());
}

private static String readFromFile(File file) {
try {
return FileUtils.readFileToString(file).trim();
} catch (IOException ioException) {
throw new GradleException("Cannot read java properties file.", ioException);
}
}

public abstract static class JavaHomeValueSource implements ValueSource<String, JavaHomeValueSource.Params> {

private String minimumCompilerVersionPath(Version bwcVersion) {
Expand All @@ -185,6 +184,14 @@ private String minimumCompilerVersionPath(Version bwcVersion) {
: "buildSrc/" + MINIMUM_COMPILER_VERSION_PATH;
}

private static String readFromFile(File file) {
try {
return FileUtils.readFileToString(file).trim();
} catch (IOException ioException) {
throw new GradleException("Cannot read java properties file.", ioException);
}
}

@Override
public String obtain() {
return readFromFile(
Expand Down
11 changes: 6 additions & 5 deletions x-pack/plugin/sql/qa/jdbc/security/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ subprojects {


tasks.withType(RestIntegTestTask).configureEach {
def taskName = name
dependsOn copyTestClasses
classpath += configurations.testArtifacts
testClassesDirs = project.files(testArtifactsDir)
Expand All @@ -58,15 +59,15 @@ subprojects {
project.gradle.sharedServices,
TestClustersPlugin.REGISTRY_SERVICE_NAME
)
project.getProviders().of(TestClusterValueSource.class) {

def clusterInfo = project.getProviders().of(TestClusterValueSource.class) {
it.parameters.path.set(clusterPath)
it.parameters.clusterName.set("javaRestTest")
it.parameters.clusterName.set(taskName)
it.parameters.service = serviceProvider
}

nonInputProperties.systemProperty 'tests.audit.logfile',
"${-> testClusters.javaRestTest.singleNode().getAuditLog()}"
nonInputProperties.systemProperty 'tests.audit.logfile', clusterInfo.map { it.auditLogs.get(0) }
nonInputProperties.systemProperty 'tests.audit.yesterday.logfile',
"${-> testClusters.javaRestTest.singleNode().getAuditLog().getParentFile()}/javaRestTest_audit-${new Date().format('yyyy-MM-dd')}.json"
clusterInfo.map { it.auditLogs.get(0).getParentFile().toString() + "/javaRestTest_audit-${new Date().format('yyyy-MM-dd')}-1.json" }
}
}
25 changes: 22 additions & 3 deletions x-pack/plugin/sql/qa/server/security/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import org.elasticsearch.gradle.internal.test.RestIntegTestTask
import org.elasticsearch.gradle.testclusters.TestClusterValueSource
import org.elasticsearch.gradle.testclusters.TestClustersPlugin
import org.elasticsearch.gradle.testclusters.TestClustersRegistry
import org.elasticsearch.gradle.util.GradleUtils

apply plugin: 'elasticsearch.internal-test-artifact'

dependencies {
Expand All @@ -16,6 +22,8 @@ subprojects {
// Use tests from the root security qa project in subprojects
configurations.create('testArtifacts').transitive(false)

def clusterPath = getPath()

dependencies {
javaRestTestImplementation project(":x-pack:plugin:core")
javaRestTestImplementation(testArtifact(project(xpackModule('core'))))
Expand Down Expand Up @@ -50,12 +58,23 @@ subprojects {

tasks.named("javaRestTest").configure {
dependsOn copyTestClasses

Provider<TestClustersRegistry> serviceProvider = GradleUtils.getBuildService(
project.gradle.sharedServices,
TestClustersPlugin.REGISTRY_SERVICE_NAME
)

def clusterInfo = project.getProviders().of(TestClusterValueSource.class) {
it.parameters.path.set(clusterPath)
it.parameters.clusterName.set("javaRestTest")
it.parameters.service = serviceProvider
}

testClassesDirs += project.files(testArtifactsDir)
classpath += configurations.testArtifacts
nonInputProperties.systemProperty 'tests.audit.logfile',
"${-> testClusters.javaRestTest.singleNode().getAuditLog()}"
nonInputProperties.systemProperty 'tests.audit.logfile', clusterInfo.map { it.auditLogs.get(0) }
nonInputProperties.systemProperty 'tests.audit.yesterday.logfile',
"${-> testClusters.javaRestTest.singleNode().getAuditLog().getParentFile()}/javaRestTest_audit-${new Date().format('yyyy-MM-dd')}-1.json.gz"
clusterInfo.map { it.auditLogs.get(0).getParentFile().toString() + "/javaRestTest_audit-${new Date().format('yyyy-MM-dd')}-1.json.gz"}
}

}

0 comments on commit ba52a22

Please sign in to comment.