Skip to content

Commit 8ea0e02

Browse files
author
Abduqodiri Qurbonzoda
committed
Introduce extension functions that return existing project configurations
1 parent 23c628e commit 8ea0e02

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

main/resources/teamcity/settings.kts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,24 @@ project {
4444
}
4545
}
4646

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

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

6060
additionalConfiguration()
6161
}
6262

6363
fun Project.buildVersion() = BuildType {
64-
id("Build_Version")
64+
id(BUILD_CONFIGURE_VERSION_ID)
6565
this.name = "Build (Configure Version)"
6666
commonConfigure()
6767

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

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

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

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

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

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

main/resources/teamcity/utils.kt

Lines changed: 17 additions & 1 deletion
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
@@ -95,4 +111,4 @@ fun BuildType.dependsOnSnapshot(build: BuildType, onFailure: FailureAction = Fai
95111
onDependencyCancel = FailureAction.CANCEL
96112
}
97113
}
98-
}
114+
}

0 commit comments

Comments
 (0)