forked from apollographql/apollo-kotlin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
171 lines (144 loc) · 4.93 KB
/
build.gradle.kts
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
import JapiCmp.configureJapiCmp
import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeHostTest
plugins {
id("build.logic") apply false
}
apply(plugin = "com.github.ben-manes.versions")
apply(plugin = "org.jetbrains.kotlinx.binary-compatibility-validator")
version = property("VERSION_NAME")!!
fun subprojectTasks(name: String): List<Task> {
return subprojects.flatMap { subproject ->
subproject.tasks.matching { it.name == name }
}
}
fun isTag(): Boolean {
val ref = System.getenv("GITHUB_REF")
return ref?.startsWith("refs/tags/") == true
}
fun shouldPublishSnapshots(): Boolean {
val eventName = System.getenv("GITHUB_EVENT_NAME")
val ref = System.getenv("GITHUB_REF")
return eventName == "push" && (ref == "refs/heads/main")
}
tasks.register("ciPublishSnapshot") {
description = "Publishes a SNAPSHOT"
if (shouldPublishSnapshots()) {
dependsOn(subprojectTasks("publishAllPublicationsToOssSnapshotsRepository"))
} else {
doFirst {
error("We are not on a branch, fail snapshots publishing")
}
}
}
tasks.register("ciPublishRelease") {
description = "Publishes all artifacts to OSSRH and the Gradle Plugin Portal"
if (isTag()) {
dependsOn(subprojectTasks("publishAllPublicationsToOssStagingRepository"))
// Only publish plugins to the Gradle portal if everything else succeeded
finalizedBy(":apollo-gradle-plugin:publishPlugins")
} else {
doFirst {
error("We are not on a tag, fail release publishing")
}
}
}
tasks.register("ciTestsGradle") {
description = "Execute the Gradle tests (slow)"
dependsOn(":apollo-gradle-plugin:allTests")
dependsOn(":apollo-gradle-plugin-external:validatePlugins")
}
tasks.register("ciTestsNoGradle") {
description = """Execute all tests from the root project except:
| - the Gradle ones
| - most of the Apple tests. Instead it just executes macosX64 tests to save time
| - the IntelliJ plugin tests - they are run in a dedicated job
""".trimMargin()
subprojects {
if (name !in setOf("apollo-gradle-plugin", "intellij-plugin")) {
dependsOn(tasks.matching { it.name == "test" })
}
dependsOn(tasks.matching { it.name == "jvmTest" })
dependsOn(tasks.matching { it.name == "jsIrTest" })
dependsOn(tasks.withType(KotlinNativeHostTest::class.java))
dependsOn(tasks.matching { it.name == "apiCheck" })
}
/**
* Update the database schemas in CI
*/
dependsOn(":apollo-normalized-cache-sqlite:generateCommonMainJsonDatabaseSchema")
dependsOn(":apollo-normalized-cache-sqlite-incubating:generateCommonMainJsonDatabaseSchema")
dependsOn(":apollo-normalized-cache-sqlite-incubating:generateCommonMainBlobDatabaseSchema")
dependsOn(":apollo-normalized-cache-sqlite-incubating:generateCommonMainBlob2DatabaseSchema")
doLast {
if (isCIBuild()) {
checkGitStatus()
}
}
}
/**
* Shorthands for less typing during development
*/
tasks.register("ctng") {
dependsOn("ciTestsNoGradle")
}
tasks.register("ctg") {
dependsOn("ciTestsGradle")
}
val ciBuild = tasks.register("ciBuild") {
description = "Execute the 'build' task in each subproject"
dependsOn(subprojectTasks("build"))
}
tasks.named("dependencyUpdates").configure {
(this as com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask)
rejectVersionIf {
listOf("alpha", "beta", "rc").any { candidate.version.lowercase().contains(it) }
}
}
rootProject.configureNode()
rootProject.configureJapiCmp()
configure<kotlinx.validation.ApiValidationExtension> {
ignoredPackages.addAll(
listOf(
/**
* In general, we rely on annotations or "internal" visibility to hide the non-public APIs. But there are a few exceptions:
*
* Gradle plugin: tasks and other classes must be public in order for Gradle to instantiate and decorate them.
* SQLDelight generated sources are not generated as 'internal'.
*/
"com.apollographql.apollo3.gradle.internal",
"com.apollographql.apollo3.cache.normalized.sql.internal",
"com.apollographql.apollo3.runtime.java.internal",
"com.apollographql.apollo3.runtime.java.interceptor.internal",
"com.apollographql.apollo3.runtime.java.network.http.internal",
)
)
ignoredProjects.addAll(
rootDir.resolve("libraries")
.listFiles()!!
.filter { it.resolve("build.gradle.kts").exists() }
.map { it.name }
.filter { it.endsWith("-incubating") }
+ "intellij-plugin"
)
nonPublicMarkers.addAll(
listOf(
"com.apollographql.apollo3.annotations.ApolloInternal",
"com.apollographql.apollo3.annotations.ApolloExperimental",
)
)
}
tasks.register("rmbuild") {
val root = file(".")
doLast {
root.walk().onEnter {
if (it.isDirectory && it.name == "build") {
println("deleting: $it")
it.deleteRecursively()
false
} else {
true
}
}.count()
}
}
rootSetup(ciBuild)