mirror of
https://github.com/gradle/gradle-build-action.git
synced 2024-12-26 08:42:08 -05:00
Add more information to captured build results
- Root project dir: will allow us to replace project-root-capture init script - Gradle home dir: will allow us to stop all started daemons
This commit is contained in:
parent
44e1837ae3
commit
e234151ec9
4 changed files with 37 additions and 20 deletions
|
@ -4,9 +4,11 @@ import path from 'path'
|
||||||
import {logCachingReport, CacheListener} from './cache-reporting'
|
import {logCachingReport, CacheListener} from './cache-reporting'
|
||||||
|
|
||||||
interface BuildResult {
|
interface BuildResult {
|
||||||
get rootProject(): string
|
get rootProjectName(): string
|
||||||
|
get rootProjectDir(): string
|
||||||
get requestedTasks(): string
|
get requestedTasks(): string
|
||||||
get gradleVersion(): string
|
get gradleVersion(): string
|
||||||
|
get gradleHomeDir(): string
|
||||||
get buildFailed(): boolean
|
get buildFailed(): boolean
|
||||||
get buildScanUri(): string
|
get buildScanUri(): string
|
||||||
}
|
}
|
||||||
|
@ -50,7 +52,7 @@ function writeSummaryTable(results: BuildResult[]): void {
|
||||||
{data: 'Outcome', header: true}
|
{data: 'Outcome', header: true}
|
||||||
],
|
],
|
||||||
...results.map(result => [
|
...results.map(result => [
|
||||||
result.rootProject,
|
result.rootProjectName,
|
||||||
result.requestedTasks,
|
result.requestedTasks,
|
||||||
result.gradleVersion,
|
result.gradleVersion,
|
||||||
renderOutcome(result)
|
renderOutcome(result)
|
||||||
|
|
|
@ -6,8 +6,10 @@ import org.gradle.util.GradleVersion
|
||||||
// But projectsEvaluated is good enough, since the build service won't catch configuration failures anyway
|
// But projectsEvaluated is good enough, since the build service won't catch configuration failures anyway
|
||||||
projectsEvaluated {
|
projectsEvaluated {
|
||||||
def projectTracker = gradle.sharedServices.registerIfAbsent("gradle-build-action-buildResultsRecorder", BuildResultsRecorder, { spec ->
|
def projectTracker = gradle.sharedServices.registerIfAbsent("gradle-build-action-buildResultsRecorder", BuildResultsRecorder, { spec ->
|
||||||
spec.getParameters().getRootProject().set(gradle.rootProject.name)
|
spec.getParameters().getRootProjectName().set(gradle.rootProject.name)
|
||||||
|
spec.getParameters().getRootProjectDir().set(gradle.rootProject.rootDir.absolutePath)
|
||||||
spec.getParameters().getRequestedTasks().set(gradle.startParameter.taskNames.join(" "))
|
spec.getParameters().getRequestedTasks().set(gradle.startParameter.taskNames.join(" "))
|
||||||
|
spec.getParameters().getGradleHomeDir().set(gradle.gradleHomeDir.absolutePath)
|
||||||
spec.getParameters().getInvocationId().set(gradle.ext.invocationId)
|
spec.getParameters().getInvocationId().set(gradle.ext.invocationId)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -17,8 +19,10 @@ projectsEvaluated {
|
||||||
abstract class BuildResultsRecorder implements BuildService<BuildResultsRecorder.Params>, OperationCompletionListener, AutoCloseable {
|
abstract class BuildResultsRecorder implements BuildService<BuildResultsRecorder.Params>, OperationCompletionListener, AutoCloseable {
|
||||||
private boolean buildFailed = false
|
private boolean buildFailed = false
|
||||||
interface Params extends BuildServiceParameters {
|
interface Params extends BuildServiceParameters {
|
||||||
Property<String> getRootProject()
|
Property<String> getRootProjectName()
|
||||||
|
Property<String> getRootProjectDir()
|
||||||
Property<String> getRequestedTasks()
|
Property<String> getRequestedTasks()
|
||||||
|
Property<String> getGradleHomeDir()
|
||||||
Property<String> getInvocationId()
|
Property<String> getInvocationId()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,9 +35,11 @@ abstract class BuildResultsRecorder implements BuildService<BuildResultsRecorder
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
def buildResults = [
|
def buildResults = [
|
||||||
rootProject: getParameters().getRootProject().get(),
|
rootProjectName: getParameters().getRootProjectName().get(),
|
||||||
requestedTasks: getParameters().getRequestedTasks().get(),
|
rootProjectDir: getParameters().getRootProjectDir().get(),
|
||||||
gradleVersion: GradleVersion.current().version,
|
requestedTasks: getParameters().getRequestedTasks().get(),
|
||||||
|
gradleVersion: GradleVersion.current().version,
|
||||||
|
gradleHomeDir: getParameters().getGradleHomeDir().get(),
|
||||||
buildFailed: buildFailed,
|
buildFailed: buildFailed,
|
||||||
buildScanUri: null
|
buildScanUri: null
|
||||||
]
|
]
|
||||||
|
@ -43,4 +49,4 @@ abstract class BuildResultsRecorder implements BuildService<BuildResultsRecorder
|
||||||
def buildResultsFile = new File(buildResultsDir, System.getenv("GITHUB_ACTION") + getParameters().getInvocationId().get() + ".json")
|
def buildResultsFile = new File(buildResultsDir, System.getenv("GITHUB_ACTION") + getParameters().getInvocationId().get() + ".json")
|
||||||
buildResultsFile << groovy.json.JsonOutput.toJson(buildResults)
|
buildResultsFile << groovy.json.JsonOutput.toJson(buildResults)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,9 +18,9 @@ if (isTopLevelBuild) {
|
||||||
settingsEvaluated { settings ->
|
settingsEvaluated { settings ->
|
||||||
// The `buildScanPublished` hook is the only way to capture the build scan URI.
|
// The `buildScanPublished` hook is the only way to capture the build scan URI.
|
||||||
if (settings.pluginManager.hasPlugin("com.gradle.enterprise")) {
|
if (settings.pluginManager.hasPlugin("com.gradle.enterprise")) {
|
||||||
captureUsingBuildScanPublished(settings.extensions["gradleEnterprise"].buildScan, settings.rootProject.name, invocationId)
|
captureUsingBuildScanPublished(settings.extensions["gradleEnterprise"].buildScan, settings.rootProject, invocationId)
|
||||||
}
|
}
|
||||||
// We also need to add hooks in case the plugin is applied but no build scan is published
|
// We also need to add hooks in case the plugin is applied but no build scan is published
|
||||||
if (useBuildService) {
|
if (useBuildService) {
|
||||||
captureUsingBuildService(settings, invocationId)
|
captureUsingBuildService(settings, invocationId)
|
||||||
} else {
|
} else {
|
||||||
|
@ -30,18 +30,21 @@ if (isTopLevelBuild) {
|
||||||
} else if (atLeastGradle3) {
|
} else if (atLeastGradle3) {
|
||||||
projectsEvaluated { gradle ->
|
projectsEvaluated { gradle ->
|
||||||
if (gradle.rootProject.pluginManager.hasPlugin("com.gradle.build-scan")) {
|
if (gradle.rootProject.pluginManager.hasPlugin("com.gradle.build-scan")) {
|
||||||
captureUsingBuildScanPublished(gradle.rootProject.extensions["buildScan"], gradle.rootProject.name, invocationId)
|
captureUsingBuildScanPublished(gradle.rootProject.extensions["buildScan"], gradle.rootProject, invocationId)
|
||||||
}
|
}
|
||||||
// We need to capture in buildFinished in case the plugin is applied but no build scan is published
|
// We need to capture in buildFinished in case the plugin is applied but no build scan is published
|
||||||
captureUsingBuildFinished(gradle, invocationId)
|
captureUsingBuildFinished(gradle, invocationId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def captureUsingBuildScanPublished(buildScanExtension, rootProjectName, invocationId) {
|
def captureUsingBuildScanPublished(buildScanExtension, rootProject, invocationId) {
|
||||||
buildScanExtension.with {
|
buildScanExtension.with {
|
||||||
def requestedTasks = gradle.startParameter.taskNames.join(" ")
|
def requestedTasks = gradle.startParameter.taskNames.join(" ")
|
||||||
|
def rootProjectName = rootProject.name
|
||||||
|
def rootProjectDir = rootProject.projectDir.absolutePath
|
||||||
def gradleVersion = GradleVersion.current().version
|
def gradleVersion = GradleVersion.current().version
|
||||||
|
def gradleHomeDir = gradle.gradleHomeDir.absolutePath
|
||||||
def buildFailed = false
|
def buildFailed = false
|
||||||
|
|
||||||
buildFinished { result ->
|
buildFinished { result ->
|
||||||
|
@ -52,10 +55,12 @@ def captureUsingBuildScanPublished(buildScanExtension, rootProjectName, invocati
|
||||||
|
|
||||||
def buildScanUri = buildScan.buildScanUri.toASCIIString()
|
def buildScanUri = buildScan.buildScanUri.toASCIIString()
|
||||||
def buildResults = [
|
def buildResults = [
|
||||||
rootProject: rootProjectName,
|
rootProjectName: rootProjectName,
|
||||||
|
rootProjectDir: rootProjectDir,
|
||||||
requestedTasks: requestedTasks,
|
requestedTasks: requestedTasks,
|
||||||
gradleVersion: gradleVersion,
|
gradleVersion: gradleVersion,
|
||||||
buildFailed: buildFailed,
|
gradleHomeDir: gradleHomeDir,
|
||||||
|
buildFailed: buildFailed,
|
||||||
buildScanUri: buildScanUri
|
buildScanUri: buildScanUri
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -65,7 +70,7 @@ def captureUsingBuildScanPublished(buildScanExtension, rootProjectName, invocati
|
||||||
|
|
||||||
// Overwrite any contents written by buildFinished or build service, since this result is a superset.
|
// Overwrite any contents written by buildFinished or build service, since this result is a superset.
|
||||||
if (buildResultsFile.exists()) {
|
if (buildResultsFile.exists()) {
|
||||||
buildResultsFile.text = groovy.json.JsonOutput.toJson(buildResults)
|
buildResultsFile.text = groovy.json.JsonOutput.toJson(buildResults)
|
||||||
} else {
|
} else {
|
||||||
buildResultsFile << groovy.json.JsonOutput.toJson(buildResults)
|
buildResultsFile << groovy.json.JsonOutput.toJson(buildResults)
|
||||||
}
|
}
|
||||||
|
@ -78,9 +83,11 @@ def captureUsingBuildScanPublished(buildScanExtension, rootProjectName, invocati
|
||||||
def captureUsingBuildFinished(gradle, invocationId) {
|
def captureUsingBuildFinished(gradle, invocationId) {
|
||||||
gradle.buildFinished { result ->
|
gradle.buildFinished { result ->
|
||||||
def buildResults = [
|
def buildResults = [
|
||||||
rootProject: gradle.rootProject.name,
|
rootProjectName: gradle.rootProject.name,
|
||||||
|
rootProjectDir: gradle.rootProject.rootDir.absolutePath,
|
||||||
requestedTasks: gradle.startParameter.taskNames.join(" "),
|
requestedTasks: gradle.startParameter.taskNames.join(" "),
|
||||||
gradleVersion: GradleVersion.current().version,
|
gradleVersion: GradleVersion.current().version,
|
||||||
|
gradleHomeDir: gradle.gradleHomeDir.absolutePath,
|
||||||
buildFailed: result.failure != null,
|
buildFailed: result.failure != null,
|
||||||
buildScanUri: null
|
buildScanUri: null
|
||||||
]
|
]
|
||||||
|
|
|
@ -120,9 +120,11 @@ class TestBuildResultRecorder extends BaseInitScriptTest {
|
||||||
|
|
||||||
void assertResults(String task, TestGradleVersion testGradleVersion, boolean hasFailure, boolean hasBuildScan) {
|
void assertResults(String task, TestGradleVersion testGradleVersion, boolean hasFailure, boolean hasBuildScan) {
|
||||||
def results = new JsonSlurper().parse(buildResultFile)
|
def results = new JsonSlurper().parse(buildResultFile)
|
||||||
assert results['rootProject'] == ROOT_PROJECT_NAME
|
assert results['rootProjectName'] == ROOT_PROJECT_NAME
|
||||||
|
assert results['rootProjectDir'] == testProjectDir.canonicalPath
|
||||||
assert results['requestedTasks'] == task
|
assert results['requestedTasks'] == task
|
||||||
assert results['gradleVersion'] == testGradleVersion.gradleVersion.version
|
assert results['gradleVersion'] == testGradleVersion.gradleVersion.version
|
||||||
|
assert results['gradleHomeDir'] != null
|
||||||
assert results['buildFailed'] == hasFailure
|
assert results['buildFailed'] == hasFailure
|
||||||
assert results['buildScanUri'] == (hasBuildScan ? "${mockScansServer.address}s/${PUBLIC_BUILD_SCAN_ID}" : null)
|
assert results['buildScanUri'] == (hasBuildScan ? "${mockScansServer.address}s/${PUBLIC_BUILD_SCAN_ID}" : null)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue