Skip to content

Commit

Permalink
Merge pull request #36 from Automattic/cleanup
Browse files Browse the repository at this point in the history
Cleanup
  • Loading branch information
wzieba authored Feb 28, 2024
2 parents a4a0430 + e7cd587 commit f84809a
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class MetricsReporter(
) {
reportLocally(report)

val payload = report.toAppsInfraPayload(gradleScanId)
val payload = report.toAppsMetricsPayload(gradleScanId)
@Suppress("TooGenericExceptionCaught")
try {
logSlowTasks(report)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.automattic.android.measure.models.MeasuredTask.State.EXECUTED
import com.automattic.android.measure.models.MeasuredTask.State.IS_FROM_CACHE
import com.automattic.android.measure.models.MeasuredTask.State.UP_TO_DATE

fun InMemoryReport.toAppsInfraPayload(gradleScanId: String?): GroupedAppsMetrics {
fun InMemoryReport.toAppsMetricsPayload(gradleScanId: String?): GroupedAppsMetrics {
val projectKey = buildData.forProject.name.lowercase()

val meta = mapOf(
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ class BuildTimePluginConfigurationCacheTests {

@Test
fun `given a project utilizes configuration cache, when build finishes, then report 0 configuration cache duration`() {
// given
val runner = runner()

// when
runner("help", "--stacktrace").build()

Expand Down Expand Up @@ -83,13 +80,11 @@ class BuildTimePluginConfigurationCacheTests {
}

private fun runner(vararg arguments: String): GradleRunner {
val projectDir = File("build/functionalTest")
projectDir.mkdirs()

projectDir.resolve("settings.gradle.kts").writeText("")

projectDir.resolve("build.gradle.kts").writeText(
"""
val projectDir = File("build/functionalTest").apply {
mkdirs()
resolve("settings.gradle.kts").writeText("")
resolve("build.gradle.kts").writeText(
"""
plugins {
id("com.automattic.android.measure-builds")
}
Expand All @@ -98,15 +93,15 @@ class BuildTimePluginConfigurationCacheTests {
attachGradleScanId.set(false)
automatticProject.set(com.automattic.android.measure.MeasureBuildsExtension.AutomatticProject.WooCommerce)
}
""".trimIndent()
)

val runner = GradleRunner.create()
runner.forwardOutput()
runner.withPluginClasspath()
runner.withArguments(*arguments, "--configuration-cache")
runner.withProjectDir(projectDir)
return runner
""".trimIndent()
)
}

return GradleRunner.create()
.forwardOutput()
.withPluginClasspath()
.withArguments(*arguments, "--configuration-cache")
.withProjectDir(projectDir)
}

private val executionData: ExecutionData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ class BuildTimePluginTest {
val run = runner.withArguments("help").build()

// then
assertThat(run.output)
.contains("No authToken provided. Skipping reporting.")
assertThat(run.output).contains("No authToken provided. Skipping reporting.")
.contains("BUILD SUCCESSFUL")
}

Expand All @@ -130,17 +129,16 @@ class BuildTimePluginTest {
)

// when
val run = runner.withArguments("help").build()
runner.withArguments("help").build()

// then
File("build/functionalTest/build/reports/measure_builds/execution_data.json").let {
val executionData = Json.decodeFromString<ExecutionData>(it.readText())

assertThat(executionData.tasks).hasSize(1)
.first().satisfies({ task ->
assertThat(task.name).isEqualTo(":help")
assertThat(task.state).isEqualTo(MeasuredTask.State.EXECUTED)
})
assertThat(executionData.tasks).hasSize(1).first().satisfies({ task ->
assertThat(task.name).isEqualTo(":help")
assertThat(task.state).isEqualTo(MeasuredTask.State.EXECUTED)
})
}
}

Expand All @@ -157,44 +155,44 @@ class BuildTimePluginTest {
applyAppsMetricsToken: Boolean = true,
vararg arguments: String,
): GradleRunner {
val projectDir = File("build/functionalTest")
projectDir.mkdirs()
if (projectWithSendingScans) {
projectDir.resolve("settings.gradle.kts").writeText(
"""
plugins {
id("com.gradle.enterprise") version "3.15.1"
}
gradleEnterprise {
buildScan {
publishAlways()
termsOfServiceUrl = "https://gradle.com/terms-of-service"
termsOfServiceAgree = "yes"
isUploadInBackground = false
}
val projectDir = File("build/functionalTest").apply {
mkdirs()
if (projectWithSendingScans) {
resolve("settings.gradle.kts").writeText(
"""
plugins {
id("com.gradle.enterprise") version "3.15.1"
}
gradleEnterprise {
buildScan {
publishAlways()
termsOfServiceUrl = "https://gradle.com/terms-of-service"
termsOfServiceAgree = "yes"
isUploadInBackground = false
}
}
""".trimIndent()
)
}
resolve("build.gradle.kts").writeText(
"""
plugins {
id("com.automattic.android.measure-builds")
}
measureBuilds {
${if (enable != null) "enable.set($enable)" else ""}
attachGradleScanId.set($attachGradleScanId)
automatticProject.set(com.automattic.android.measure.MeasureBuildsExtension.AutomatticProject.WooCommerce)
${if (applyAppsMetricsToken) "authToken.set(\"token\")" else ""}
}
""".trimIndent()
)
}
projectDir.resolve("build.gradle.kts").writeText(
"""
plugins {
id("com.automattic.android.measure-builds")
}
measureBuilds {
${if (enable != null) "enable.set($enable)" else ""}
attachGradleScanId.set($attachGradleScanId)
automatticProject.set(com.automattic.android.measure.MeasureBuildsExtension.AutomatticProject.WooCommerce)
${if (applyAppsMetricsToken) "authToken.set(\"token\")" else ""}
}
""".trimIndent()
)

val runner = GradleRunner.create()
runner.forwardOutput()
runner.withPluginClasspath()
runner.withArguments(arguments.toList())
runner.withProjectDir(projectDir)
return runner
return GradleRunner.create()
.forwardOutput()
.withPluginClasspath()
.withArguments(arguments.toList())
.withProjectDir(projectDir)
}
}

0 comments on commit f84809a

Please sign in to comment.