Skip to content

Commit f81b225

Browse files
authored
Remove DefaultInstance (#86)
Removing `DefaultInstance` further cleans up the library API so that its entrypoint is more familiar and easier to grasp with autocomplete. It's not much effort to build an instance before using. Also make the `check` task run integration tests and examples, and switch CI to run `test` instead. CI can't run integration or examples because it doesn't have an API token. Also fix the `update-examples` workflow to support `workflow_dispatch`.
1 parent 3b49efb commit f81b225

File tree

6 files changed

+26
-15
lines changed

6 files changed

+26
-15
lines changed

.github/workflows/pr.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ jobs:
1414
steps:
1515
- name: Checkout
1616
uses: actions/checkout@v3
17-
- name: gradle check
17+
- name: gradle test
1818
uses: ./.github/actions/build
1919
with:
20-
args: 'check compileIntegrationTestKotlin'
20+
args: 'test compileIntegrationTestKotlin'
2121
# artifact-name: 'Test reports (${{matrix.runner}})'
2222
# path-to-upload: '**/build/reports/tests/**'
2323

.github/workflows/update-examples.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: 'Update examples'
33
on:
44
push:
55
tags: [ '*' ]
6-
workflow_call:
6+
workflow_dispatch:
77

88
defaults:
99
run:

examples/build.gradle.kts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
@file:Suppress("HasPlatformType")
2+
3+
plugins {
4+
base
5+
}
6+
17
val exampleTestTasks = ArrayList<TaskProvider<*>>()
28

39
exampleTestTasks += tasks.register<Exec>("runExampleScript") {
@@ -32,8 +38,12 @@ exampleTestTasks += notebooks.map { notebook ->
3238
}
3339
}
3440

35-
tasks.register("runAll") {
41+
val runAll = tasks.register("runAll") {
3642
group = "Application"
3743
description = "Runs everything in 'examples' directory"
3844
dependsOn(exampleTestTasks)
3945
}
46+
47+
tasks.named("check") {
48+
dependsOn(runAll)
49+
}

library/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,10 @@ kotlin {
208208
}
209209
}
210210

211+
tasks.named("check") {
212+
dependsOn("integrationTest")
213+
}
214+
211215
java {
212216
consistentResolution {
213217
useRuntimeClasspathVersions()

library/src/integrationTest/kotlin/com/gabrielfeo/gradle/enterprise/api/internal/GradleEnterpriseApiIntegrationTest.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ import kotlin.test.Test
1010
class GradleEnterpriseApiIntegrationTest {
1111

1212
@Test
13-
fun canFetchBuildsWithDefaultInstance() = runTest {
13+
fun canFetchBuildsWithDefaultConfig() = runTest {
1414
env = RealEnv
1515
keychain = RealKeychain(RealSystemProperties)
16-
val builds = GradleEnterpriseApi.buildsApi.getBuilds(since = 0, maxBuilds = 1)
16+
val api = GradleEnterpriseApi.newInstance()
17+
val builds = api.buildsApi.getBuilds(since = 0, maxBuilds = 1)
1718
assertEquals(1, builds.size)
18-
GradleEnterpriseApi.shutdown()
19+
api.shutdown()
1920
}
2021

2122
@Test

library/src/main/kotlin/com/gabrielfeo/gradle/enterprise/api/GradleEnterpriseApi.kt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,26 +52,22 @@ interface GradleEnterpriseApi {
5252
* The default, companion instance of the Gradle Enterprise API client. See
5353
* [GradleEnterpriseApi].
5454
*/
55-
companion object DefaultInstance : GradleEnterpriseApi by RealGradleEnterpriseApi() {
55+
companion object {
5656

5757
/**
58-
* Create a new instance of `GradleEnterpriseApi` with new options.
58+
* Create a new instance of `GradleEnterpriseApi` with a custom `Config`.
5959
*/
60-
fun newInstance(config: Config): GradleEnterpriseApi {
60+
fun newInstance(config: Config = Config()): GradleEnterpriseApi {
6161
return RealGradleEnterpriseApi(config)
6262
}
6363
}
6464

6565
}
6666

6767
internal class RealGradleEnterpriseApi(
68-
customConfig: Config? = null,
68+
override val config: Config,
6969
) : GradleEnterpriseApi {
7070

71-
override val config by lazy {
72-
customConfig ?: Config()
73-
}
74-
7571
private val okHttpClient by lazy {
7672
buildOkHttpClient(config = config)
7773
}

0 commit comments

Comments
 (0)