Не подтверждена Коммит 8a8b1867 создал по автору Osip Fatkullin's avatar Osip Fatkullin Зафиксировано автором GitHub
Просмотр файлов

KTOR-8344 Enable build cache for settings plugins (#4745)

* Remove redundant build scan customization
* Configure build cache for build-settings-logic
* Obfuscate hostname and username
владелец 6e316974
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. * Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/ */
plugins {
id("com.gradle.develocity") version "3.17.6"
}
dependencyResolutionManagement { dependencyResolutionManagement {
versionCatalogs { versionCatalogs {
create("libs") { create("libs") {
...@@ -11,3 +15,24 @@ dependencyResolutionManagement { ...@@ -11,3 +15,24 @@ dependencyResolutionManagement {
} }
rootProject.name = "build-settings-logic" rootProject.name = "build-settings-logic"
// region Build Cache Settings
develocity {
// Should be in sync with ktorbuild.develocity.settings.gradle.kts
server = "https://ge.jetbrains.com"
}
val isCIRun = providers.environmentVariable("TEAMCITY_VERSION").isPresent
buildCache {
if (isCIRun) {
local {
isEnabled = false
}
}
remote(develocity.buildCache) {
isPush = isCIRun
isEnabled = true
}
}
// endregion
/*
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/
import com.gradle.develocity.agent.gradle.DevelocityConfiguration
import org.gradle.api.initialization.Settings
fun Settings.enrichTeamCityData() {
val ge = extensions.getByType(DevelocityConfiguration::class.java)
gradle.projectsEvaluated {
if (isCIRun) {
val buildTypeId = "teamcity.buildType.id"
val buildId = "teamcity.build.id"
if (gradle.rootProject.hasProperty(buildId) && gradle.rootProject.hasProperty(buildTypeId)) {
val buildIdValue = gradle.rootProject.property(buildId).toString()
val teamCityBuildNumber = java.net.URLEncoder.encode(buildIdValue, "UTF-8")
val teamCityBuildTypeId = gradle.rootProject.property(buildTypeId)
ge.buildScan.link(
"Ktor TeamCity build",
"${TEAMCITY_URL}/buildConfiguration/${teamCityBuildTypeId}/${teamCityBuildNumber}"
)
}
if (gradle.rootProject.hasProperty(buildId)) {
ge.buildScan.value("CI build id", gradle.rootProject.property(buildId) as String)
}
}
}
}
fun Settings.enrichGitData() {
val ge = extensions.getByType(DevelocityConfiguration::class.java)
val skipGitTags = settings.providers.gradleProperty("ktor.develocity.skipGitTags")
.getOrElse("false")
.toBooleanStrict()
gradle.projectsEvaluated {
if (!isCIRun && !skipGitTags) {
// Git commit id
val commitId = execute("git rev-parse --verify HEAD")
if (commitId.isNotEmpty()) {
ge.buildScan.value("Git Commit ID", commitId)
ge.buildScan.link("GitHub Commit Link", "$GITHUB_REPO/tree/$commitId")
}
// Git branch name
val branchName = execute("git rev-parse --abbrev-ref HEAD")
if (branchName.isNotEmpty()) {
ge.buildScan.value("Git Branch Name", branchName)
ge.buildScan.link("GitHub Branch Link", "$GITHUB_REPO/tree/$branchName")
}
// Git dirty local state
val status = execute("git status --porcelain")
if (status.isNotEmpty()) {
ge.buildScan.value("Git Status", status)
}
}
}
}
/*
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/
import org.gradle.api.initialization.Settings
@Suppress("UnstableApiUsage")
fun Settings.execute(cmd: String): String {
return settings.providers.exec {
commandLine(cmd.split(" "))
}.standardOutput.asText.get().trim()
}
/* /*
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. * Copyright 2014-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/ */
import java.util.* import java.util.*
...@@ -9,18 +9,37 @@ plugins { ...@@ -9,18 +9,37 @@ plugins {
id("com.gradle.common-custom-user-data-gradle-plugin") id("com.gradle.common-custom-user-data-gradle-plugin")
} }
val isCIRun = providers.environmentVariable("TEAMCITY_VERSION").isPresent
develocity { develocity {
val startParameter = gradle.startParameter val startParameter = gradle.startParameter
val scanJournal = File(settingsDir, "scan-journal.log") val scanJournal = File(settingsDir, "scan-journal.log")
server = DEVELOCITY_SERVER // Should be in sync with settings.gradle.kts
server = "https://ge.jetbrains.com"
buildScan { buildScan {
uploadInBackground = !isCIRun uploadInBackground = !isCIRun
// obfuscate NIC since we don't want to expose user real IP (will be relevant without VPN) // These properties should be specified in ~/.gradle/gradle.properties
val overriddenUsername = providers.gradleProperty("ktor.develocity.username").orNull.orEmpty().trim()
val overriddenHostname = providers.gradleProperty("ktor.develocity.hostname").orNull.orEmpty().trim()
obfuscation { obfuscation {
ipAddresses { addresses -> addresses.map { _ -> "0.0.0.0" } } ipAddresses { listOf("0.0.0.0") }
hostname { overriddenHostname.ifEmpty { "concealed" } }
username { originalUserName ->
when {
isCIRun -> "TeamCity"
overriddenUsername == "<default>" -> originalUserName
overriddenUsername.isNotEmpty() -> overriddenUsername
else -> buildString {
append(originalUserName.first())
append("***")
append(originalUserName.last())
}
}
}
} }
capture { capture {
...@@ -31,9 +50,9 @@ develocity { ...@@ -31,9 +50,9 @@ develocity {
scanJournal.appendText("${Date()} — $buildScanUri — $startParameter\n") scanJournal.appendText("${Date()} — $buildScanUri — $startParameter\n")
} }
val skipBuildScans = settings.providers.gradleProperty("ktor.develocity.skipBuildScans") val skipBuildScans = providers.gradleProperty("ktor.develocity.skipBuildScans")
.getOrElse("false") .orNull
.toBooleanStrict() .toBoolean()
publishing.onlyIf { !skipBuildScans } publishing.onlyIf { !skipBuildScans }
} }
...@@ -51,6 +70,3 @@ buildCache { ...@@ -51,6 +70,3 @@ buildCache {
isEnabled = true isEnabled = true
} }
} }
enrichTeamCityData()
enrichGitData()
/*
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/
const val DEVELOCITY_SERVER = "https://ge.jetbrains.com"
const val GITHUB_REPO = "https://github.com/ktorio/ktor"
const val TEAMCITY_URL = "https://ktor.teamcity.com"
val isCIRun = System.getenv("TEAMCITY_VERSION") != null
...@@ -61,10 +61,10 @@ org.jetbrains.dokka.classpath.useNativeDistributionAccessor=true ...@@ -61,10 +61,10 @@ org.jetbrains.dokka.classpath.useNativeDistributionAccessor=true
org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled
org.jetbrains.dokka.experimental.gradle.pluginMode.noWarn=true org.jetbrains.dokka.experimental.gradle.pluginMode.noWarn=true
# Uncomment to skip attempts to publish Develocity build scans # NOTE: Add these properties to ~/.gradle/gradle.properties if you want to customize them.
# Add this property to ~/.gradle/gradle.properties to avoid polluting git with unwanted changes # Disable build scans publishing
#ktor.develocity.skipBuildScans=true #ktor.develocity.skipBuildScans=true
# A username to be shown in build scans. Set to '<default>' to show the real username.
# Uncomment to skip adding git tags to Develocity build scan #ktor.develocity.username=<default>
# Add this property to ~/.gradle/gradle.properties to avoid polluting git with unwanted changes # A hostname to be shown in build scans
#ktor.develocity.skipGitTags=true #ktor.develocity.hostname=
...@@ -9,7 +9,7 @@ pluginManagement { ...@@ -9,7 +9,7 @@ pluginManagement {
plugins { plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "0.9.0" id("org.gradle.toolchains.foojay-resolver-convention") version "0.9.0"
id("conventions-dependency-resolution-management") id("conventions-dependency-resolution-management")
id("conventions-develocity") id("ktorbuild.develocity")
} }
rootProject.name = "ktor" rootProject.name = "ktor"
......
Поддерживает Markdown
0% или .
You are about to add 0 people to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Пожалуйста, зарегистрируйтесь или чтобы прокомментировать