Skip to content

Commit

Permalink
Introduce extension functions that return existing project configurat…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
qurbonzoda committed Jul 27, 2020
1 parent e26e66f commit 4b429fe
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
5 changes: 2 additions & 3 deletions .teamcity/additionalConfiguration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
*/

import jetbrains.buildServer.configs.kotlin.v2019_2.BuildType
import jetbrains.buildServer.configs.kotlin.v2019_2.Project

fun Project.additionalConfiguration(buildVersion: BuildType) {
subProject(benchmarksProject(buildVersion))
fun Project.additionalConfiguration() {
subProject(benchmarksProject(existingBuildVersion()))
}
20 changes: 10 additions & 10 deletions .teamcity/settings.kts
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,24 @@ project {
}
}

val deployConfigure = deployConfigure().apply {
val deployVersion = deployVersion().apply {
dependsOnSnapshot(buildAll, onFailure = FailureAction.IGNORE)
}
val deploys = platforms.map { deploy(it, deployConfigure) }
val deployPublish = deployPublish(deployConfigure).apply {
val deploys = platforms.map { deploy(it, deployVersion) }
val deployPublish = deployPublish(deployVersion).apply {
dependsOnSnapshot(buildAll, onFailure = FailureAction.IGNORE)
deploys.forEach {
dependsOnSnapshot(it)
}
}

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

additionalConfiguration(buildVersion)
additionalConfiguration()
}

fun Project.buildVersion() = BuildType {
id("Build_Version")
id(BUILD_CONFIGURE_VERSION_ID)
this.name = "Build (Configure Version)"
commonConfigure()

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

fun Project.buildAll(versionBuild: BuildType) = BuildType {
id("Build_All")
id(BUILD_ALL_ID)
this.name = "Build (All)"
type = BuildTypeSettings.Type.COMPOSITE

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

fun Project.deployConfigure() = BuildType {
id("Deploy_Configure")
fun Project.deployVersion() = BuildType {
id(DEPLOY_CONFIGURE_VERSION_ID)
this.name = "Deploy (Configure Version)"
commonConfigure()

Expand Down Expand Up @@ -159,7 +159,7 @@ fun Project.deployConfigure() = BuildType {
}.also { buildType(it) }

fun Project.deployPublish(configureBuild: BuildType) = BuildType {
id("Deploy_Publish")
id(DEPLOY_PUBLISH_ID)
this.name = "Deploy (Publish)"
type = BuildTypeSettings.Type.COMPOSITE
dependsOnSnapshot(configureBuild)
Expand Down
16 changes: 16 additions & 0 deletions .teamcity/utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@ fun Platform.buildTypeId(): String = buildTypeName().substringBefore(" ")
fun Platform.teamcityAgentName(): String = buildTypeName()


const val BUILD_CONFIGURE_VERSION_ID = "Build_Version"
const val BUILD_ALL_ID = "Build_All"
const val DEPLOY_CONFIGURE_VERSION_ID = "Deploy_Configure"
const val DEPLOY_PUBLISH_ID = "Deploy_Publish"

private fun existingBuildId(suffix: String): String = "RootProjectId_$suffix"
private fun Project.existingBuildWithId(id: String): BuildType = buildTypes.single { it.id.toString() == existingBuildId(id) }

fun Project.existingBuildVersion(): BuildType = existingBuildWithId(BUILD_CONFIGURE_VERSION_ID)
fun Project.existingBuildAll(): BuildType = existingBuildWithId(BUILD_ALL_ID)
fun Project.existingBuild(platform: Platform): BuildType = existingBuildWithId("Build_${platform.buildTypeId()}")
fun Project.existingDeployVersion(): BuildType = existingBuildWithId(DEPLOY_CONFIGURE_VERSION_ID)
fun Project.existingDeployPublish(): BuildType = existingBuildWithId(DEPLOY_PUBLISH_ID)
fun Project.existingDeploy(platform: Platform): BuildType = existingBuildWithId("Deploy_${platform.buildTypeId()}")


fun Project.buildType(name: String, platform: Platform, configure: BuildType.() -> Unit) = BuildType {
// ID is prepended with Project ID, so don't repeat it here
// ID should conform to identifier rules, so just letters, numbers and underscore
Expand Down

0 comments on commit 4b429fe

Please sign in to comment.