Skip to content

Commit 13d057c

Browse files
author
Abduqodiri Qurbonzoda
committed
Extract utils to separate file
1 parent e093db0 commit 13d057c

File tree

3 files changed

+114
-94
lines changed

3 files changed

+114
-94
lines changed

.teamcity/Benchmarks.kt

Lines changed: 12 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ import jetbrains.buildServer.configs.kotlin.v2018_2.*
77
import jetbrains.buildServer.configs.kotlin.v2018_2.buildSteps.gradle
88
import java.lang.IllegalArgumentException
99

10-
val platforms = listOf("Windows", "Linux", "Mac OS X")
11-
val jdk = "JDK_18_x64"
12-
1310
fun Project.additionalConfiguration() {
1411
subProject(benchmarksProject())
1512
}
@@ -18,10 +15,14 @@ fun benchmarksProject() = Project {
1815
this.id("Benchmarks")
1916
this.name = "Benchmarks"
2017

18+
params {
19+
param("teamcity.ui.settings.readOnly", "true")
20+
}
21+
2122
val benchmarkAll = benchmarkAll()
2223
val benchmarks = listOf(
23-
benchmark("js", "Linux"),
24-
benchmark("jvm", "Linux"),
24+
benchmark("js", Platform.Linux),
25+
benchmark("jvm", Platform.Linux),
2526
*platforms.map { benchmark("native", it) }.toTypedArray()
2627
)
2728

@@ -45,7 +46,7 @@ fun Project.benchmarkAll() = BuildType {
4546
commonConfigure()
4647
}.also { buildType(it) }
4748

48-
fun Project.benchmark(target: String, platform: String) = platform(platform, "${target}Benchmark") {
49+
fun Project.benchmark(target: String, platform: Platform) = buildType("${target}Benchmark", platform) {
4950
steps {
5051
gradle {
5152
name = "Benchmark"
@@ -68,83 +69,13 @@ fun Project.benchmark(target: String, platform: String) = platform(platform, "${
6869
}
6970
}
7071

71-
fun benchmarkTask(target: String, platform: String): String = when(target) {
72+
fun benchmarkTask(target: String, platform: Platform): String = when(target) {
7273
"js", "jvm" -> "${target}FastBenchmark"
73-
"native" -> when(platform) {
74-
"Mac OS X" -> "macosX64FastBenchmark"
75-
"Linux" -> "linuxX64FastBenchmark"
76-
"Windows" -> "mingwX64FastBenchmark"
77-
else -> throw IllegalArgumentException("Unknown platform: $platform")
78-
}
74+
"native" -> "${platform.nativeTaskPrefix()}FastBenchmark"
7975
else -> throw IllegalArgumentException("Unknown target: $target")
8076
}
8177

82-
fun Requirements.benchmarkAgentInstanceTypeRequirement(platform: String) {
83-
if (platform == "Linux") equals("system.ec2.instance-type", "m5d.xlarge")
84-
else if (platform == "Windows") equals("system.ec2.instance-type", "m5.xlarge")
85-
}
86-
87-
fun BuildType.dependsOn(build: BuildType, configure: Dependency.() -> Unit) =
88-
apply {
89-
dependencies.dependency(build, configure)
90-
}
91-
92-
fun BuildType.dependsOnSnapshot(build: BuildType, onFailure: FailureAction = FailureAction.FAIL_TO_START, configure: SnapshotDependency.() -> Unit = {}) = apply {
93-
dependencies.dependency(build) {
94-
snapshot {
95-
configure()
96-
onDependencyFailure = onFailure
97-
onDependencyCancel = FailureAction.CANCEL
98-
}
99-
}
100-
}
101-
102-
fun Project.platform(platform: String, name: String, configure: BuildType.() -> Unit) = BuildType {
103-
// ID is prepended with Project ID, so don't repeat it here
104-
// ID should conform to identifier rules, so just letters, numbers and underscore
105-
id("${name}_${platform.substringBefore(" ")}")
106-
// Display name of the build configuration
107-
this.name = "$name ($platform)"
108-
109-
requirements {
110-
contains("teamcity.agent.jvm.os.name", platform)
111-
}
112-
113-
params {
114-
// This parameter is needed for macOS agent to be compatible
115-
if (platform.startsWith("Mac")) param("env.JDK_17", "")
116-
}
117-
118-
commonConfigure()
119-
configure()
120-
}.also { buildType(it) }
121-
122-
123-
fun BuildType.commonConfigure() {
124-
requirements {
125-
noLessThan("teamcity.agent.hardware.memorySizeMb", "6144")
126-
}
127-
128-
// Allow to fetch build status through API for badges
129-
allowExternalStatus = true
130-
131-
// Configure VCS, by default use the same and only VCS root from which this configuration is fetched
132-
vcs {
133-
root(DslContext.settingsRoot)
134-
showDependenciesChanges = true
135-
checkoutMode = CheckoutMode.ON_AGENT
136-
}
137-
138-
failureConditions {
139-
errorMessage = true
140-
nonZeroExitCode = true
141-
executionTimeoutMin = 120
142-
}
143-
144-
features {
145-
feature {
146-
id = "perfmon"
147-
type = "perfmon"
148-
}
149-
}
78+
fun Requirements.benchmarkAgentInstanceTypeRequirement(platform: Platform) {
79+
if (platform == Platform.Linux) equals("system.ec2.instance-type", "m5d.xlarge")
80+
else if (platform == Platform.Windows) equals("system.ec2.instance-type", "m5.xlarge")
15081
}

.teamcity/settings.kts

Lines changed: 4 additions & 13 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 = "%env.BINTRAY_USER%"
33-
val bintrayToken = "%env.BINTRAY_API_KEY%"
34-
35-
val platforms = listOf("Windows", "Linux", "Mac OS X")
36-
val jdk = "JDK_18_x64"
3728

3829
project {
3930
// Disable editing of project and build settings from the UI to avoid issues with TeamCity
@@ -112,7 +103,7 @@ fun Project.buildAll(versionBuild: BuildType) = BuildType {
112103
commonConfigure()
113104
}.also { buildType(it) }
114105

115-
fun Project.build(platform: String, versionBuild: BuildType) = platform(platform, "Build") {
106+
fun Project.build(platform: Platform, versionBuild: BuildType) = buildType("Build", platform) {
116107

117108
dependsOnSnapshot(versionBuild)
118109

@@ -123,7 +114,7 @@ fun Project.build(platform: String, versionBuild: BuildType) = platform(platform
123114

124115
steps {
125116
gradle {
126-
name = "Build and Test $platform Binaries"
117+
name = "Build and Test ${platform.buildTypeName()} Binaries"
127118
jdkHome = "%env.$jdk%"
128119
jvmArgs = "-Xmx1g"
129120
tasks = "clean publishToBuildLocal check"
@@ -182,7 +173,7 @@ fun Project.deployPublish(configureBuild: BuildType) = BuildType {
182173
}.also { buildType(it) }
183174

184175

185-
fun Project.deploy(platform: String, configureBuild: BuildType) = platform(platform, "Deploy") {
176+
fun Project.deploy(platform: Platform, configureBuild: BuildType) = buildType("Deploy", platform) {
186177
type = BuildTypeSettings.Type.DEPLOYMENT
187178
enablePersonalBuilds = false
188179
maxRunningBuilds = 1
@@ -199,7 +190,7 @@ fun Project.deploy(platform: String, configureBuild: BuildType) = platform(platf
199190

200191
steps {
201192
gradle {
202-
name = "Deploy $platform Binaries"
193+
name = "Deploy ${platform.buildTypeName()} Binaries"
203194
jdkHome = "%env.$jdk%"
204195
jvmArgs = "-Xmx1g"
205196
gradleParams = "--info --stacktrace -P$versionSuffixParameter=%$versionSuffixParameter% -P$releaseVersionParameter=%$releaseVersionParameter% -PbintrayApiKey=%bintray-key% -PbintrayUser=%bintray-user%"

.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 = "%env.BINTRAY_USER%"
13+
const val bintrayToken = "%env.BINTRAY_API_KEY%"
14+
15+
val platforms = Platform.values()
16+
const val jdk = "JDK_18_x64"
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+
}

0 commit comments

Comments
 (0)