Update develocity-injection init script to v2.0 (#593)

Updates the develocity-injection init script to the latest reference
script content
from https://github.com/gradle/develocity-ci-injection.

---------

Co-authored-by: daz <daz@gradle.com>
This commit is contained in:
Bot Githubaction
2025-04-04 21:39:30 +02:00
committed by GitHub
parent df11ab8fb2
commit 572d36861a
5 changed files with 99 additions and 87 deletions

View File

@@ -4,28 +4,40 @@ import {setupToken} from './short-lived-token'
export async function setup(config: BuildScanConfig): Promise<void> {
maybeExportVariable('DEVELOCITY_INJECTION_INIT_SCRIPT_NAME', 'gradle-actions.inject-develocity.init.gradle')
maybeExportVariable('DEVELOCITY_AUTO_INJECTION_CUSTOM_VALUE', 'gradle-actions')
maybeExportVariable('DEVELOCITY_INJECTION_CUSTOM_VALUE', 'gradle-actions')
maybeExportVariableNotEmpty('DEVELOCITY_INJECTION_ENABLED', config.getDevelocityInjectionEnabled())
maybeExportVariableNotEmpty('DEVELOCITY_URL', config.getDevelocityUrl())
maybeExportVariableNotEmpty('DEVELOCITY_ALLOW_UNTRUSTED_SERVER', config.getDevelocityAllowUntrustedServer())
maybeExportVariableNotEmpty('DEVELOCITY_CAPTURE_FILE_FINGERPRINTS', config.getDevelocityCaptureFileFingerprints())
maybeExportVariableNotEmpty('DEVELOCITY_ENFORCE_URL', config.getDevelocityEnforceUrl())
maybeExportVariableNotEmpty('DEVELOCITY_PLUGIN_VERSION', config.getDevelocityPluginVersion())
maybeExportVariableNotEmpty('DEVELOCITY_CCUD_PLUGIN_VERSION', config.getDevelocityCcudPluginVersion())
maybeExportVariableNotEmpty('GRADLE_PLUGIN_REPOSITORY_URL', config.getGradlePluginRepositoryUrl())
maybeExportVariableNotEmpty('GRADLE_PLUGIN_REPOSITORY_USERNAME', config.getGradlePluginRepositoryUsername())
maybeExportVariableNotEmpty('GRADLE_PLUGIN_REPOSITORY_PASSWORD', config.getGradlePluginRepositoryPassword())
maybeExportVariableNotEmpty('DEVELOCITY_INJECTION_URL', config.getDevelocityUrl())
maybeExportVariableNotEmpty(
'DEVELOCITY_INJECTION_ALLOW_UNTRUSTED_SERVER',
config.getDevelocityAllowUntrustedServer()
)
maybeExportVariableNotEmpty(
'DEVELOCITY_INJECTION_CAPTURE_FILE_FINGERPRINTS',
config.getDevelocityCaptureFileFingerprints()
)
maybeExportVariableNotEmpty('DEVELOCITY_INJECTION_ENFORCE_URL', config.getDevelocityEnforceUrl())
maybeExportVariableNotEmpty('DEVELOCITY_INJECTION_DEVELOCITY_PLUGIN_VERSION', config.getDevelocityPluginVersion())
maybeExportVariableNotEmpty('DEVELOCITY_INJECTION_CCUD_PLUGIN_VERSION', config.getDevelocityCcudPluginVersion())
maybeExportVariableNotEmpty('DEVELOCITY_INJECTION__PLUGIN_REPOSITORY_URL', config.getGradlePluginRepositoryUrl())
maybeExportVariableNotEmpty(
'DEVELOCITY_INJECTION__PLUGIN_REPOSITORY_USERNAME',
config.getGradlePluginRepositoryUsername()
)
maybeExportVariableNotEmpty(
'DEVELOCITY_INJECTION__PLUGIN_REPOSITORY_PASSWORD',
config.getGradlePluginRepositoryPassword()
)
// If build-scan-publish is enabled, ensure the environment variables are set
// The DEVELOCITY_PLUGIN_VERSION and DEVELOCITY_CCUD_PLUGIN_VERSION are set to the latest versions
// except if they are defined in the configuration
if (config.getBuildScanPublishEnabled()) {
maybeExportVariable('DEVELOCITY_INJECTION_ENABLED', 'true')
maybeExportVariable('DEVELOCITY_PLUGIN_VERSION', '3.19.2')
maybeExportVariable('DEVELOCITY_CCUD_PLUGIN_VERSION', '2.1')
maybeExportVariable('DEVELOCITY_TERMS_OF_USE_URL', config.getBuildScanTermsOfUseUrl())
maybeExportVariable('DEVELOCITY_TERMS_OF_USE_AGREE', config.getBuildScanTermsOfUseAgree())
maybeExportVariable('DEVELOCITY_INJECTION_DEVELOCITY_PLUGIN_VERSION', '3.19.2')
maybeExportVariable('DEVELOCITY_INJECTION_CCUD_PLUGIN_VERSION', '2.1')
maybeExportVariable('DEVELOCITY_INJECTION_TERMS_OF_USE_URL', config.getBuildScanTermsOfUseUrl())
maybeExportVariable('DEVELOCITY_INJECTION_TERMS_OF_USE_AGREE', config.getBuildScanTermsOfUseAgree())
}
return setupToken(

View File

@@ -1,6 +1,6 @@
/*
* Initscript for injection of Develocity into Gradle builds.
* Version: 1.3
* Version: 2.0
*/
import org.gradle.util.GradleVersion
@@ -18,24 +18,24 @@ initscript {
return gradle.startParameter.systemPropertiesArgs[name] ?: System.getProperty(name) ?: System.getenv(envVarName)
}
def requestedInitScriptName = getInputParam(gradle, 'develocity.injection.init-script-name')
def requestedInitScriptName = getInputParam(gradle, 'develocity-injection.init-script-name')
def initScriptName = buildscript.sourceFile.name
if (requestedInitScriptName != initScriptName) {
return
}
// Plugin loading is only required for Develocity injection. Abort early if not enabled.
def develocityInjectionEnabled = Boolean.parseBoolean(getInputParam(gradle, "develocity.injection-enabled"))
def develocityInjectionEnabled = Boolean.parseBoolean(getInputParam(gradle, "develocity-injection.enabled"))
if (!develocityInjectionEnabled) {
return
}
def pluginRepositoryUrl = getInputParam(gradle, 'gradle.plugin-repository.url')
def pluginRepositoryUsername = getInputParam(gradle, 'gradle.plugin-repository.username')
def pluginRepositoryPassword = getInputParam(gradle, 'gradle.plugin-repository.password')
def develocityPluginVersion = getInputParam(gradle, 'develocity.plugin.version')
def ccudPluginVersion = getInputParam(gradle, 'develocity.ccud-plugin.version')
def logLevel = Boolean.parseBoolean(getInputParam(gradle, 'develocity.injection.debug')) ? LogLevel.LIFECYCLE : LogLevel.INFO
def pluginRepositoryUrl = getInputParam(gradle, 'develocity-injection.plugin-repository.url')
def pluginRepositoryUsername = getInputParam(gradle, 'develocity-injection.plugin-repository.username')
def pluginRepositoryPassword = getInputParam(gradle, 'develocity-injection.plugin-repository.password')
def develocityPluginVersion = getInputParam(gradle, 'develocity-injection.develocity-plugin.version')
def ccudPluginVersion = getInputParam(gradle, 'develocity-injection.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 atLeastGradle4 = GradleVersion.current() >= GradleVersion.version('4.0')
@@ -91,10 +91,10 @@ if (!isTopLevelBuild) {
return
}
def requestedInitScriptName = getInputParam(gradle, 'develocity.injection.init-script-name')
def requestedInitScriptName = getInputParam(gradle, 'develocity-injection.init-script-name')
def initScriptName = buildscript.sourceFile.name
def develocityInjectionEnabled = Boolean.parseBoolean(getInputParam(gradle, "develocity.injection-enabled"))
def develocityInjectionEnabled = Boolean.parseBoolean(getInputParam(gradle, "develocity-injection.enabled"))
if (develocityInjectionEnabled) {
if (requestedInitScriptName != initScriptName) {
logger.log(LogLevel.WARN, "Develocity injection not enabled because requested init script name was '${requestedInitScriptName}', but '${initScriptName}' was expected")
@@ -127,17 +127,17 @@ void enableDevelocityInjection() {
def CCUD_PLUGIN_ID = 'com.gradle.common-custom-user-data-gradle-plugin'
def CCUD_PLUGIN_CLASS = 'com.gradle.CommonCustomUserDataGradlePlugin'
def develocityUrl = getInputParam(gradle, 'develocity.url')
def develocityAllowUntrustedServer = Boolean.parseBoolean(getInputParam(gradle, 'develocity.allow-untrusted-server'))
def develocityEnforceUrl = Boolean.parseBoolean(getInputParam(gradle, 'develocity.enforce-url'))
def buildScanUploadInBackground = Boolean.parseBoolean(getInputParam(gradle, 'develocity.build-scan.upload-in-background'))
def develocityCaptureFileFingerprints = getInputParam(gradle, 'develocity.capture-file-fingerprints') ? Boolean.parseBoolean(getInputParam(gradle, 'develocity.capture-file-fingerprints')) : true
def develocityPluginVersion = getInputParam(gradle, 'develocity.plugin.version')
def ccudPluginVersion = getInputParam(gradle, 'develocity.ccud-plugin.version')
def buildScanTermsOfUseUrl = getInputParam(gradle, 'develocity.terms-of-use.url')
def buildScanTermsOfUseAgree = getInputParam(gradle, 'develocity.terms-of-use.agree')
def ciAutoInjectionCustomValueValue = getInputParam(gradle, 'develocity.auto-injection.custom-value')
def logLevel = Boolean.parseBoolean(getInputParam(gradle, 'develocity.injection.debug')) ? LogLevel.LIFECYCLE : LogLevel.INFO
def develocityUrl = getInputParam(gradle, 'develocity-injection.url')
def develocityAllowUntrustedServer = Boolean.parseBoolean(getInputParam(gradle, 'develocity-injection.allow-untrusted-server'))
def develocityEnforceUrl = Boolean.parseBoolean(getInputParam(gradle, 'develocity-injection.enforce-url'))
def buildScanUploadInBackground = Boolean.parseBoolean(getInputParam(gradle, 'develocity-injection.upload-in-background'))
def develocityCaptureFileFingerprints = getInputParam(gradle, 'develocity-injection.capture-file-fingerprints') ? Boolean.parseBoolean(getInputParam(gradle, 'develocity-injection.capture-file-fingerprints')) : true
def develocityPluginVersion = getInputParam(gradle, 'develocity-injection.develocity-plugin.version')
def ccudPluginVersion = getInputParam(gradle, 'develocity-injection.ccud-plugin.version')
def buildScanTermsOfUseUrl = getInputParam(gradle, 'develocity-injection.terms-of-use.url')
def buildScanTermsOfUseAgree = getInputParam(gradle, 'develocity-injection.terms-of-use.agree')
def ciAutoInjectionCustomValueValue = getInputParam(gradle, 'develocity-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 atLeastGradle4 = GradleVersion.current() >= GradleVersion.version('4.0')
@@ -372,7 +372,7 @@ void enableDevelocityInjection() {
}
void applyPluginExternally(def pluginManager, String pluginClassName, String pluginVersion) {
def logLevel = Boolean.parseBoolean(getInputParam(gradle, 'develocity.injection.debug')) ? LogLevel.LIFECYCLE : LogLevel.INFO
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'