mirror of
https://github.com/gradle/actions.git
synced 2025-04-19 17:29:20 +08:00
Update develocity-injection init script to v1.3
Updates the develocity-injection init script to the latest reference script content from https://github.com/gradle/develocity-ci-injection.
This commit is contained in:
parent
dc4f141bca
commit
90b47aa345
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Initscript for injection of Develocity into Gradle builds.
|
* Initscript for injection of Develocity into Gradle builds.
|
||||||
* Version: 1.2
|
* Version: 1.3
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.gradle.util.GradleVersion
|
import org.gradle.util.GradleVersion
|
||||||
@ -35,19 +35,20 @@ initscript {
|
|||||||
def pluginRepositoryPassword = getInputParam(gradle, 'gradle.plugin-repository.password')
|
def pluginRepositoryPassword = getInputParam(gradle, 'gradle.plugin-repository.password')
|
||||||
def develocityPluginVersion = getInputParam(gradle, 'develocity.plugin.version')
|
def develocityPluginVersion = getInputParam(gradle, 'develocity.plugin.version')
|
||||||
def ccudPluginVersion = getInputParam(gradle, 'develocity.ccud-plugin.version')
|
def ccudPluginVersion = getInputParam(gradle, 'develocity.ccud-plugin.version')
|
||||||
|
def logLevel = Boolean.parseBoolean(getInputParam(gradle, 'develocity.injection.debug')) ? LogLevel.LIFECYCLE : LogLevel.INFO
|
||||||
|
|
||||||
def atLeastGradle5 = GradleVersion.current() >= GradleVersion.version('5.0')
|
def atLeastGradle5 = GradleVersion.current() >= GradleVersion.version('5.0')
|
||||||
def atLeastGradle4 = GradleVersion.current() >= GradleVersion.version('4.0')
|
def atLeastGradle4 = GradleVersion.current() >= GradleVersion.version('4.0')
|
||||||
|
|
||||||
if (develocityPluginVersion || ccudPluginVersion && atLeastGradle4) {
|
if (develocityPluginVersion || ccudPluginVersion && atLeastGradle4) {
|
||||||
pluginRepositoryUrl = pluginRepositoryUrl ?: 'https://plugins.gradle.org/m2'
|
pluginRepositoryUrl = pluginRepositoryUrl ?: 'https://plugins.gradle.org/m2'
|
||||||
logger.lifecycle("Develocity plugins resolution: $pluginRepositoryUrl")
|
logger.log(logLevel, "Develocity plugins resolution: $pluginRepositoryUrl")
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
maven {
|
maven {
|
||||||
url = pluginRepositoryUrl
|
url = pluginRepositoryUrl
|
||||||
if (pluginRepositoryUsername && pluginRepositoryPassword) {
|
if (pluginRepositoryUsername && pluginRepositoryPassword) {
|
||||||
logger.lifecycle("Using credentials for plugin repository")
|
logger.log(logLevel, "Using credentials for plugin repository")
|
||||||
credentials {
|
credentials {
|
||||||
username = pluginRepositoryUsername
|
username = pluginRepositoryUsername
|
||||||
password = pluginRepositoryPassword
|
password = pluginRepositoryPassword
|
||||||
@ -92,13 +93,13 @@ if (!isTopLevelBuild) {
|
|||||||
|
|
||||||
def requestedInitScriptName = getInputParam(gradle, 'develocity.injection.init-script-name')
|
def requestedInitScriptName = getInputParam(gradle, 'develocity.injection.init-script-name')
|
||||||
def initScriptName = buildscript.sourceFile.name
|
def initScriptName = buildscript.sourceFile.name
|
||||||
if (requestedInitScriptName != initScriptName) {
|
|
||||||
logger.quiet("Ignoring init script '${initScriptName}' as requested name '${requestedInitScriptName}' does not match")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
def develocityInjectionEnabled = Boolean.parseBoolean(getInputParam(gradle, "develocity.injection-enabled"))
|
def develocityInjectionEnabled = Boolean.parseBoolean(getInputParam(gradle, "develocity.injection-enabled"))
|
||||||
if (develocityInjectionEnabled) {
|
if (develocityInjectionEnabled) {
|
||||||
|
if (requestedInitScriptName != initScriptName) {
|
||||||
|
logger.log(LogLevel.WARN, "Develocity injection not enabled because requested init script name was '${requestedInitScriptName}', but '${initScriptName}' was expected")
|
||||||
|
return
|
||||||
|
}
|
||||||
enableDevelocityInjection()
|
enableDevelocityInjection()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,6 +107,10 @@ if (develocityInjectionEnabled) {
|
|||||||
def buildScanCollector = new BuildScanCollector()
|
def buildScanCollector = new BuildScanCollector()
|
||||||
def buildScanCaptureEnabled = buildScanCollector.metaClass.respondsTo(buildScanCollector, 'captureBuildScanLink', String)
|
def buildScanCaptureEnabled = buildScanCollector.metaClass.respondsTo(buildScanCollector, 'captureBuildScanLink', String)
|
||||||
if (buildScanCaptureEnabled) {
|
if (buildScanCaptureEnabled) {
|
||||||
|
if (requestedInitScriptName != initScriptName) {
|
||||||
|
logger.log(LogLevel.WARN, "Build Scan capture not enabled because requested init script name was '${requestedInitScriptName}', but '${initScriptName}' was expected")
|
||||||
|
return
|
||||||
|
}
|
||||||
enableBuildScanLinkCapture(buildScanCollector)
|
enableBuildScanLinkCapture(buildScanCollector)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,6 +137,7 @@ void enableDevelocityInjection() {
|
|||||||
def buildScanTermsOfUseUrl = getInputParam(gradle, 'develocity.terms-of-use.url')
|
def buildScanTermsOfUseUrl = getInputParam(gradle, 'develocity.terms-of-use.url')
|
||||||
def buildScanTermsOfUseAgree = getInputParam(gradle, 'develocity.terms-of-use.agree')
|
def buildScanTermsOfUseAgree = getInputParam(gradle, 'develocity.terms-of-use.agree')
|
||||||
def ciAutoInjectionCustomValueValue = getInputParam(gradle, 'develocity.auto-injection.custom-value')
|
def ciAutoInjectionCustomValueValue = getInputParam(gradle, 'develocity.auto-injection.custom-value')
|
||||||
|
def logLevel = Boolean.parseBoolean(getInputParam(gradle, 'develocity.injection.debug')) ? LogLevel.LIFECYCLE : LogLevel.INFO
|
||||||
|
|
||||||
def atLeastGradle5 = GradleVersion.current() >= GradleVersion.version('5.0')
|
def atLeastGradle5 = GradleVersion.current() >= GradleVersion.version('5.0')
|
||||||
def atLeastGradle4 = GradleVersion.current() >= GradleVersion.version('4.0')
|
def atLeastGradle4 = GradleVersion.current() >= GradleVersion.version('4.0')
|
||||||
@ -145,22 +151,22 @@ void enableDevelocityInjection() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
def printEnforcingDevelocityUrl = {
|
def printEnforcingDevelocityUrl = {
|
||||||
logger.lifecycle("Enforcing Develocity: $develocityUrl, allowUntrustedServer: $develocityAllowUntrustedServer")
|
logger.log(logLevel, "Enforcing Develocity: $develocityUrl, allowUntrustedServer: $develocityAllowUntrustedServer")
|
||||||
}
|
}
|
||||||
|
|
||||||
def printAcceptingGradleTermsOfUse = {
|
def printAcceptingGradleTermsOfUse = {
|
||||||
logger.lifecycle("Accepting Gradle Terms of Use: $buildScanTermsOfUseUrl")
|
logger.log(logLevel, "Accepting Gradle Terms of Use: $buildScanTermsOfUseUrl")
|
||||||
}
|
}
|
||||||
|
|
||||||
// finish early if DV plugin version is unsupported (v3.6.4 is the minimum version tested and supports back to DV 2021.1)
|
// finish early if DV plugin version is unsupported (v3.6.4 is the minimum version tested and supports back to DV 2021.1)
|
||||||
if (develocityPluginVersion && isNotAtLeast(develocityPluginVersion, '3.6.4')) {
|
if (develocityPluginVersion && isNotAtLeast(develocityPluginVersion, '3.6.4')) {
|
||||||
logger.warn("Develocity Gradle plugin must be at least 3.6.4. Configured version is $develocityPluginVersion.")
|
logger.log(LogLevel.WARN, "Develocity Gradle plugin must be at least 3.6.4. Configured version is $develocityPluginVersion.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// finish early if configuration parameters passed in via system properties are not valid/supported
|
// finish early if configuration parameters passed in via system properties are not valid/supported
|
||||||
if (ccudPluginVersion && isNotAtLeast(ccudPluginVersion, '1.7')) {
|
if (ccudPluginVersion && isNotAtLeast(ccudPluginVersion, '1.7')) {
|
||||||
logger.warn("Common Custom User Data Gradle plugin must be at least 1.7. Configured version is $ccudPluginVersion.")
|
logger.log(LogLevel.WARN, "Common Custom User Data Gradle plugin must be at least 1.7. Configured version is $ccudPluginVersion.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,7 +193,7 @@ void enableDevelocityInjection() {
|
|||||||
{ rootExtension }
|
{ rootExtension }
|
||||||
)
|
)
|
||||||
if (develocityUrl) {
|
if (develocityUrl) {
|
||||||
logger.lifecycle("Connection to Develocity: $develocityUrl, allowUntrustedServer: $develocityAllowUntrustedServer, captureFileFingerprints: $develocityCaptureFileFingerprints")
|
logger.log(logLevel, "Connection to Develocity: $develocityUrl, allowUntrustedServer: $develocityAllowUntrustedServer, captureFileFingerprints: $develocityCaptureFileFingerprints")
|
||||||
rootExtension.server = develocityUrl
|
rootExtension.server = develocityUrl
|
||||||
rootExtension.allowUntrustedServer = develocityAllowUntrustedServer
|
rootExtension.allowUntrustedServer = develocityAllowUntrustedServer
|
||||||
}
|
}
|
||||||
@ -197,7 +203,7 @@ void enableDevelocityInjection() {
|
|||||||
}
|
}
|
||||||
buildScanExtension.value CI_AUTO_INJECTION_CUSTOM_VALUE_NAME, ciAutoInjectionCustomValueValue
|
buildScanExtension.value CI_AUTO_INJECTION_CUSTOM_VALUE_NAME, ciAutoInjectionCustomValueValue
|
||||||
if (isAtLeast(develocityPluginVersion, '2.1') && atLeastGradle5) {
|
if (isAtLeast(develocityPluginVersion, '2.1') && atLeastGradle5) {
|
||||||
logger.lifecycle("Setting captureFileFingerprints: $develocityCaptureFileFingerprints")
|
logger.log(logLevel, "Setting captureFileFingerprints: $develocityCaptureFileFingerprints")
|
||||||
if (isAtLeast(develocityPluginVersion, '3.17')) {
|
if (isAtLeast(develocityPluginVersion, '3.17')) {
|
||||||
buildScanExtension.capture.fileFingerprints.set(develocityCaptureFileFingerprints)
|
buildScanExtension.capture.fileFingerprints.set(develocityCaptureFileFingerprints)
|
||||||
} else if (isAtLeast(develocityPluginVersion, '3.7')) {
|
} else if (isAtLeast(develocityPluginVersion, '3.7')) {
|
||||||
@ -225,7 +231,7 @@ void enableDevelocityInjection() {
|
|||||||
develocity.buildScan.termsOfUseAgree = buildScanTermsOfUseAgree
|
develocity.buildScan.termsOfUseAgree = buildScanTermsOfUseAgree
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.lifecycle("Setting uploadInBackground: $buildScanUploadInBackground")
|
logger.log(logLevel, "Setting uploadInBackground: $buildScanUploadInBackground")
|
||||||
develocity.buildScan.uploadInBackground = buildScanUploadInBackground
|
develocity.buildScan.uploadInBackground = buildScanUploadInBackground
|
||||||
},
|
},
|
||||||
{ buildScan ->
|
{ buildScan ->
|
||||||
@ -250,7 +256,7 @@ void enableDevelocityInjection() {
|
|||||||
|
|
||||||
// uploadInBackground available for build-scan-plugin 3.3.4 and later only
|
// uploadInBackground available for build-scan-plugin 3.3.4 and later only
|
||||||
if (buildScan.metaClass.respondsTo(buildScan, 'setUploadInBackground', Boolean)) {
|
if (buildScan.metaClass.respondsTo(buildScan, 'setUploadInBackground', Boolean)) {
|
||||||
logger.lifecycle("Setting uploadInBackground: $buildScanUploadInBackground")
|
logger.log(logLevel, "Setting uploadInBackground: $buildScanUploadInBackground")
|
||||||
buildScan.uploadInBackground = buildScanUploadInBackground
|
buildScan.uploadInBackground = buildScanUploadInBackground
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -261,7 +267,7 @@ void enableDevelocityInjection() {
|
|||||||
it.moduleVersion.with { group == "com.gradle" && name == "common-custom-user-data-gradle-plugin" }
|
it.moduleVersion.with { group == "com.gradle" && name == "common-custom-user-data-gradle-plugin" }
|
||||||
}
|
}
|
||||||
if (!ccudPluginComponent) {
|
if (!ccudPluginComponent) {
|
||||||
logger.lifecycle("Applying $CCUD_PLUGIN_CLASS with version $ccudPluginVersion via init script")
|
logger.log(logLevel, "Applying $CCUD_PLUGIN_CLASS with version $ccudPluginVersion via init script")
|
||||||
pluginManager.apply(initscript.classLoader.loadClass(CCUD_PLUGIN_CLASS))
|
pluginManager.apply(initscript.classLoader.loadClass(CCUD_PLUGIN_CLASS))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -274,7 +280,7 @@ void enableDevelocityInjection() {
|
|||||||
def pluginClass = dvOrGe(DEVELOCITY_PLUGIN_CLASS, GRADLE_ENTERPRISE_PLUGIN_CLASS)
|
def pluginClass = dvOrGe(DEVELOCITY_PLUGIN_CLASS, GRADLE_ENTERPRISE_PLUGIN_CLASS)
|
||||||
applyPluginExternally(settings.pluginManager, pluginClass, develocityPluginVersion)
|
applyPluginExternally(settings.pluginManager, pluginClass, develocityPluginVersion)
|
||||||
if (develocityUrl) {
|
if (develocityUrl) {
|
||||||
logger.lifecycle("Connection to Develocity: $develocityUrl, allowUntrustedServer: $develocityAllowUntrustedServer, captureFileFingerprints: $develocityCaptureFileFingerprints")
|
logger.log(logLevel, "Connection to Develocity: $develocityUrl, allowUntrustedServer: $develocityAllowUntrustedServer, captureFileFingerprints: $develocityCaptureFileFingerprints")
|
||||||
eachDevelocitySettingsExtension(settings) { ext ->
|
eachDevelocitySettingsExtension(settings) { ext ->
|
||||||
// server and allowUntrustedServer must be configured via buildScan extension for gradle-enterprise-plugin 3.1.1 and earlier
|
// server and allowUntrustedServer must be configured via buildScan extension for gradle-enterprise-plugin 3.1.1 and earlier
|
||||||
if (ext.metaClass.respondsTo(ext, 'getServer')) {
|
if (ext.metaClass.respondsTo(ext, 'getServer')) {
|
||||||
@ -293,13 +299,13 @@ void enableDevelocityInjection() {
|
|||||||
|
|
||||||
eachDevelocitySettingsExtension(settings,
|
eachDevelocitySettingsExtension(settings,
|
||||||
{ develocity ->
|
{ develocity ->
|
||||||
logger.lifecycle("Setting captureFileFingerprints: $develocityCaptureFileFingerprints")
|
logger.log(logLevel, "Setting captureFileFingerprints: $develocityCaptureFileFingerprints")
|
||||||
develocity.buildScan.capture.fileFingerprints = develocityCaptureFileFingerprints
|
develocity.buildScan.capture.fileFingerprints = develocityCaptureFileFingerprints
|
||||||
},
|
},
|
||||||
{ gradleEnterprise ->
|
{ gradleEnterprise ->
|
||||||
gradleEnterprise.buildScan.publishAlways()
|
gradleEnterprise.buildScan.publishAlways()
|
||||||
if (isAtLeast(develocityPluginVersion, '2.1')) {
|
if (isAtLeast(develocityPluginVersion, '2.1')) {
|
||||||
logger.lifecycle("Setting captureFileFingerprints: $develocityCaptureFileFingerprints")
|
logger.log(logLevel, "Setting captureFileFingerprints: $develocityCaptureFileFingerprints")
|
||||||
if (isAtLeast(develocityPluginVersion, '3.7')) {
|
if (isAtLeast(develocityPluginVersion, '3.7')) {
|
||||||
gradleEnterprise.buildScan.capture.taskInputFiles = develocityCaptureFileFingerprints
|
gradleEnterprise.buildScan.capture.taskInputFiles = develocityCaptureFileFingerprints
|
||||||
} else {
|
} else {
|
||||||
@ -325,7 +331,7 @@ void enableDevelocityInjection() {
|
|||||||
develocity.buildScan.termsOfUseAgree = buildScanTermsOfUseAgree
|
develocity.buildScan.termsOfUseAgree = buildScanTermsOfUseAgree
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.lifecycle("Setting uploadInBackground: $buildScanUploadInBackground")
|
logger.log(logLevel, "Setting uploadInBackground: $buildScanUploadInBackground")
|
||||||
develocity.buildScan.uploadInBackground = buildScanUploadInBackground
|
develocity.buildScan.uploadInBackground = buildScanUploadInBackground
|
||||||
},
|
},
|
||||||
{ gradleEnterprise ->
|
{ gradleEnterprise ->
|
||||||
@ -349,7 +355,7 @@ void enableDevelocityInjection() {
|
|||||||
|
|
||||||
// uploadInBackground available for gradle-enterprise-plugin 3.3.4 and later only
|
// uploadInBackground available for gradle-enterprise-plugin 3.3.4 and later only
|
||||||
if (gradleEnterprise.buildScan.metaClass.respondsTo(gradleEnterprise.buildScan, 'setUploadInBackground', Boolean)) {
|
if (gradleEnterprise.buildScan.metaClass.respondsTo(gradleEnterprise.buildScan, 'setUploadInBackground', Boolean)) {
|
||||||
logger.lifecycle("Setting uploadInBackground: $buildScanUploadInBackground")
|
logger.log(logLevel, "Setting uploadInBackground: $buildScanUploadInBackground")
|
||||||
gradleEnterprise.buildScan.uploadInBackground = buildScanUploadInBackground
|
gradleEnterprise.buildScan.uploadInBackground = buildScanUploadInBackground
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -357,7 +363,7 @@ void enableDevelocityInjection() {
|
|||||||
|
|
||||||
if (ccudPluginVersion) {
|
if (ccudPluginVersion) {
|
||||||
if (!settings.pluginManager.hasPlugin(CCUD_PLUGIN_ID)) {
|
if (!settings.pluginManager.hasPlugin(CCUD_PLUGIN_ID)) {
|
||||||
logger.lifecycle("Applying $CCUD_PLUGIN_CLASS with version $ccudPluginVersion via init script")
|
logger.log(logLevel, "Applying $CCUD_PLUGIN_CLASS with version $ccudPluginVersion via init script")
|
||||||
settings.pluginManager.apply(initscript.classLoader.loadClass(CCUD_PLUGIN_CLASS))
|
settings.pluginManager.apply(initscript.classLoader.loadClass(CCUD_PLUGIN_CLASS))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -366,7 +372,8 @@ void enableDevelocityInjection() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void applyPluginExternally(def pluginManager, String pluginClassName, String pluginVersion) {
|
void applyPluginExternally(def pluginManager, String pluginClassName, String pluginVersion) {
|
||||||
logger.lifecycle("Applying $pluginClassName with version $pluginVersion via init script")
|
def logLevel = Boolean.parseBoolean(getInputParam(gradle, 'develocity.injection.debug')) ? LogLevel.LIFECYCLE : LogLevel.INFO
|
||||||
|
logger.log(logLevel, "Applying $pluginClassName with version $pluginVersion via init script")
|
||||||
|
|
||||||
def externallyApplied = 'develocity.externally-applied'
|
def externallyApplied = 'develocity.externally-applied'
|
||||||
def externallyAppliedDeprecated = 'gradle.enterprise.externally-applied'
|
def externallyAppliedDeprecated = 'gradle.enterprise.externally-applied'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user