Skip to content

Commit 862c372

Browse files
authored
Cache build-cache-performance calls (#18)
1 parent f42b6db commit 862c372

File tree

2 files changed

+31
-10
lines changed
  • src
    • main/kotlin/com/gabrielfeo/gradle/enterprise/api
    • test/kotlin/com/gabrielfeo/gradle/enterprise/api

2 files changed

+31
-10
lines changed

src/main/kotlin/com/gabrielfeo/gradle/enterprise/api/Options.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ class Options internal constructor(
107107
* - cached long-term: default max-age of 1 year
108108
* - `/api/builds/{id}/gradle-attributes`
109109
* - `/api/builds/{id}/maven-attributes`
110+
* - `/api/builds/{id}/gradle-build-cache-performance`
111+
* - `/api/builds/{id}/maven-build-cache-performance`
110112
* - not cached
111113
* - all other paths
112114
*
@@ -174,12 +176,16 @@ class Options internal constructor(
174176
* `GRADLE_ENTERPRISE_API_LONG_TERM_CACHE_URL_PATTERN` or a pattern matching:
175177
* - {host}/api/builds/{id}/gradle-attributes
176178
* - {host}/api/builds/{id}/maven-attributes
179+
* - {host}/api/builds/{id}/gradle-build-cache-performance
180+
* - {host}/api/builds/{id}/maven-build-cache-performance
177181
*
178182
* Use `|` to define multiple patterns in one, e.g. `.*gradle-attributes|.*test-distribution`.
179183
*/
180184
var longTermCacheUrlPattern: Regex =
181185
env["GRADLE_ENTERPRISE_API_LONG_TERM_CACHE_URL_PATTERN"]?.toRegex()
182-
?: """.*/api/builds/[\d\w]+/(?:gradle|maven)-attributes""".toRegex()
186+
// @formatter:off
187+
?: Regex(""".*/api/builds/[\d\w]+/(?:gradle|maven)-(?:attributes|build-cache-performance)""")
188+
// @formatter:on
183189

184190
/**
185191
* Max age in seconds for URLs to be cached long-term (matched by [longTermCacheUrlPattern]).

src/test/kotlin/com/gabrielfeo/gradle/enterprise/api/OptionsTest.kt

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,35 @@ class OptionsTest {
6969
}
7070

7171
@Test
72-
fun `default longTermCacheUrlPattern matches attributes path`() {
72+
fun `default longTermCacheUrlPattern matches attributes URLs`() {
7373
val options = Options(FakeEnv(), FakeKeychain())
74-
with(options.cache.longTermCacheUrlPattern) {
75-
assertTrue(matches("https://ge.gradle.org/api/builds/tgnsqkb2rhlni/gradle-attributes"))
76-
assertTrue(matches("https://ge.gradle.org/api/builds/tgnsqkb2rhlni/maven-attributes"))
77-
}
74+
options.cache.longTermCacheUrlPattern.assertMatches(
75+
"https://ge.gradle.org/api/builds/tgnsqkb2rhlni/gradle-attributes",
76+
"https://ge.gradle.org/api/builds/tgnsqkb2rhlni/maven-attributes",
77+
)
78+
}
79+
80+
@Test
81+
fun `default longTermCacheUrlPattern matches build cache performance URLs`() {
82+
val options = Options(FakeEnv(), FakeKeychain())
83+
options.cache.longTermCacheUrlPattern.assertMatches(
84+
"https://ge.gradle.org/api/builds/tgnsqkb2rhlni/gradle-build-cache-performance",
85+
"https://ge.gradle.org/api/builds/tgnsqkb2rhlni/maven-build-cache-performance",
86+
)
7887
}
7988

8089
@Test
81-
fun `default shortTermCacheUrlPattern matches builds path`() {
90+
fun `default shortTermCacheUrlPattern matches builds URLs`() {
8291
val options = Options(FakeEnv(), FakeKeychain())
83-
with(options.cache.shortTermCacheUrlPattern) {
84-
assertTrue(matches("https://ge.gradle.org/api/builds?since=0"))
85-
assertTrue(matches("https://ge.gradle.org/api/builds?since=0&maxBuilds=2"))
92+
options.cache.shortTermCacheUrlPattern.assertMatches(
93+
"https://ge.gradle.org/api/builds?since=0",
94+
"https://ge.gradle.org/api/builds?since=0&maxBuilds=2",
95+
)
96+
}
97+
98+
private fun Regex.assertMatches(vararg values: String) {
99+
values.forEach {
100+
assertTrue(matches(it), "/$pattern/ doesn't match '$it'")
86101
}
87102
}
88103
}

0 commit comments

Comments
 (0)