Skip to content

Commit 89cb45a

Browse files
Abduqodiri Qurbonzodaqurbonzoda
authored andcommitted
Extract common utility functions to utils.kt
1 parent fc6ef0d commit 89cb45a

File tree

3 files changed

+104
-79
lines changed

3 files changed

+104
-79
lines changed

main/resources/teamcity/settings.kts

Lines changed: 4 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,6 @@ To debug in IntelliJ Idea, open the 'Maven Projects' tool window (View
2525
*/
2626

2727
version = "2018.2"
28-
val versionSuffixParameter = "versionSuffix"
29-
val teamcitySuffixParameter = "teamcitySuffix"
30-
val releaseVersionParameter = "releaseVersion"
31-
32-
val bintrayUserName = "<<BINTRAY_USER>>"
33-
val bintrayToken = "<<BINTRAY_TOKEN>>"
34-
35-
val platforms = listOf("Windows", "Linux", "Mac OS X")
36-
val jdk = "<<JDK>>"
3728

3829
project {
3930
// Disable editing of project and build settings from the UI to avoid issues with TeamCity
@@ -109,7 +100,7 @@ fun Project.buildAll(versionBuild: BuildType) = BuildType {
109100
commonConfigure()
110101
}.also { buildType(it) }
111102

112-
fun Project.build(platform: String, versionBuild: BuildType) = platform(platform, "Build") {
103+
fun Project.build(platform: Platform, versionBuild: BuildType) = buildType("Build", platform) {
113104

114105
dependsOnSnapshot(versionBuild)
115106

@@ -120,7 +111,7 @@ fun Project.build(platform: String, versionBuild: BuildType) = platform(platform
120111

121112
steps {
122113
gradle {
123-
name = "Build and Test $platform Binaries"
114+
name = "Build and Test ${platform.buildTypeName()} Binaries"
124115
jdkHome = "%env.$jdk%"
125116
jvmArgs = "-Xmx1g"
126117
tasks = "clean publishToBuildLocal check"
@@ -135,21 +126,6 @@ fun Project.build(platform: String, versionBuild: BuildType) = platform(platform
135126
artifactRules = "+:build/maven=>maven\n+:build/api=>api"
136127
}
137128

138-
fun BuildType.dependsOn(build: BuildType, configure: Dependency.() -> Unit) =
139-
apply {
140-
dependencies.dependency(build, configure)
141-
}
142-
143-
fun BuildType.dependsOnSnapshot(build: BuildType, onFailure: FailureAction = FailureAction.FAIL_TO_START, configure: SnapshotDependency.() -> Unit = {}) = apply {
144-
dependencies.dependency(build) {
145-
snapshot {
146-
configure()
147-
onDependencyFailure = onFailure
148-
onDependencyCancel = FailureAction.CANCEL
149-
}
150-
}
151-
}
152-
153129
fun Project.deployConfigure() = BuildType {
154130
id("Deploy_Configure")
155131
this.name = "Deploy (Configure Version)"
@@ -194,7 +170,7 @@ fun Project.deployPublish(configureBuild: BuildType) = BuildType {
194170
}.also { buildType(it) }
195171

196172

197-
fun Project.deploy(platform: String, configureBuild: BuildType) = platform(platform, "Deploy") {
173+
fun Project.deploy(platform: Platform, configureBuild: BuildType) = buildType("Deploy", platform) {
198174
type = BuildTypeSettings.Type.DEPLOYMENT
199175
enablePersonalBuilds = false
200176
maxRunningBuilds = 1
@@ -211,7 +187,7 @@ fun Project.deploy(platform: String, configureBuild: BuildType) = platform(platf
211187

212188
steps {
213189
gradle {
214-
name = "Deploy $platform Binaries"
190+
name = "Deploy ${platform.buildTypeName()} Binaries"
215191
jdkHome = "%env.$jdk%"
216192
jvmArgs = "-Xmx1g"
217193
gradleParams = "--info --stacktrace -P$versionSuffixParameter=%$versionSuffixParameter% -P$releaseVersionParameter=%$releaseVersionParameter% -PbintrayApiKey=%bintray-key% -PbintrayUser=%bintray-user%"
@@ -221,53 +197,3 @@ fun Project.deploy(platform: String, configureBuild: BuildType) = platform(platf
221197
}
222198
}
223199
}.dependsOnSnapshot(configureBuild)
224-
225-
fun Project.platform(platform: String, name: String, configure: BuildType.() -> Unit) = BuildType {
226-
// ID is prepended with Project ID, so don't repeat it here
227-
// ID should conform to identifier rules, so just letters, numbers and underscore
228-
id("${name}_${platform.substringBefore(" ")}")
229-
// Display name of the build configuration
230-
this.name = "$name ($platform)"
231-
232-
requirements {
233-
contains("teamcity.agent.jvm.os.name", platform)
234-
}
235-
236-
params {
237-
// This parameter is needed for macOS agent to be compatible
238-
if (platform.startsWith("Mac")) param("env.JDK_17", "")
239-
}
240-
241-
commonConfigure()
242-
configure()
243-
}.also { buildType(it) }
244-
245-
246-
fun BuildType.commonConfigure() {
247-
requirements {
248-
noLessThan("teamcity.agent.hardware.memorySizeMb", "6144")
249-
}
250-
251-
// Allow to fetch build status through API for badges
252-
allowExternalStatus = true
253-
254-
// Configure VCS, by default use the same and only VCS root from which this configuration is fetched
255-
vcs {
256-
root(DslContext.settingsRoot)
257-
showDependenciesChanges = true
258-
checkoutMode = CheckoutMode.ON_AGENT
259-
}
260-
261-
failureConditions {
262-
errorMessage = true
263-
nonZeroExitCode = true
264-
executionTimeoutMin = 120
265-
}
266-
267-
features {
268-
feature {
269-
id = "perfmon"
270-
type = "perfmon"
271-
}
272-
}
273-
}

main/resources/teamcity/utils.kt

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* Copyright 2016-2020 JetBrains s.r.o.
3+
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
4+
*/
5+
6+
import jetbrains.buildServer.configs.kotlin.v2018_2.*
7+
8+
const val versionSuffixParameter = "versionSuffix"
9+
const val teamcitySuffixParameter = "teamcitySuffix"
10+
const val releaseVersionParameter = "releaseVersion"
11+
12+
const val bintrayUserName = "<<BINTRAY_USER>>"
13+
const val bintrayToken = "<<BINTRAY_TOKEN>>"
14+
15+
val platforms = Platform.values()
16+
const val jdk = "<<JDK>>"
17+
18+
enum class Platform {
19+
Windows, Linux, MacOS;
20+
}
21+
22+
fun Platform.nativeTaskPrefix(): String = when(this) {
23+
Platform.Windows -> "mingwX64"
24+
Platform.Linux -> "linuxX64"
25+
Platform.MacOS -> "macosX64"
26+
}
27+
fun Platform.buildTypeName(): String = when (this) {
28+
Platform.Windows, Platform.Linux -> name
29+
Platform.MacOS -> "Mac OS X"
30+
}
31+
fun Platform.buildTypeId(): String = buildTypeName().substringBefore(" ")
32+
fun Platform.teamcityAgentName(): String = buildTypeName()
33+
34+
35+
fun Project.buildType(name: String, platform: Platform, configure: BuildType.() -> Unit) = BuildType {
36+
// ID is prepended with Project ID, so don't repeat it here
37+
// ID should conform to identifier rules, so just letters, numbers and underscore
38+
id("${name}_${platform.buildTypeId()}")
39+
// Display name of the build configuration
40+
this.name = "$name (${platform.buildTypeName()})"
41+
42+
requirements {
43+
contains("teamcity.agent.jvm.os.name", platform.teamcityAgentName())
44+
}
45+
46+
params {
47+
// This parameter is needed for macOS agent to be compatible
48+
if (platform == Platform.MacOS) param("env.JDK_17", "")
49+
}
50+
51+
commonConfigure()
52+
configure()
53+
}.also { buildType(it) }
54+
55+
56+
fun BuildType.commonConfigure() {
57+
requirements {
58+
noLessThan("teamcity.agent.hardware.memorySizeMb", "6144")
59+
}
60+
61+
// Allow to fetch build status through API for badges
62+
allowExternalStatus = true
63+
64+
// Configure VCS, by default use the same and only VCS root from which this configuration is fetched
65+
vcs {
66+
root(DslContext.settingsRoot)
67+
showDependenciesChanges = true
68+
checkoutMode = CheckoutMode.ON_AGENT
69+
}
70+
71+
failureConditions {
72+
errorMessage = true
73+
nonZeroExitCode = true
74+
executionTimeoutMin = 120
75+
}
76+
77+
features {
78+
feature {
79+
id = "perfmon"
80+
type = "perfmon"
81+
}
82+
}
83+
}
84+
85+
fun BuildType.dependsOn(build: BuildType, configure: Dependency.() -> Unit) =
86+
apply {
87+
dependencies.dependency(build, configure)
88+
}
89+
90+
fun BuildType.dependsOnSnapshot(build: BuildType, onFailure: FailureAction = FailureAction.FAIL_TO_START, configure: SnapshotDependency.() -> Unit = {}) = apply {
91+
dependencies.dependency(build) {
92+
snapshot {
93+
configure()
94+
onDependencyFailure = onFailure
95+
onDependencyCancel = FailureAction.CANCEL
96+
}
97+
}
98+
}

main/src/kotlinx/team/infra/TeamCity.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ fun Project.configureTeamCityConfigGenerator(teamcity: TeamCityConfiguration) {
3434
it
3535
.replace("<artifactId>resource</artifactId>", "<artifactId>teamcity</artifactId>")
3636
}
37-
copyResource(teamcityDir, "settings.kts") { text ->
37+
copyResource(teamcityDir, "settings.kts")
38+
copyResource(teamcityDir, "utils.kt") { text ->
3839
val bintrayUser = teamcity.bintrayUser
3940
?: throw KotlinInfrastructureException("TeamCity configuration should specify `bintrayUser` parameter")
4041
val bintrayToken = teamcity.bintrayToken

0 commit comments

Comments
 (0)