Skip to content

Commit 98fafd9

Browse files
committed
chore(ci/api): compose core api - add search steps
1 parent fa3e572 commit 98fafd9

File tree

2 files changed

+48
-42
lines changed

2 files changed

+48
-42
lines changed

.teamcity/common/ReferenceProject.kt

Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import jetbrains.buildServer.configs.kotlin.BuildType
66
import jetbrains.buildServer.configs.kotlin.Project
77
import jetbrains.buildServer.configs.kotlin.RelativeId
88
import templates.SCRIPT_PATH
9+
import templates.TemplateSearchIndex
910
import vcsRoots.KotlinLangOrg
1011

1112
private fun String.camelCase(delim: String = "-", join: String = "") =
@@ -19,8 +20,8 @@ open class ReferenceProject(val urlPart: String, val projectTitle: String = urlP
1920
}
2021

2122
val projectName = projectTitle.camelCase(join = " ")
22-
2323
val projectPrefix = urlPart.camelCase()
24+
2425
val project = Project {
2526
id = RelativeId(projectPrefix)
2627
name = projectName
@@ -32,64 +33,69 @@ open class ReferenceProject(val urlPart: String, val projectTitle: String = urlP
3233
}
3334
}
3435

35-
protected val versions = mutableListOf<Pair<BuildType, String>>()
36+
val versions = mutableListOf<Pair<BuildType, String>>()
3637

37-
fun getCurrentVersion(): Pair<BuildType, String>? = this.versions.lastOrNull()
38+
val currentVersion: BuildType
39+
get() = this.versions.lastOrNull()?.first
40+
?: throw IllegalStateException("Current version is not set for $projectName")
3841

3942
fun addReference(version: String, buildReference: ProjectReferenceBuilder) {
4043
versions.add(buildReference() to version)
4144
}
4245

43-
fun build() {
44-
val (currentVersion) = getCurrentVersion()
45-
?: throw IllegalStateException("Current version is not set for $projectName")
46-
47-
val workingDir = "dist/api/$urlPart"
46+
fun pagesSearchType(workingDir: String) = BuildType {
47+
id = RelativeId("${projectPrefix}_Latest")
48+
name = "API Pages"
49+
description = "The latest stable version for $projectName"
50+
artifactRules = "$workingDir/** => pages.zip"
4851

49-
val pages = BuildType {
50-
id = RelativeId("${projectPrefix}_Latest")
51-
name = "API Pages"
52-
description = "The latest stable version for $projectName"
52+
vcs {
53+
root(KotlinLangOrg, "${SCRIPT_PATH}/")
54+
}
5355

54-
artifactRules = "$workingDir/** => pages.zip"
56+
steps {
57+
step(scriptNoRobots(workingDir))
58+
step(scriptGenerateSitemap(workingDir))
59+
}
5560

56-
vcs {
57-
root(KotlinLangOrg, "${SCRIPT_PATH}/")
61+
dependencies {
62+
dependency(currentVersion) {
63+
snapshot {}
64+
artifacts {
65+
artifactRules = "pages.zip!** => $workingDir"
66+
cleanDestination = true
67+
}
5868
}
69+
}
70+
}
5971

60-
steps {
61-
step(scriptNoRobots(workingDir))
62-
step(scriptGenerateSitemap(workingDir))
63-
}
72+
fun searchBuildType(workingDir: String, pages: BuildType) = TemplateSearchIndex {
73+
id = RelativeId("${projectPrefix}_Search")
74+
name = "API Search Index"
75+
description = "Build search index for $projectName"
76+
77+
params {
78+
param("env.ALGOLIA_INDEX_NAME", urlPart)
79+
}
6480

65-
dependencies {
66-
dependency(currentVersion) {
67-
snapshot {}
68-
artifacts {
69-
artifactRules = "pages.zip!** => $workingDir"
70-
cleanDestination = true
71-
}
81+
dependencies {
82+
dependency(pages) {
83+
snapshot {}
84+
artifacts {
85+
artifactRules = "pages.zip!** => $workingDir"
86+
cleanDestination = true
7287
}
7388
}
7489
}
90+
}
91+
92+
fun build() {
93+
val workingDir = "dist/api/$urlPart"
94+
val pages = pagesSearchType(workingDir)
7595

7696
project.apply {
7797
buildType(pages)
78-
buildType {
79-
id = RelativeId("${projectPrefix}_Search")
80-
name = "API Search Index"
81-
description = "Build search index for $projectName"
82-
83-
dependencies {
84-
dependency(pages) {
85-
snapshot {}
86-
artifacts {
87-
artifactRules = "pages.zip!** => $workingDir"
88-
cleanDestination = true
89-
}
90-
}
91-
}
92-
}
98+
buildType(searchBuildType(workingDir, pages))
9399
}
94100

95101
currentVersion.dependencies {

.teamcity/templates/TemplateSearchIndex.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fun scriptDistAnalyze(block: ScriptBuildStep.() -> Unit) = ScriptBuildStep {
2424
dockerPull = true
2525
}.apply(block)
2626

27-
abstract class TemplateSearchIndex(init: BuildType.() -> Unit) : BuildType({
27+
open class TemplateSearchIndex(init: BuildType.() -> Unit) : BuildType({
2828
artifactRules = """
2929
reports/** => reports.zip
3030
""".trimIndent()

0 commit comments

Comments
 (0)