mirror of
https://github.com/gradle/gradle-build-action.git
synced 2024-11-22 17:12:51 +00:00
Merge pull request #695 from gradle/dd/issue-626
Handle GE plugin applied in settingsEvaluated
This commit is contained in:
commit
12681a2972
3 changed files with 45 additions and 10 deletions
|
@ -16,26 +16,29 @@ if (isTopLevelBuild) {
|
||||||
if (atLeastGradle6) {
|
if (atLeastGradle6) {
|
||||||
def useBuildService = version >= GradleVersion.version("6.6")
|
def useBuildService = version >= GradleVersion.version("6.6")
|
||||||
settingsEvaluated { settings ->
|
settingsEvaluated { settings ->
|
||||||
// The `buildScanPublished` hook is the only way to capture the build scan URI.
|
// By default, use standard mechanisms to capture build results
|
||||||
if (settings.pluginManager.hasPlugin("com.gradle.enterprise")) {
|
|
||||||
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
|
|
||||||
// The `buildScanPublished` results will NOT be overwritten by these calls
|
|
||||||
if (useBuildService) {
|
if (useBuildService) {
|
||||||
captureUsingBuildService(settings, invocationId)
|
captureUsingBuildService(settings, invocationId)
|
||||||
} else {
|
} else {
|
||||||
captureUsingBuildFinished(gradle, invocationId)
|
captureUsingBuildFinished(gradle, invocationId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The `buildScanPublished` hook allows the capture of the build scan URI.
|
||||||
|
// Results captured this way will overwrite any results from the other mechanism.
|
||||||
|
settings.pluginManager.withPlugin("com.gradle.enterprise") {
|
||||||
|
captureUsingBuildScanPublished(settings.extensions["gradleEnterprise"].buildScan, settings.rootProject, invocationId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (atLeastGradle3) {
|
} else if (atLeastGradle3) {
|
||||||
projectsEvaluated { gradle ->
|
projectsEvaluated { gradle ->
|
||||||
if (gradle.rootProject.pluginManager.hasPlugin("com.gradle.build-scan")) {
|
// By default, use 'buildFinished' to capture build results
|
||||||
|
captureUsingBuildFinished(gradle, invocationId)
|
||||||
|
|
||||||
|
// The `buildScanPublished` hook allows the capture of the build scan URI.
|
||||||
|
// Results captured this way will overwrite any results from 'buildFinished'.
|
||||||
|
gradle.rootProject.pluginManager.withPlugin("com.gradle.build-scan") {
|
||||||
captureUsingBuildScanPublished(gradle.rootProject.extensions["buildScan"], gradle.rootProject, invocationId)
|
captureUsingBuildScanPublished(gradle.rootProject.extensions["buildScan"], gradle.rootProject, invocationId)
|
||||||
}
|
}
|
||||||
// Always attempt to capture in buildFinished in case the plugin is applied but no build scan is published
|
|
||||||
// The `buildScanPublished` results will NOT be overwritten by this call
|
|
||||||
captureUsingBuildFinished(gradle, invocationId)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,6 +73,7 @@ def captureUsingBuildScanPublished(buildScanExtension, rootProject, invocationId
|
||||||
|
|
||||||
def captureUsingBuildFinished(gradle, invocationId) {
|
def captureUsingBuildFinished(gradle, invocationId) {
|
||||||
gradle.buildFinished { result ->
|
gradle.buildFinished { result ->
|
||||||
|
println "Got buildFinished: ${result}"
|
||||||
def buildResults = new BuildResults(invocationId, gradle, gradle.rootProject)
|
def buildResults = new BuildResults(invocationId, gradle, gradle.rootProject)
|
||||||
buildResults.setBuildResult(result)
|
buildResults.setBuildResult(result)
|
||||||
buildResults.writeToResultsFile(false)
|
buildResults.writeToResultsFile(false)
|
||||||
|
|
|
@ -38,6 +38,9 @@ class BaseInitScriptTest extends Specification {
|
||||||
static final List<TestGradleVersion> CONFIGURATION_CACHE_VERSIONS =
|
static final List<TestGradleVersion> CONFIGURATION_CACHE_VERSIONS =
|
||||||
[GRADLE_7_X, GRADLE_8_X]
|
[GRADLE_7_X, GRADLE_8_X]
|
||||||
|
|
||||||
|
static final List<TestGradleVersion> SETTINGS_PLUGIN_VERSIONS =
|
||||||
|
[GRADLE_6_X, GRADLE_7_X, GRADLE_8_X]
|
||||||
|
|
||||||
static final String PUBLIC_BUILD_SCAN_ID = 'i2wepy2gr7ovw'
|
static final String PUBLIC_BUILD_SCAN_ID = 'i2wepy2gr7ovw'
|
||||||
static final String DEFAULT_SCAN_UPLOAD_TOKEN = 'scan-upload-token'
|
static final String DEFAULT_SCAN_UPLOAD_TOKEN = 'scan-upload-token'
|
||||||
static final String ROOT_PROJECT_NAME = 'test-init-script'
|
static final String ROOT_PROJECT_NAME = 'test-init-script'
|
||||||
|
|
|
@ -148,6 +148,34 @@ class TestBuildResultRecorder extends BaseInitScriptTest {
|
||||||
testGradleVersion << ALL_VERSIONS
|
testGradleVersion << ALL_VERSIONS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def "produces build results file with build scan when GE plugin is applied in settingsEvaluated"() {
|
||||||
|
assumeTrue testGradleVersion.compatibleWithCurrentJvm
|
||||||
|
|
||||||
|
when:
|
||||||
|
settingsFile.text = """
|
||||||
|
plugins {
|
||||||
|
id 'com.gradle.enterprise' version '3.13' apply(false)
|
||||||
|
}
|
||||||
|
gradle.settingsEvaluated {
|
||||||
|
apply plugin: 'com.gradle.enterprise'
|
||||||
|
gradleEnterprise {
|
||||||
|
server = '$mockScansServer.address'
|
||||||
|
buildScan {
|
||||||
|
publishAlways()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""" + settingsFile.text
|
||||||
|
|
||||||
|
run(['help'], initScript, testGradleVersion.gradleVersion)
|
||||||
|
|
||||||
|
then:
|
||||||
|
assertResults('help', testGradleVersion, false, true)
|
||||||
|
|
||||||
|
where:
|
||||||
|
testGradleVersion << SETTINGS_PLUGIN_VERSIONS
|
||||||
|
}
|
||||||
|
|
||||||
void assertResults(String task, TestGradleVersion testGradleVersion, boolean hasFailure, boolean hasBuildScan, boolean scanUploadFailed = false) {
|
void assertResults(String task, TestGradleVersion testGradleVersion, boolean hasFailure, boolean hasBuildScan, boolean scanUploadFailed = false) {
|
||||||
def results = new JsonSlurper().parse(buildResultFile)
|
def results = new JsonSlurper().parse(buildResultFile)
|
||||||
assert results['rootProjectName'] == ROOT_PROJECT_NAME
|
assert results['rootProjectName'] == ROOT_PROJECT_NAME
|
||||||
|
|
Loading…
Reference in a new issue