Align init script with other CI plugins by checking whether the init script name matches

This commit is contained in:
Pavlo Shevchenko 2024-03-11 16:14:39 +01:00 committed by daz
parent e33d4754ca
commit b9bc45cfbb
No known key found for this signature in database
3 changed files with 16 additions and 0 deletions

View File

@ -3,6 +3,7 @@ import {getBuildScanPublishEnabled, getBuildScanTermsOfUseUrl, getBuildScanTerms
export function setup(): void { export function setup(): void {
if (getBuildScanPublishEnabled() && verifyTermsOfUseAgreement()) { if (getBuildScanPublishEnabled() && verifyTermsOfUseAgreement()) {
maybeExportVariable('DEVELOCITY_INJECTION_INIT_SCRIPT_NAME', 'gradle-actions.inject-develocity.init.gradle')
maybeExportVariable('DEVELOCITY_INJECTION_ENABLED', 'true') maybeExportVariable('DEVELOCITY_INJECTION_ENABLED', 'true')
maybeExportVariable('DEVELOCITY_PLUGIN_VERSION', '3.16.2') maybeExportVariable('DEVELOCITY_PLUGIN_VERSION', '3.16.2')
maybeExportVariable('DEVELOCITY_CCUD_PLUGIN_VERSION', '1.13') maybeExportVariable('DEVELOCITY_CCUD_PLUGIN_VERSION', '1.13')

View File

@ -14,6 +14,12 @@ initscript {
return System.getProperty(name) ?: System.getenv(envVarName) return System.getProperty(name) ?: System.getenv(envVarName)
} }
def requestedInitScriptName = getInputParam('develocity.injection.init-script-name')
def initScriptName = buildscript.sourceFile.name
if (requestedInitScriptName != initScriptName) {
return
}
// finish early if injection is disabled // finish early if injection is disabled
def gradleInjectionEnabled = getInputParam("develocity.injection-enabled") def gradleInjectionEnabled = getInputParam("develocity.injection-enabled")
if (gradleInjectionEnabled != "true") { if (gradleInjectionEnabled != "true") {
@ -97,6 +103,13 @@ def getInputParam = { String name ->
return System.getProperty(name) ?: System.getenv(envVarName) return System.getProperty(name) ?: System.getenv(envVarName)
} }
def requestedInitScriptName = getInputParam('develocity.injection.init-script-name')
def initScriptName = buildscript.sourceFile.name
if (requestedInitScriptName != initScriptName) {
logger.quiet("Ignoring init script '${initScriptName}' as requested name '${requestedInitScriptName}' does not match")
return
}
// finish early if injection is disabled // finish early if injection is disabled
def gradleInjectionEnabled = getInputParam("develocity.injection-enabled") def gradleInjectionEnabled = getInputParam("develocity.injection-enabled")
if (gradleInjectionEnabled != "true") { if (gradleInjectionEnabled != "true") {

View File

@ -534,6 +534,7 @@ class TestDevelocityInjection extends BaseInitScriptTest {
def getEnvVars() { def getEnvVars() {
Map<String, String> envVars = [ Map<String, String> envVars = [
DEVELOCITY_INJECTION_INIT_SCRIPT_NAME : "gradle-actions.inject-develocity.init.gradle",
DEVELOCITY_INJECTION_ENABLED : "true", DEVELOCITY_INJECTION_ENABLED : "true",
DEVELOCITY_URL : serverUrl, DEVELOCITY_URL : serverUrl,
DEVELOCITY_ALLOW_UNTRUSTED_SERVER : "true", DEVELOCITY_ALLOW_UNTRUSTED_SERVER : "true",
@ -552,6 +553,7 @@ class TestDevelocityInjection extends BaseInitScriptTest {
def getJvmArgs() { def getJvmArgs() {
List<String> jvmArgs = [ List<String> jvmArgs = [
"-Ddevelocity.injection.init-script-name=gradle-actions.inject-develocity.init.gradle",
"-Ddevelocity.injection-enabled=true", "-Ddevelocity.injection-enabled=true",
"-Ddevelocity.url=$serverUrl", "-Ddevelocity.url=$serverUrl",
"-Ddevelocity.allow-untrusted-server=true", "-Ddevelocity.allow-untrusted-server=true",