Triple-T / gradle-play-publisher

GPP is Android's unofficial release automation Gradle Plugin. It can do anything from building, uploading, and then promoting your App Bundle or APK to publishing app listings and other metadata.
MIT License
4.13k stars 341 forks source link

Add a possibility to verify the artifacts on a specific track #984

Closed japawl closed 3 years ago

japawl commented 3 years ago

Problem description

On our automated release train, we are using multiple tracks for different type of builds (alpha, preRelease, hotfix and so on). We had an incident that due to track name mixup, wrong artifact got promoted to production.

Potential solutions/workarounds

To prevent any kind similar issues when wrong artifact is promoted to production, a task can be created that checks specific track against given versionCode and versionName. This would also ensure that only artifacts built with fully automated release trains are permitted to be promoted, as any manually uploaded artifact (not following the versionCode and versionName values, which are controlled by the automation scripts) would fail the check task.

Additional context

Google Play Developer API has a getter method for specific task available. We currently have in-house custom gradle tasks that fetches the track info (the checking part we have separated in a different Task, which is just parsing Json file and checking its values):

tasks.register("getTrackReleaseInfo") {
        val output = File(project.buildDir, "release-tracks-info.json")
        outputs.file(output.path)

        val apiService = gradle.sharedServices.registrations
            .named("playApi-com.glovo")
            .get().service.get()

        doLast {
            val publisher = apiService.withGroovyBuilder { "getPublisher"() }!!

            val editId = publisher.withGroovyBuilder { "insertEdit"() }!!
                .withGroovyBuilder { "getId"() }

            val track = publisher.withGroovyBuilder { "getTrack"(editId, "$trackName") }!! 

            val releaseInfo =  track.withGroovyBuilder { "toPrettyString"() } as String

            output.writeText(releaseInfo)
        }
    }

This is not the perfect way to consume the apiService and I see value to ship this functionality along with the plugin.

SUPERCILEX commented 3 years ago

Thanks for the idea, but I don't think I'll ever want to add specialized tasks like that. There's simply no way it'll meet a broad audience's needs. I also don't want to add tasks that simply put an API request's JSON somewhere, because at that point I feel like you may as well just use the androidpublisher client directly.

If that task meets your needs, then I don't see the harm in continuing to use it. Obviously there are no backwards compat guarantees, but I also don't see those APIs changing anytime soon. BTW, you can clean the task up a little bit:

import com.github.triplet.gradle.androidpublisher.EditResponse
import com.github.triplet.gradle.androidpublisher.PlayPublisher
import com.google.api.services.androidpublisher.model.Track

// ...

    doLast {
        val publisher = apiService.withGroovyBuilder { "getPublisher"() } as PlayPublisher

        val editId = when (val result = publisher.insertEdit()) {
            is EditResponse.Success -> result.id
            is EditResponse.Failure -> TODO()
        }

        val track = publisher.withGroovyBuilder { "getTrack"(editId, trackName) } as Track

        output.writeText(track.toPrettyString())
    }