Skip to content

Commit 1baaff9

Browse files
committed
Create unit test report workflow
1 parent e157a9f commit 1baaff9

File tree

6 files changed

+86
-4
lines changed

6 files changed

+86
-4
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Firebase AI Daily Tests
2+
3+
on:
4+
schedule:
5+
- cron: 51 8 * * * # Runs automatically once a day
6+
workflow_dispatch: # Allow triggering the workflow manually
7+
8+
permissions:
9+
contents: read
10+
issues: write
11+
12+
jobs:
13+
dailies:
14+
name: "Unit Test Report"
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
19+
with:
20+
submodules: true
21+
22+
- name: Set up JDK 17
23+
uses: actions/setup-java@3a4f6e1af504cf6a31855fa899c6aa5355ba6c12 # v4.7.0
24+
with:
25+
java-version: 17
26+
distribution: temurin
27+
cache: gradle
28+
29+
- name: Generate Test Report
30+
env:
31+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32+
run: ./gradlew generateTestReport
33+
34+
- name: Update tracking issue
35+
run: gh issue edit 7421 --body-file test-report.md

plugins/src/main/java/com/google/firebase/gradle/plugins/BaseFirebaseLibraryPlugin.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package com.google.firebase.gradle.plugins
1818

1919
import com.android.build.gradle.LibraryExtension
2020
import com.google.firebase.gradle.plugins.ci.Coverage
21+
import com.google.firebase.gradle.plugins.report.UnitTestReportTask
2122
import com.google.firebase.gradle.plugins.services.GMavenService
2223
import java.io.File
2324
import java.nio.file.Paths
@@ -141,6 +142,13 @@ abstract class BaseFirebaseLibraryPlugin : Plugin<Project> {
141142
}
142143
}
143144

145+
protected fun registerUnitTestReportTask(project: Project) =
146+
project.tasks.register<UnitTestReportTask>("generateTestReport") {
147+
outputFile.set(project.file("test-report.md"))
148+
commitCount.set(8 as Integer)
149+
apiToken.set(System.getenv("GH_TOKEN"))
150+
}
151+
144152
protected fun getApiInfo(
145153
project: Project,
146154
srcDirs: ConfigurableFileCollection,

plugins/src/main/java/com/google/firebase/gradle/plugins/FirebaseAndroidLibraryPlugin.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ class FirebaseAndroidLibraryPlugin : BaseFirebaseLibraryPlugin() {
162162
}
163163

164164
setupMetalavaSemver(project, firebaseLibrary)
165+
registerUnitTestReportTask(project)
165166
}
166167

167168
private fun setupApiInformationAnalysis(project: Project, android: LibraryExtension) {

plugins/src/main/java/com/google/firebase/gradle/plugins/FirebaseJavaLibraryPlugin.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ class FirebaseJavaLibraryPlugin : BaseFirebaseLibraryPlugin() {
105105
}
106106

107107
setupMetalavaSemver(project, firebaseLibrary)
108+
registerUnitTestReportTask(project)
108109
}
109110

110111
private fun setupApiInformationAnalysis(project: Project) {

plugins/src/main/java/com/google/firebase/gradle/plugins/report/UnitTestReport.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@ import java.time.Duration
3030
import java.util.regex.Matcher
3131
import java.util.regex.Pattern
3232
import org.gradle.internal.Pair
33+
import java.io.File
3334

3435
@SuppressWarnings("NewApi")
3536
class UnitTestReport(private val apiToken: String) {
3637
private val client: HttpClient =
3738
HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(10)).build()
3839

39-
fun createReport(commitCount: Int) {
40+
fun createReport(outputFile: File, commitCount: Int) {
4041
val response = request("commits?per_page=$commitCount", JsonArray::class.java)
4142
val commits =
4243
response
@@ -55,10 +56,10 @@ class UnitTestReport(private val apiToken: String) {
5556
ReportCommit(obj.get("sha").asString, pr)
5657
}
5758
.toList()
58-
outputReport(commits)
59+
outputReport(outputFile, commits)
5960
}
6061

61-
private fun outputReport(commits: List<ReportCommit>) {
62+
private fun outputReport(outputFile: File, commits: List<ReportCommit>) {
6263
val reports: MutableList<TestReport> = ArrayList()
6364
for (commit in commits) {
6465
reports.addAll(parseTestReports(commit.sha))
@@ -82,7 +83,7 @@ class UnitTestReport(private val apiToken: String) {
8283
output.append("\n")
8384

8485
try {
85-
val writer = FileWriter("test-report.md")
86+
val writer = FileWriter(outputFile)
8687
writer.append(output.toString())
8788
writer.close()
8889
} catch (e: Exception) {
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.google.firebase.gradle.plugins.report
17+
18+
import org.gradle.api.DefaultTask
19+
import org.gradle.api.file.RegularFileProperty
20+
import org.gradle.api.provider.Property
21+
import org.gradle.api.tasks.Input
22+
import org.gradle.api.tasks.OutputFile
23+
import org.gradle.api.tasks.TaskAction
24+
25+
abstract class UnitTestReportTask: DefaultTask() {
26+
@get:OutputFile abstract val outputFile: RegularFileProperty
27+
28+
@get:Input abstract val commitCount: Property<Integer>
29+
30+
@get:Input abstract val apiToken: Property<String>
31+
32+
@TaskAction
33+
fun make() {
34+
UnitTestReport(apiToken.get()).createReport(outputFile.asFile.get(), commitCount.get().toInt())
35+
}
36+
}

0 commit comments

Comments
 (0)