firebase / firebase-android-sdk

Firebase Android SDK
https://firebase.google.com
Apache License 2.0
2.26k stars 573 forks source link

App Distribution Gradle plugin has limited configuration cache support #5752

Open PhilGlass opened 7 months ago

PhilGlass commented 7 months ago

AppDistributionExtension properties should be modelled as Property<T> instances rather than raw values. This would allow them to be set from dependency-carrying providers, instead of requiring the values to be known at configuration time (which means the configuration cache is invalidated each time they change). Release notes which include metadata from the HEAD commit are one use case - they'll change every time you commit or switch branch.

I can work around the issue using releaseNotesFile and manual task dependencies:

fun Project.configureFirebaseAppDistribution(group: String) {
    val outputFile = layout.buildDirectory.file("firebase-app-distribution-release-notes").get()

    val generateFirebaseAppDistributionReleaseNotes = tasks.register(
        "generateFirebaseAppDistributionReleaseNotes",
        GenerateFirebaseAppDistributionReleaseNotesTask::class.java
    ) { task ->
        task.outputFile.set(outputFile)
    }

    androidApp {
        buildTypes {
            debug {
                extension<AppDistributionExtension> {
                    // UploadDistributionTask is untracked, so it will never be cached and an absolute path is fine.
                    releaseNotesFile = outputFile.asFile.absolutePath
                    groups = group
                }
            }
        }
    }

    // We have to set up explicit task dependencies because the app distribution extension cannot be configured
    // using dependency-carrying Providers, only raw values.
    tasks.withType<UploadDistributionTask>().configureEach { task ->
        task.dependsOn(generateFirebaseAppDistributionReleaseNotes)
    }
}

@UntrackedTask(
    because = "This task is cheap and only runs when we are uploading to Firebase App Distribution"
)
abstract class GenerateFirebaseAppDistributionReleaseNotesTask : DefaultTask() {
    @get:OutputFile
    abstract val outputFile: RegularFileProperty

    @TaskAction fun execute() {
        val latestCommitSubject = exec("git log -1 --pretty=%s")
        outputFile.get().asFile.writeText(latestCommitSubject)
    }
}

but I shouldn't have to - this must be a pretty common use case.

google-oss-bot commented 7 months ago

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.