-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
302 lines (255 loc) · 10.1 KB
/
build.gradle.kts
File metadata and controls
302 lines (255 loc) · 10.1 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
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
import java.net.URI
import java.net.http.HttpClient
import java.net.http.HttpRequest
import java.net.http.HttpResponse
import java.util.Base64
plugins {
`maven-publish`
signing
kotlin("multiplatform") version "2.2.0" apply false
id("io.github.gradle-nexus.publish-plugin") version "1.1.0"
id("org.jetbrains.dokka") version "1.9.20"
}
allprojects {
group = "io.exoquery"
version = "1.0.0"
//val varintName = project.name
apply {
plugin("org.jetbrains.dokka")
plugin("maven-publish")
plugin("signing")
}
repositories {
mavenCentral()
maven(url = "https://plugins.gradle.org/m2/")
maven(url = "https://jitpack.io")
}
val dokkaHtml by tasks.getting(org.jetbrains.dokka.gradle.DokkaTask::class)
val javadocJar: TaskProvider<Jar> by tasks.registering(Jar::class) {
dependsOn(dokkaHtml)
archiveClassifier.set("javadoc")
from(dokkaHtml.outputDirectory)
}
publishing {
val user = System.getenv("SONATYPE_USERNAME")
val pass = System.getenv("SONATYPE_PASSWORD")
repositories {
maven {
name = "Oss"
setUrl {
"https://ossrh-staging-api.central.sonatype.com/service/local/staging/deploy/maven2/"
}
credentials {
username = user
password = pass
}
}
maven {
name = "Snapshot"
setUrl { "https://central.sonatype.com/repository/maven-snapshots/" }
credentials {
username = user
password = pass
}
}
}
publications.withType<MavenPublication> {
artifact(javadocJar)
pom {
name.set("decomat")
description.set("DecoMat - Deconstructive Pattern Matching for Kotlin")
url.set("https://github.com/exoquery/decomat")
licenses {
license {
name.set("The Apache Software License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
distribution.set("repo")
}
}
developers {
developer {
name.set("Alexander Ioffe")
email.set("deusaquilus@gmail.com")
organization.set("github")
organizationUrl.set("http://www.github.com")
}
}
scm {
url.set("https://github.com/exoquery/decomat/tree/main")
connection.set("scm:git:git://github.com/ExoQuery/DecoMat.git")
developerConnection.set("scm:git:ssh://github.com:ExoQuery/DecoMat.git")
}
}
}
}
val isCI = project.hasProperty("isCI")
val isLocal = !isCI
val noSign = project.hasProperty("nosign")
val doNotSign = isLocal || noSign
signing {
// Sign if we're not doing a local build and we haven't specifically disabled it
if (!doNotSign) {
val signingKeyRaw = System.getenv("NEW_SIGNING_KEY_ID_BASE64")
if (signingKeyRaw == null) error("ERROR: No Signing Key Found")
// Seems like the right way was to have newlines after all the exported (ascii armored) lines
// and you can put them into the github-var with newlines but if you
// include the "-----BEGIN PGP PRIVATE KEY BLOCK-----" and "-----END PGP PRIVATE KEY BLOCK-----"
// parts with that then errors happen. Have a look at https://github.com/gradle/gradle/issues/15718 for more detail
// Ultimately however `iurysza` is only partially correct and they key-itself does not need to be escaped
// and can be put into a github-var with newlines.
val signingKey =
"-----BEGIN PGP PRIVATE KEY BLOCK-----\n\n${signingKeyRaw}\n-----END PGP PRIVATE KEY BLOCK-----"
useInMemoryPgpKeys(
System.getenv("NEW_SIGNING_KEY_ID_BASE64_ID"),
signingKey,
System.getenv("NEW_SIGNING_KEY_ID_BASE64_PASS")
)
sign(publishing.publications)
}
}
// Fix for Kotlin issue: https://youtrack.jetbrains.com/issue/KT-61313
tasks.withType<Sign>().configureEach {
val pubName = name.removePrefix("sign").removeSuffix("Publication")
// These tasks only exist for native targets, hence findByName() to avoid trying to find them for other targets
// Task ':linkDebugTest<platform>' uses this output of task ':sign<platform>Publication' without declaring an explicit or implicit dependency
tasks.findByName("linkDebugTest$pubName")?.let {
mustRunAfter(it)
}
// Task ':compileTestKotlin<platform>' uses this output of task ':sign<platform>Publication' without declaring an explicit or implicit dependency
tasks.findByName("compileTestKotlin$pubName")?.let {
mustRunAfter(it)
}
}
// Was having odd issues happening in CI releases like this:
// e.g. Task ':pprint-kotlin-core:publish<AndroidNativeArm32>PublicationToOssRepository' uses this output of task ':pprint-kotlin-core:sign<AndroidNativeArm64>Publication' without declaring an explicit or implicit dependency.
// I tried a few things that caused other issues. Ultimately the working solution I got from here:
// https://github.com/gradle/gradle/issues/26091#issuecomment-1722947958
tasks.withType<AbstractPublishToMaven>().configureEach {
val signingTasks = tasks.withType<Sign>()
mustRunAfter(signingTasks)
// Also, do not publish the decomat-examples project
onlyIf {
!this.project.name.contains("decomat-examples")
}
}
}
tasks.register("publishLinuxLocal") {
dependsOn(
":${Release.Project.`decomat-core`}:publishToMavenLocal",
":${Release.Project.`decomat-ksp`}:publishToMavenLocal"
)
}
object Release {
object Project {
val `decomat-core` = "decomat-core"
val `decomat-ksp` = "decomat-ksp"
}
val macBuildCommands =
listOf(
"iosX64",
"iosArm64",
"tvosX64",
"tvosArm64",
"watchosX64",
"watchosArm32",
"watchosArm64",
"macosX64",
"macosArm64",
"iosSimulatorArm64"
).map { "publish${it.capitalize()}PublicationToOssRepository" }
val windowsBuildCommands =
listOf(
"mingwX64"
).map { "publish${it.capitalize()}PublicationToOssRepository" }
fun String.capitalize() = this.replaceFirstChar { it.uppercase() }
}
data class Repo(
val key: String,
val state: String,
val description: String? = null,
val portal_deployment_id: String? = null
) {
val encodedKey get() = java.net.URLEncoder.encode(key, java.nio.charset.StandardCharsets.UTF_8)
val showName get() = description?.let { "${it}-${key}" } ?: key
}
data class Wrapper(val repositories: List<Repo>) {
val repositoriesSorted = repositories.sortedBy { it.showName }
}
fun HttpClient.listStagingRepos(user: String, pass: String): Wrapper {
val pid = "io.exoquery"
val auth = Base64.getEncoder().encodeToString("$user:$pass".toByteArray())
val request = HttpRequest.newBuilder()
.uri(URI.create("https://ossrh-staging-api.central.sonatype.com/manual/search/repositories?profile_id=$pid&ip=any"))
.header("Content-Type", "application/json")
.header("Authorization", "Basic $auth")
.GET()
.build()
val mapper = jacksonObjectMapper()
fun tryPrintJson(json: String) {
try {
mapper.writerWithDefaultPrettyPrinter().writeValueAsString(mapper.readTree(json))
} catch (e: Exception) {
json
}
}
val response = this.send(request, HttpResponse.BodyHandlers.ofString())
println("================ /manual/search/repositories Response Code: ${response.statusCode()}: ================\n${tryPrintJson(response.body())}")
/* 1. Sanity-check the HTTP call */
if (response.statusCode() !in 200..299) {
val msg = "================ OSS RH search failed Code:${response.statusCode()} ================\n${response.body()}"
logger.error(msg)
throw GradleException("Search request was not successful because of:\n${msg}")
}
val payload: Wrapper = mapper.readValue<Wrapper>(response.body())
return payload
}
val publishSonatypeStaging by tasks.registering {
description = "Creates a new OSSRH staging repository and records its ID"
doLast {
/* ---- gather inputs exactly as before ---- */
val user = System.getenv("SONATYPE_USERNAME") ?: error("SONATYPE_USERNAME not set")
val pass = System.getenv("SONATYPE_PASSWORD") ?: error("SONATYPE_PASSWORD not set")
val http = HttpClient.newHttpClient()
val auth = Base64.getEncoder().encodeToString("$user:$pass".toByteArray())
/* Pick the repositories that were not uploaded yet */
val matching = http.listStagingRepos(user, pass).repositoriesSorted.filter { it.portal_deployment_id == null }
if (matching.isEmpty()) {
logger.lifecycle("No unpublished repositories found.")
return@doLast
} else {
println("---------------- Found ${matching.size} unpublished repositories ---------------\n${matching.joinToString("\n")}")
}
var ok = 0
var failed = 0
matching.forEach { repo ->
println("==== Processing Repo: ${repo.showName} ====")
// Encode the key exactly like `jq -sRr @uri`
val enc = repo.encodedKey
val promoteRequest = HttpRequest.newBuilder()
.uri(URI.create("https://ossrh-staging-api.central.sonatype.com/manual/upload/repository/$enc?publishing_type=user_managed"))
.header("Content-Type", "application/json")
.header("Accept", "application/json")
.header("Authorization", "Basic $auth")
.POST(HttpRequest.BodyPublishers.ofString("{}"))
.build()
val promoteResp = http.send(promoteRequest, HttpResponse.BodyHandlers.ofString())
if (promoteResp.statusCode() in 200..299) {
println("--- Promoted staging repo ${repo.showName} ---")
ok++
} else {
println("--- Failed to promote repo ${repo.showName} - HTTP Code ${promoteResp.statusCode()} ---\n${promoteResp.body()}")
failed++
}
}
println("==== Processing of Repos Completed ====")
if (failed > 0) {
throw GradleException("Some repositories failed to publish: $failed of ${matching.size}")
} else {
println("All $ok staging repositories successfully switched to user-managed.")
}
}
}