-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path.gitlab-ci.main.kts
More file actions
executable file
·317 lines (253 loc) · 6.41 KB
/
.gitlab-ci.main.kts
File metadata and controls
executable file
·317 lines (253 loc) · 6.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
#!/usr/bin/env kotlin
/*
* Copyright (c) 2025-2026, OpenSavvy and contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// https://gitlab-ci-kts.opensavvy.dev/news/index.html
@file:DependsOn("dev.opensavvy.gitlab:gitlab-ci-kotlin-jvm:0.7.5")
import opensavvy.gitlab.ci.*
import opensavvy.gitlab.ci.Environment.EnvironmentTier.Development
import opensavvy.gitlab.ci.plugins.Gradle.Companion.gradlew
import opensavvy.gitlab.ci.plugins.Gradle.Companion.useGradle
import opensavvy.gitlab.ci.script.shell
/**
* [OpenSavvy's CI container images](https://gitlab.com/opensavvy/automation/containers/-/releases)
*/
val ciContainers = "0.8.7"
/**
* The URL of the website built by /docs/website.
*/
val siteUrl = "https://ktmongo.opensavvy.dev"
// ***
fun Job.opensavvyImage(name: String) =
image("registry.gitlab.com/opensavvy/automation/containers/$name", ciContainers)
// region GitLab
/**
* Renames all JUnit XML test reports to remove non-latin-1 characters, because GitLab crashes in their presence.
*
* See [GITLAB-580885](https://gitlab.com/gitlab-org/gitlab/-/issues/580885).
*/
fun Job.stripUnicodeTestReports() {
afterScript {
// language="Shell Script"
shell($$"""
find . -path '*/build/test-results/*/TEST-*.xml' -print0 |
grep -zP '[^\x00-\x{00FF}]' |
while IFS= read -r -d '' f; do
d="$(dirname "$f")"
b="$(basename "$f")"
nb=$(printf '%s' "$b" | LC_ALL=C sed -E \
-e 's/[\xc4-\xdf][\x80-\xbf]/-/g' \
-e 's/[\xe0-\xef][\x80-\xbf]{2}/-/g' \
-e 's/[\xf0-\xf4][\x80-\xbf]{3}/-/g')
mv -- "$f" "$d/$nb"
done
""".trimIndent())
}
}
// endregion
// region Kotlin Multiplatform
fun Job.jvm() {
useGradle()
opensavvyImage("java")
}
fun Job.jsBrowser() {
useGradle()
opensavvyImage("chromium")
stripUnicodeTestReports()
}
fun Job.jsNode() {
useGradle()
opensavvyImage("nodejs")
stripUnicodeTestReports()
}
fun Job.nativeLinuxX64() {
useGradle()
opensavvyImage("java")
stripUnicodeTestReports()
}
fun Job.nativeIosArm64() {
useGradle()
image("macos-15-xcode-16")
beforeScript {
shell("xcodebuild -downloadPlatform iOS")
}
tag("saas-macos-medium-m1")
retry(1) {
onExitCode(1)
}
}
// endregion
val supportedMongoDB = listOf("7.0.31")
gitlabCi {
val build by stage()
val test by stage()
val deploy by stage()
// region Tests
for (mongo in supportedMongoDB) {
val checkJvm = job(name = "checkJvm[Mongo $mongo]", stage = test) {
jvm()
service("mongo", mongo) {
alias = "mongo"
}
script {
gradlew.tasks(
"check :koverLog :koverHtmlReport koverVerify --rerun",
"-x jsBrowserTest",
"-x jsNodeTest",
"-x wasmJsBrowserTest",
"-x wasmJsNodeTest",
"-x wasmWasiNodeTest",
"-x linuxX64Test",
"-x mingwX64Test",
"-x macosX64Test",
"-x macosArm64Test",
"-x iosX64Test",
"-x iosSimulatorArm64Test",
"-x watchosX64Test",
"-x tvosX64Test",
$$"-PappVersion=$project_version",
)
}
afterScript {
shell("mkdir -p jvm-cover-report")
shell("mv build/reports/kover/html/* jvm-cover-report")
}
artifacts {
include("jvm-cover-report")
exposeAs("JVM code coverage")
}
interruptible(true)
}
}
val checkJsBrowser by job(stage = test) {
jsBrowser()
script {
gradlew.tasks(
"jsBrowserTest wasmJsBrowserTest",
$$"-PappVersion=$project_version",
)
}
interruptible(true)
}
val checkJsNode by job(stage = test) {
jsNode()
script {
gradlew.tasks(
"jsNodeTest wasmJsNodeTest wasmWasiNodeTest",
$$"-PappVersion=$project_version",
)
}
retry(2)
interruptible(true)
}
val checkLinuxX64 by job(stage = test) {
nativeLinuxX64()
script {
gradlew.tasks(
"linuxX64Test mingwX64Test",
$$"-PappVersion=$project_version",
)
}
interruptible(true)
}
val checkIosArm64 by job(stage = test) {
nativeIosArm64()
script {
gradlew.tasks(
"iosSimulatorArm64Test watchosSimulatorArm64Test",
$$"-PappVersion=$project_version",
)
}
interruptible(true)
}
// endregion
// region Documentation
val mkdocs by job(stage = build) {
opensavvyImage("mkdocs")
variable("GIT_DEPTH", "0")
beforeScript {
shell("./docs/website/verify-marker.sh")
shell($$"./gradlew docs:website:embedDokkaIntoMkDocs -PappVersion=$project_version")
shell("cd docs/website")
shell("ls")
shell($$"""echo "repo_url: $CI_PROJECT_URL">>mkdocs.yml""")
shell($$"""echo "repo_name: $CI_PROJECT_TITLE">>mkdocs.yml""")
shell($$"""echo "site_url: $$siteUrl">>mkdocs.yml""")
}
script {
shell("./generate-news.sh")
shell("mkdocs build --site-dir ../../docs-website")
}
afterScript {
shell("""echo "URL=$(.gitlab/ci/review-url.sh docs-website/index.html)">>docs.env""")
}
artifacts {
include("docs-website")
dotenv("docs.env")
}
environment {
name("review/${Variable.Commit.Ref.slug}/docs")
url($$"$URL")
tier(Development)
}
interruptible(true)
}
val dokka by job(stage = build) {
jvm()
script {
gradlew.tasks(
":dokkaGeneratePublicationHtml",
$$"-PappVersion=$project_version"
)
}
afterScript {
shell("mkdir -p api-docs")
shell("mv build/dokka/html/* api-docs")
shell("""echo "URL=$(.gitlab/ci/review-url.sh api-docs/index.html)">>dokka.env""")
}
artifacts {
include("api-docs")
dotenv("dokka.env")
}
environment {
name("review/${Variable.Commit.Ref.slug}/api-docs")
url($$"$URL")
tier(Development)
}
interruptible(true)
}
if (Value.isTag) {
job("pages", stage = deploy) {
image("alpine", "latest")
dependsOn(mkdocs, artifacts = true)
dependsOn(dokka, artifacts = true)
script {
shell("mkdir -p public")
shell("mv -T docs-website public")
shell("mv api-docs public")
}
artifacts {
include("public")
}
interruptible(false)
}
}
// endregion
}.println()
println("""
workflow:
rules:
- if: ${'$'}CI_PIPELINE_SOURCE == "parent_pipeline"
""".trimIndent())