Skip to content

Commit 4b429fe

Browse files
author
Abduqodiri Qurbonzoda
committed
Introduce extension functions that return existing project configurations
1 parent e26e66f commit 4b429fe

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

.teamcity/additionalConfiguration.kt

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
44
*/
55

6-
import jetbrains.buildServer.configs.kotlin.v2019_2.BuildType
76
import jetbrains.buildServer.configs.kotlin.v2019_2.Project
87

9-
fun Project.additionalConfiguration(buildVersion: BuildType) {
10-
subProject(benchmarksProject(buildVersion))
8+
fun Project.additionalConfiguration() {
9+
subProject(benchmarksProject(existingBuildVersion()))
1110
}

.teamcity/settings.kts

+10-10
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,24 @@ project {
4545
}
4646
}
4747

48-
val deployConfigure = deployConfigure().apply {
48+
val deployVersion = deployVersion().apply {
4949
dependsOnSnapshot(buildAll, onFailure = FailureAction.IGNORE)
5050
}
51-
val deploys = platforms.map { deploy(it, deployConfigure) }
52-
val deployPublish = deployPublish(deployConfigure).apply {
51+
val deploys = platforms.map { deploy(it, deployVersion) }
52+
val deployPublish = deployPublish(deployVersion).apply {
5353
dependsOnSnapshot(buildAll, onFailure = FailureAction.IGNORE)
5454
deploys.forEach {
5555
dependsOnSnapshot(it)
5656
}
5757
}
5858

59-
buildTypesOrder = listOf(buildAll, buildVersion, *builds.toTypedArray(), deployPublish, deployConfigure, *deploys.toTypedArray())
59+
buildTypesOrder = listOf(buildAll, buildVersion, *builds.toTypedArray(), deployPublish, deployVersion, *deploys.toTypedArray())
6060

61-
additionalConfiguration(buildVersion)
61+
additionalConfiguration()
6262
}
6363

6464
fun Project.buildVersion() = BuildType {
65-
id("Build_Version")
65+
id(BUILD_CONFIGURE_VERSION_ID)
6666
this.name = "Build (Configure Version)"
6767
commonConfigure()
6868

@@ -84,7 +84,7 @@ fun Project.buildVersion() = BuildType {
8484
}.also { buildType(it) }
8585

8686
fun Project.buildAll(versionBuild: BuildType) = BuildType {
87-
id("Build_All")
87+
id(BUILD_ALL_ID)
8888
this.name = "Build (All)"
8989
type = BuildTypeSettings.Type.COMPOSITE
9090

@@ -129,8 +129,8 @@ fun Project.build(platform: Platform, versionBuild: BuildType) = buildType("Buil
129129
artifactRules = "+:build/maven=>maven\n+:build/api=>api"
130130
}
131131

132-
fun Project.deployConfigure() = BuildType {
133-
id("Deploy_Configure")
132+
fun Project.deployVersion() = BuildType {
133+
id(DEPLOY_CONFIGURE_VERSION_ID)
134134
this.name = "Deploy (Configure Version)"
135135
commonConfigure()
136136

@@ -159,7 +159,7 @@ fun Project.deployConfigure() = BuildType {
159159
}.also { buildType(it) }
160160

161161
fun Project.deployPublish(configureBuild: BuildType) = BuildType {
162-
id("Deploy_Publish")
162+
id(DEPLOY_PUBLISH_ID)
163163
this.name = "Deploy (Publish)"
164164
type = BuildTypeSettings.Type.COMPOSITE
165165
dependsOnSnapshot(configureBuild)

.teamcity/utils.kt

+16
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,22 @@ fun Platform.buildTypeId(): String = buildTypeName().substringBefore(" ")
3232
fun Platform.teamcityAgentName(): String = buildTypeName()
3333

3434

35+
const val BUILD_CONFIGURE_VERSION_ID = "Build_Version"
36+
const val BUILD_ALL_ID = "Build_All"
37+
const val DEPLOY_CONFIGURE_VERSION_ID = "Deploy_Configure"
38+
const val DEPLOY_PUBLISH_ID = "Deploy_Publish"
39+
40+
private fun existingBuildId(suffix: String): String = "RootProjectId_$suffix"
41+
private fun Project.existingBuildWithId(id: String): BuildType = buildTypes.single { it.id.toString() == existingBuildId(id) }
42+
43+
fun Project.existingBuildVersion(): BuildType = existingBuildWithId(BUILD_CONFIGURE_VERSION_ID)
44+
fun Project.existingBuildAll(): BuildType = existingBuildWithId(BUILD_ALL_ID)
45+
fun Project.existingBuild(platform: Platform): BuildType = existingBuildWithId("Build_${platform.buildTypeId()}")
46+
fun Project.existingDeployVersion(): BuildType = existingBuildWithId(DEPLOY_CONFIGURE_VERSION_ID)
47+
fun Project.existingDeployPublish(): BuildType = existingBuildWithId(DEPLOY_PUBLISH_ID)
48+
fun Project.existingDeploy(platform: Platform): BuildType = existingBuildWithId("Deploy_${platform.buildTypeId()}")
49+
50+
3551
fun Project.buildType(name: String, platform: Platform, configure: BuildType.() -> Unit) = BuildType {
3652
// ID is prepended with Project ID, so don't repeat it here
3753
// ID should conform to identifier rules, so just letters, numbers and underscore

0 commit comments

Comments
 (0)