@@ -73,3 +73,70 @@ dependencyResolutionManagement {
7373}
7474
7575gradle.beforeProject { version = baseVersion }
76+
77+ plugins { id(" com.gradle.develocity" ) version (" 3.18.2" ) }
78+
79+ // Use Apache's Gradle Enterprise instance only in CI and only if the access-key is present
80+ // See
81+ // https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=263426153#ProjectOnboardingInstructionsforDevelocity-GitHubActions
82+ // https://docs.gradle.com/develocity/gradle-plugin/current/#via_environment_variable
83+ val hasDevelocityAccessKey =
84+ System .getenv(" DEVELOCITY_ACCESS_KEY" ) != null &&
85+ System .getenv(" DEVELOCITY_ACCESS_KEY" ).isNotBlank()
86+ val isCI = System .getenv(" CI" ) != null
87+
88+ if (isCI) {
89+ logger.lifecycle(
90+ " Running build in CI ${if (hasDevelocityAccessKey) " with" else " without" } Develocity access"
91+ )
92+ }
93+
94+ // Publish a build-scan automatically in CI, else only on demand.
95+ develocity {
96+ if (isCI) {
97+ if (hasDevelocityAccessKey) {
98+ // The GE instance for Apache rejects unauthenticated build scan uploads, so we publish those
99+ // to Gradle's public one. This means, that CI runs without secrets, aka all PR CI runs, get
100+ // the build scans published at Gradle's infra, while other CI runs publish to Apache's infra.
101+ server = " https://ge.apache.org"
102+ }
103+ buildScan {
104+ termsOfUseUrl = " https://gradle.com/terms-of-service"
105+ termsOfUseAgree = " yes"
106+ // Add some potentially interesting information from the environment
107+ listOf (
108+ " GITHUB_ACTION_REPOSITORY" ,
109+ " GITHUB_ACTOR" ,
110+ " GITHUB_BASE_REF" ,
111+ " GITHUB_HEAD_REF" ,
112+ " GITHUB_JOB" ,
113+ " GITHUB_REF" ,
114+ " GITHUB_REPOSITORY" ,
115+ " GITHUB_RUN_ID" ,
116+ " GITHUB_RUN_NUMBER" ,
117+ " GITHUB_SHA" ,
118+ " GITHUB_WORKFLOW"
119+ )
120+ .forEach { e ->
121+ val v = System .getenv(e)
122+ if (v != null ) {
123+ value(e, v)
124+ }
125+ }
126+ val ghUrl = System .getenv(" GITHUB_SERVER_URL" )
127+ if (ghUrl != null ) {
128+ val ghRepo = System .getenv(" GITHUB_REPOSITORY" )
129+ val ghRunId = System .getenv(" GITHUB_RUN_ID" )
130+ link(" Summary" , " $ghUrl /$ghRepo /actions/runs/$ghRunId " )
131+ link(" PRs" , " $ghUrl /$ghRepo /pulls" )
132+ }
133+ obfuscation { ipAddresses { addresses -> addresses.map { _ -> " 0.0.0.0" } } }
134+ }
135+ } else {
136+ val isBuildScan = gradle.startParameter.isBuildScan
137+ buildScan {
138+ publishing { onlyIf { isBuildScan } }
139+ obfuscation { ipAddresses { addresses -> addresses.map { _ -> " 0.0.0.0" } } }
140+ }
141+ }
142+ }
0 commit comments