Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/unit-test-report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Firebase AI Daily Tests

on:
schedule:
- cron: 51 8 * * * # Runs automatically once a day
workflow_dispatch: # Allow triggering the workflow manually

permissions:
contents: read
issues: write

jobs:
dailies:
name: "Unit Test Report"
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
submodules: true

- name: Set up JDK 17
uses: actions/setup-java@3a4f6e1af504cf6a31855fa899c6aa5355ba6c12 # v4.7.0
with:
java-version: 17
distribution: temurin
cache: gradle

- name: Generate Test Report
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./gradlew generateTestReport

- name: Update tracking issue
run: gh issue edit 7421 --body-file test-report.md
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it meant to be hardcoded to 7421?

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.google.firebase.gradle.plugins

import com.android.build.gradle.LibraryExtension
import com.google.firebase.gradle.plugins.ci.Coverage
import com.google.firebase.gradle.plugins.report.UnitTestReportTask
import com.google.firebase.gradle.plugins.services.GMavenService
import java.io.File
import java.nio.file.Paths
Expand Down Expand Up @@ -141,6 +142,13 @@ abstract class BaseFirebaseLibraryPlugin : Plugin<Project> {
}
}

protected fun registerUnitTestReportTask(project: Project) =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This plugin is applied once per subproject. Since the task is not tied to any particular subproject, does it make sense to register it here?

project.tasks.register<UnitTestReportTask>("generateTestReport") {
outputFile.set(project.file("test-report.md"))
commitCount.set(8 as Integer)
apiToken.set(System.getenv("GH_TOKEN"))
}

protected fun getApiInfo(
project: Project,
srcDirs: ConfigurableFileCollection,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ class FirebaseAndroidLibraryPlugin : BaseFirebaseLibraryPlugin() {
}

setupMetalavaSemver(project, firebaseLibrary)
registerUnitTestReportTask(project)
}

private fun setupApiInformationAnalysis(project: Project, android: LibraryExtension) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class FirebaseJavaLibraryPlugin : BaseFirebaseLibraryPlugin() {
}

setupMetalavaSemver(project, firebaseLibrary)
registerUnitTestReportTask(project)
}

private fun setupApiInformationAnalysis(project: Project) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ import java.time.Duration
import java.util.regex.Matcher
import java.util.regex.Pattern
import org.gradle.internal.Pair
import java.io.File

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

fun createReport(commitCount: Int) {
fun createReport(outputFile: File, commitCount: Int) {
val response = request("commits?per_page=$commitCount", JsonArray::class.java)
val commits =
response
Expand All @@ -55,10 +56,10 @@ class UnitTestReport(private val apiToken: String) {
ReportCommit(obj.get("sha").asString, pr)
}
.toList()
outputReport(commits)
outputReport(outputFile, commits)
}

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

try {
val writer = FileWriter("test-report.md")
val writer = FileWriter(outputFile)
writer.append(output.toString())
writer.close()
} catch (e: Exception) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.firebase.gradle.plugins.report

import org.gradle.api.DefaultTask
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction

abstract class UnitTestReportTask: DefaultTask() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation

@get:OutputFile abstract val outputFile: RegularFileProperty

@get:Input abstract val commitCount: Property<Integer>

@get:Input abstract val apiToken: Property<String>

@TaskAction
fun make() {
UnitTestReport(apiToken.get()).createReport(outputFile.asFile.get(), commitCount.get().toInt())
}
}
Loading