forked from dosier/koog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
293 lines (258 loc) · 10.9 KB
/
build.gradle.kts
File metadata and controls
293 lines (258 loc) · 10.9 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
import ai.koog.gradle.fixups.DisableDistTasks.disableDistTasks
import ai.koog.gradle.plugins.CheckSplitPackagesExtension
import ai.koog.gradle.plugins.CheckSplitPackagesPlugin
import okhttp3.MultipartBody
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.RequestBody.Companion.asRequestBody
import org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrLink
import org.jetbrains.kotlin.gradle.tasks.BaseKotlinCompile
import org.jlleitschuh.gradle.ktlint.KtlintExtension
import java.time.Clock
import java.util.Base64
group = "ai.koog"
version = run {
// our version follows the semver specification
val main = "0.4.1"
val feat = run {
val releaseBuild = !System.getenv("BRANCH_KOOG_IS_RELEASING_FROM").isNullOrBlank()
val nightlyBuild = System.getenv("IS_NIGHTLY_BUILD")?.toBoolean() ?: false
val branch = System.getenv("BRANCH_KOOG_IS_RELEASING_FROM")
val customVersion = System.getenv("CE_CUSTOM_VERSION")
val tcCounter = System.getenv("TC_BUILD_COUNTER")
if (nightlyBuild) {
if (branch != "develop") {
throw GradleException("Nightly builds are allowed only from the develop branch")
}
val date = Clock.systemUTC().instant().atZone(java.time.ZoneId.of("CET"))
.format(java.time.format.DateTimeFormatter.ISO_LOCAL_DATE)
if (!customVersion.isNullOrBlank()) {
"-$branch-$date-$customVersion"
} else {
"-$branch-$date"
}
} else if (releaseBuild) {
when (branch) {
"main" -> {
if (customVersion.isNullOrBlank()) {
""
} else {
throw GradleException("Custom version is not allowed during release from the main branch")
}
}
"develop" -> {
if (!customVersion.isNullOrBlank()) {
throw GradleException("Custom version is not allowed during release from the develop branch")
} else if (tcCounter.isNullOrBlank()) {
throw GradleException("TC_BUILD_COUNTER is required during release from the develop branch")
} else {
".$tcCounter"
}
}
else -> {
if (!customVersion.isNullOrBlank()) {
"-feat-$customVersion"
} else {
throw GradleException("Custom version is required during release from a feature branch")
}
}
}
} else {
// do not care
""
}
}
"$main$feat"
}
buildscript {
dependencies {
classpath("com.squareup.okhttp3:okhttp:4.12.0")
}
}
plugins {
id("ai.kotlin.dokka")
alias(libs.plugins.kotlinx.kover)
alias(libs.plugins.ktlint)
}
allprojects {
repositories {
mavenCentral()
}
}
disableDistTasks()
// Apply Kover and ktlint to all subprojects
subprojects {
apply(plugin = "org.jetbrains.kotlinx.kover")
apply(plugin = "org.jlleitschuh.gradle.ktlint")
}
subprojects {
extensions.configure<KtlintExtension> {
outputToConsole = true
coloredOutput = true
}
tasks.withType<Test> {
testLogging {
showStandardStreams = true
showExceptions = true
exceptionFormat = FULL
}
environment.putAll(
mapOf(
"ANTHROPIC_API_TEST_KEY" to System.getenv("ANTHROPIC_API_TEST_KEY"),
"OPEN_AI_API_TEST_KEY" to System.getenv("OPEN_AI_API_TEST_KEY"),
"GEMINI_API_TEST_KEY" to System.getenv("GEMINI_API_TEST_KEY"),
"OPEN_ROUTER_API_TEST_KEY" to System.getenv("OPEN_ROUTER_API_TEST_KEY"),
"AWS_SECRET_ACCESS_KEY" to System.getenv("AWS_SECRET_ACCESS_KEY"),
"AWS_ACCESS_KEY_ID" to System.getenv("AWS_ACCESS_KEY_ID"),
"DEEPSEEK_API_TEST_KEY" to System.getenv("DEEPSEEK_API_TEST_KEY"),
)
)
}
}
tasks.register("reportProjectVersionToTeamCity") {
doLast {
println("##teamcity[buildNumber '${project.version}']")
}
}
tasks {
val packSonatypeCentralBundle by registering(Zip::class) {
group = "publishing"
subprojects {
dependsOn(tasks.withType<PublishToMavenRepository>())
}
from(rootProject.layout.buildDirectory.dir("artifacts/maven"))
archiveFileName.set("bundle.zip")
destinationDirectory.set(layout.buildDirectory)
}
@Suppress("unused")
val publishMavenToCentralPortal by registering {
group = "publishing"
dependsOn(packSonatypeCentralBundle)
doLast {
val uriBase = "https://central.sonatype.com/api/v1/publisher/upload"
val mainBranch = System.getenv("BRANCH_KOOG_IS_RELEASING_FROM") == "main"
val publishingType = if (mainBranch) {
println("Publishing from the main branch, so publishing as AUTOMATIC.")
"AUTOMATIC"
} else {
println("Publishing from the non-main branch, so publishing as USER_MANAGED.")
"USER_MANAGED" // do not publish releases from non-main branches without approval
}
val deploymentName = "${project.name}-$version"
val uri = "$uriBase?name=$deploymentName&publishingType=$publishingType"
val userName = System.getenv("CE_MVN_CLIENT_USERNAME") as String
val token = System.getenv("CE_MVN_CLIENT_PASSWORD") as String
val base64Auth = Base64.getEncoder().encode("$userName:$token".toByteArray()).toString(Charsets.UTF_8)
val bundleFile = packSonatypeCentralBundle.get().archiveFile.get().asFile
println("Sending request to $uri...")
val client = OkHttpClient()
val request = Request.Builder()
.url(uri)
.header("Authorization", "Bearer $base64Auth")
.post(
MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("bundle", bundleFile.name, bundleFile.asRequestBody())
.build()
)
.build()
client.newCall(request).execute().use { response ->
val statusCode = response.code
println("Upload status code: $statusCode")
println("Upload result: ${response.body!!.string()}")
if (statusCode != 201) {
error("Upload error to Central repository. Status code $statusCode.")
}
}
}
}
}
dependencies {
dokka(project(":agents:agents-core"))
dokka(project(":agents:agents-features:agents-features-debugger"))
dokka(project(":agents:agents-features:agents-features-event-handler"))
dokka(project(":agents:agents-features:agents-features-memory"))
dokka(project(":agents:agents-features:agents-features-opentelemetry"))
dokka(project(":agents:agents-features:agents-features-snapshot"))
dokka(project(":agents:agents-features:agents-features-trace"))
dokka(project(":agents:agents-features:agents-features-tokenizer"))
dokka(project(":agents:agents-mcp"))
dokka(project(":agents:agents-test"))
dokka(project(":agents:agents-tools"))
dokka(project(":agents:agents-utils"))
dokka(project(":agents:agents-ext"))
dokka(project(":embeddings:embeddings-base"))
dokka(project(":embeddings:embeddings-llm"))
dokka(project(":prompt:prompt-cache:prompt-cache-files"))
dokka(project(":prompt:prompt-cache:prompt-cache-model"))
dokka(project(":prompt:prompt-cache:prompt-cache-redis"))
dokka(project(":prompt:prompt-executor:prompt-executor-cached"))
dokka(project(":prompt:prompt-executor:prompt-executor-clients"))
dokka(project(":prompt:prompt-executor:prompt-executor-clients:prompt-executor-anthropic-client"))
dokka(project(":prompt:prompt-executor:prompt-executor-clients:prompt-executor-bedrock-client"))
dokka(project(":prompt:prompt-executor:prompt-executor-clients:prompt-executor-deepseek-client"))
dokka(project(":prompt:prompt-executor:prompt-executor-clients:prompt-executor-google-client"))
dokka(project(":prompt:prompt-executor:prompt-executor-clients:prompt-executor-ollama-client"))
dokka(project(":prompt:prompt-executor:prompt-executor-clients:prompt-executor-openai-client"))
dokka(project(":prompt:prompt-executor:prompt-executor-clients:prompt-executor-openai-client-base"))
dokka(project(":prompt:prompt-executor:prompt-executor-clients:prompt-executor-openrouter-client"))
dokka(project(":prompt:prompt-executor:prompt-executor-llms"))
dokka(project(":prompt:prompt-executor:prompt-executor-llms-all"))
dokka(project(":prompt:prompt-executor:prompt-executor-model"))
dokka(project(":prompt:prompt-llm"))
dokka(project(":prompt:prompt-markdown"))
dokka(project(":prompt:prompt-model"))
dokka(project(":prompt:prompt-structure"))
dokka(project(":prompt:prompt-tokenizer"))
dokka(project(":prompt:prompt-xml"))
dokka(project(":koog-spring-boot-starter"))
dokka(project(":koog-ktor"))
dokka(project(":rag:rag-base"))
dokka(project(":rag:vector-storage"))
}
kover {
val excludedProjects = setOf(
":integration-tests",
":examples",
":buildSrc",
":docs",
)
merge {
subprojects {
it.path !in excludedProjects
}
}
reports {
total {
binary {
file = file(".qodana/code-coverage/kover.ic")
}
}
}
}
fun Project.getKotlinCompileTasks(sourceSetName: String): List<Task> {
return this.tasks
.withType<BaseKotlinCompile>()
// Filtering JS linking tasks, additional overhead and not needed for verification. Not used by assemble task.
.filter { it !is KotlinJsIrLink }
.filter { it.sourceSetName.get() == sourceSetName }
}
tasks.register("compileKotlinAll") {
description = """
Compiles all main Kotlin sources in all subprojects. Useful to verify that everything compiles for all supported platforms.
""".trimIndent()
dependsOn(subprojects.map { it.getKotlinCompileTasks("main") })
}
tasks.register("compileTestKotlinAll") {
description = """
Compiles all test Kotlin sources in all subprojects. Useful to verify that everything compiles for all supported platforms.
""".trimIndent()
dependsOn(subprojects.map { it.getKotlinCompileTasks("test") })
}
apply<CheckSplitPackagesPlugin>()
extensions.getByType<CheckSplitPackagesExtension>().apply {
includeProjects = setOf(":agents:", ":embeddings:", ":prompt:", ":koog-spring-boot-starter", ":rag:")
failOnError = true
includePackages = setOf("ai.koog")
}