1
+ package common
2
+
3
+ import common.extensions.scriptGenerateSitemap
4
+ import common.extensions.scriptNoRobots
5
+ import jetbrains.buildServer.configs.kotlin.BuildType
6
+ import jetbrains.buildServer.configs.kotlin.Project
7
+ import jetbrains.buildServer.configs.kotlin.RelativeId
8
+ import templates.SCRIPT_PATH
9
+ import templates.TemplateSearchIndex
10
+ import vcsRoots.KotlinLangOrg
11
+
12
+ private fun String.camelCase (delim : String = "-", join : String = "") =
13
+ this .split(delim).joinToString(join) { it.replaceFirstChar { char -> char.uppercase() } }
14
+
15
+ typealias ProjectReferenceBuilder = () -> BuildType
16
+
17
+ open class ReferenceProject (val urlPart : String , val projectTitle : String = urlPart) {
18
+ init {
19
+ if (urlPart.isBlank()) throw IllegalArgumentException (" urlPart cannot be blank" )
20
+ }
21
+
22
+ val projectName = projectTitle.camelCase(join = " " )
23
+ val projectPrefix = urlPart.camelCase()
24
+
25
+ val project = Project {
26
+ id = RelativeId (projectPrefix)
27
+ name = projectName
28
+ description = " Project for https://kotlinlang.org/api/$urlPart /"
29
+
30
+ params {
31
+ param(" env.ALGOLIA_INDEX_NAME" , urlPart)
32
+ param(" env.API_REFERENCE_NAME" , projectTitle)
33
+ }
34
+ }
35
+
36
+ val versions = mutableListOf<Pair <BuildType , String >>()
37
+
38
+ val currentVersion: BuildType
39
+ get() = this .versions.lastOrNull()?.first
40
+ ? : throw IllegalStateException (" Current version is not set for $projectName " )
41
+
42
+ fun addReference (version : String , buildReference : ProjectReferenceBuilder ) {
43
+ versions.add(buildReference() to version)
44
+ }
45
+
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"
51
+
52
+ vcs {
53
+ root(KotlinLangOrg , " ${SCRIPT_PATH } /" )
54
+ }
55
+
56
+ steps {
57
+ step(scriptNoRobots(workingDir))
58
+ step(scriptGenerateSitemap(workingDir))
59
+ }
60
+
61
+ dependencies {
62
+ dependency(currentVersion) {
63
+ snapshot {}
64
+ artifacts {
65
+ artifactRules = " pages.zip!** => $workingDir "
66
+ cleanDestination = true
67
+ }
68
+ }
69
+ }
70
+ }
71
+
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
+ }
80
+
81
+ dependencies {
82
+ dependency(pages) {
83
+ snapshot {}
84
+ artifacts {
85
+ artifactRules = " pages.zip!** => $workingDir "
86
+ cleanDestination = true
87
+ }
88
+ }
89
+ }
90
+ }
91
+
92
+ fun build () {
93
+ val workingDir = " dist/api/$urlPart "
94
+ val pages = pagesSearchType(workingDir)
95
+
96
+ project.apply {
97
+ buildType(pages)
98
+ buildType(searchBuildType(workingDir, pages))
99
+ }
100
+
101
+ currentVersion.dependencies {
102
+ for ((previousVersion, version) in versions) {
103
+ if (previousVersion == currentVersion) continue
104
+ artifacts(previousVersion) {
105
+ buildRule = tag(" release" )
106
+ artifactRules = " pages.zip!** => %OLD_VERSIONS_DIR%/$version /"
107
+ cleanDestination = true
108
+ }
109
+ }
110
+ }
111
+ }
112
+ }
0 commit comments