Skip to content

Commit

Permalink
Remove DefaultInstance (#86)
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
gabrielfeo authored May 31, 2023
1 parent 3b49efb commit f81b225
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
- name: gradle check
- name: gradle test
uses: ./.github/actions/build
with:
args: 'check compileIntegrationTestKotlin'
args: 'test compileIntegrationTestKotlin'
# artifact-name: 'Test reports (${{matrix.runner}})'
# path-to-upload: '**/build/reports/tests/**'

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/update-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: 'Update examples'
on:
push:
tags: [ '*' ]
workflow_call:
workflow_dispatch:

defaults:
run:
Expand Down
12 changes: 11 additions & 1 deletion examples/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
@file:Suppress("HasPlatformType")

plugins {
base
}

val exampleTestTasks = ArrayList<TaskProvider<*>>()

exampleTestTasks += tasks.register<Exec>("runExampleScript") {
Expand Down Expand Up @@ -32,8 +38,12 @@ exampleTestTasks += notebooks.map { notebook ->
}
}

tasks.register("runAll") {
val runAll = tasks.register("runAll") {
group = "Application"
description = "Runs everything in 'examples' directory"
dependsOn(exampleTestTasks)
}

tasks.named("check") {
dependsOn(runAll)
}
4 changes: 4 additions & 0 deletions library/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ kotlin {
}
}

tasks.named("check") {
dependsOn("integrationTest")
}

java {
consistentResolution {
useRuntimeClasspathVersions()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import kotlin.test.Test
class GradleEnterpriseApiIntegrationTest {

@Test
fun canFetchBuildsWithDefaultInstance() = runTest {
fun canFetchBuildsWithDefaultConfig() = runTest {
env = RealEnv
keychain = RealKeychain(RealSystemProperties)
val builds = GradleEnterpriseApi.buildsApi.getBuilds(since = 0, maxBuilds = 1)
val api = GradleEnterpriseApi.newInstance()
val builds = api.buildsApi.getBuilds(since = 0, maxBuilds = 1)
assertEquals(1, builds.size)
GradleEnterpriseApi.shutdown()
api.shutdown()
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,22 @@ interface GradleEnterpriseApi {
* The default, companion instance of the Gradle Enterprise API client. See
* [GradleEnterpriseApi].
*/
companion object DefaultInstance : GradleEnterpriseApi by RealGradleEnterpriseApi() {
companion object {

/**
* Create a new instance of `GradleEnterpriseApi` with new options.
* Create a new instance of `GradleEnterpriseApi` with a custom `Config`.
*/
fun newInstance(config: Config): GradleEnterpriseApi {
fun newInstance(config: Config = Config()): GradleEnterpriseApi {
return RealGradleEnterpriseApi(config)
}
}

}

internal class RealGradleEnterpriseApi(
customConfig: Config? = null,
override val config: Config,
) : GradleEnterpriseApi {

override val config by lazy {
customConfig ?: Config()
}

private val okHttpClient by lazy {
buildOkHttpClient(config = config)
}
Expand Down

0 comments on commit f81b225

Please sign in to comment.