2022-06-05 04:53:36 +00:00
|
|
|
import org.gradle.tooling.events.*
|
|
|
|
import org.gradle.tooling.events.task.*
|
|
|
|
import org.gradle.util.GradleVersion
|
|
|
|
|
|
|
|
// Can't use settingsEvaluated since this script is applied inside a settingsEvaluated handler
|
|
|
|
// But projectsEvaluated is good enough, since the build service won't catch configuration failures anyway
|
|
|
|
projectsEvaluated {
|
|
|
|
def projectTracker = gradle.sharedServices.registerIfAbsent("gradle-build-action-buildResultsRecorder", BuildResultsRecorder, { spec ->
|
2022-06-05 14:18:25 +00:00
|
|
|
spec.getParameters().getRootProjectName().set(gradle.rootProject.name)
|
|
|
|
spec.getParameters().getRootProjectDir().set(gradle.rootProject.rootDir.absolutePath)
|
2022-06-05 06:18:20 +00:00
|
|
|
spec.getParameters().getRequestedTasks().set(gradle.startParameter.taskNames.join(" "))
|
2022-06-05 14:18:25 +00:00
|
|
|
spec.getParameters().getGradleHomeDir().set(gradle.gradleHomeDir.absolutePath)
|
2022-06-05 06:18:20 +00:00
|
|
|
spec.getParameters().getInvocationId().set(gradle.ext.invocationId)
|
2022-06-05 04:53:36 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
gradle.services.get(BuildEventsListenerRegistry).onTaskCompletion(projectTracker)
|
|
|
|
}
|
|
|
|
|
|
|
|
abstract class BuildResultsRecorder implements BuildService<BuildResultsRecorder.Params>, OperationCompletionListener, AutoCloseable {
|
|
|
|
private boolean buildFailed = false
|
|
|
|
interface Params extends BuildServiceParameters {
|
2022-06-05 14:18:25 +00:00
|
|
|
Property<String> getRootProjectName()
|
|
|
|
Property<String> getRootProjectDir()
|
2022-06-05 06:18:20 +00:00
|
|
|
Property<String> getRequestedTasks()
|
2022-06-05 14:18:25 +00:00
|
|
|
Property<String> getGradleHomeDir()
|
2022-06-05 06:18:20 +00:00
|
|
|
Property<String> getInvocationId()
|
2022-06-05 04:53:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void onFinish(FinishEvent finishEvent) {
|
|
|
|
if (finishEvent instanceof TaskFinishEvent && finishEvent.result instanceof TaskFailureResult) {
|
|
|
|
buildFailed = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void close() {
|
|
|
|
def buildResults = [
|
2022-06-05 14:18:25 +00:00
|
|
|
rootProjectName: getParameters().getRootProjectName().get(),
|
|
|
|
rootProjectDir: getParameters().getRootProjectDir().get(),
|
|
|
|
requestedTasks: getParameters().getRequestedTasks().get(),
|
|
|
|
gradleVersion: GradleVersion.current().version,
|
|
|
|
gradleHomeDir: getParameters().getGradleHomeDir().get(),
|
2022-06-05 04:53:36 +00:00
|
|
|
buildFailed: buildFailed,
|
2022-06-15 14:08:41 +00:00
|
|
|
buildScanUri: null,
|
|
|
|
buildScanFailed: false
|
2022-06-05 04:53:36 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
def buildResultsDir = new File(System.getenv("RUNNER_TEMP"), ".build-results")
|
|
|
|
buildResultsDir.mkdirs()
|
2022-06-05 06:18:20 +00:00
|
|
|
def buildResultsFile = new File(buildResultsDir, System.getenv("GITHUB_ACTION") + getParameters().getInvocationId().get() + ".json")
|
2022-06-05 04:53:36 +00:00
|
|
|
buildResultsFile << groovy.json.JsonOutput.toJson(buildResults)
|
|
|
|
}
|
2022-06-05 14:18:25 +00:00
|
|
|
}
|