|
| 1 | +/* |
| 2 | + * Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. |
| 3 | + */ |
| 4 | + |
| 5 | +import com.gradle.develocity.agent.gradle.DevelocityConfiguration |
| 6 | +import org.gradle.api.initialization.Settings |
| 7 | + |
| 8 | +fun Settings.enrichTeamCityData() { |
| 9 | + val ge = extensions.getByType(DevelocityConfiguration::class.java) |
| 10 | + |
| 11 | + gradle.projectsEvaluated { |
| 12 | + if (isCIRun) { |
| 13 | + val buildTypeId = "teamcity.buildType.id" |
| 14 | + val buildId = "teamcity.build.id" |
| 15 | + |
| 16 | + if (gradle.rootProject.hasProperty(buildId) && gradle.rootProject.hasProperty(buildTypeId)) { |
| 17 | + val buildIdValue = gradle.rootProject.property(buildId).toString() |
| 18 | + val teamCityBuildNumber = java.net.URLEncoder.encode(buildIdValue, Charsets.UTF_8) |
| 19 | + val teamCityBuildTypeId = gradle.rootProject.property(buildTypeId) |
| 20 | + |
| 21 | + ge.buildScan.link( |
| 22 | + "kotlinx.rpc TeamCity build", |
| 23 | + "${TEAMCITY_URL}/buildConfiguration/${teamCityBuildTypeId}/${teamCityBuildNumber}" |
| 24 | + ) |
| 25 | + } |
| 26 | + |
| 27 | + if (gradle.rootProject.hasProperty(buildId)) { |
| 28 | + ge.buildScan.value("CI build id", gradle.rootProject.property(buildId) as String) |
| 29 | + } |
| 30 | + } |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +fun Settings.enrichGitData() { |
| 35 | + val ge = extensions.getByType(DevelocityConfiguration::class.java) |
| 36 | + |
| 37 | + gradle.projectsEvaluated { |
| 38 | + val skipGitTags = settings.providers.gradleProperty("kotlinx.rpc.develocity.skipGitTags") |
| 39 | + .getOrElse("false") |
| 40 | + .toBooleanStrict() |
| 41 | + |
| 42 | + if (!isCIRun && !skipGitTags) { |
| 43 | + // Git commit id |
| 44 | + val commitId = execute("git rev-parse --verify HEAD") |
| 45 | + if (commitId.isNotEmpty()) { |
| 46 | + ge.buildScan.value("Git Commit ID", commitId) |
| 47 | + ge.buildScan.link("GitHub Commit Link", "$GITHUB_REPO/tree/$commitId") |
| 48 | + } |
| 49 | + |
| 50 | + // Git branch name |
| 51 | + val branchName = execute("git rev-parse --abbrev-ref HEAD") |
| 52 | + if (branchName.isNotEmpty()) { |
| 53 | + ge.buildScan.value("Git Branch Name", branchName) |
| 54 | + ge.buildScan.link("GitHub Branch Link", "$GITHUB_REPO/tree/$branchName") |
| 55 | + } |
| 56 | + |
| 57 | + // Git dirty local state |
| 58 | + val status = execute("git status --porcelain") |
| 59 | + if (status.isNotEmpty()) { |
| 60 | + ge.buildScan.value("Git Status", status) |
| 61 | + } |
| 62 | + } |
| 63 | + } |
| 64 | +} |
0 commit comments