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

Find the largest version CLI option #974

Closed nohe427 closed 3 years ago

nohe427 commented 3 years ago

Is there a CLI option to find the largest published version in the Play Store? I see that there is an automatic version resolver, but it does not specify whether there can be a CLI to return the largest version? Would this be something that you would consider building in?

growse commented 3 years ago

Was just about to ask a similar thing. I publish abundle to the play store for internal testing pretty regularly, but when I cut a beta/prod release, I use GPP to promote the build from internal to beta (and then to prod).

But! I also want to do a github release of the apk, and currently don't have any way of getting the auto-resolved build number of the current build on any track on the plat store with which to stamp into the APK.

SUPERCILEX commented 3 years ago

No, we don't and probably never will. The goal of GPP is to be an automation tool, not a CLI for the Play Console. @nohe427 what are you trying to do with the highest version code?

@growse so you already have the APK? That's the source of truth, meaning you can use aapt to extract the version code from it. You could also get the version code from the App Bundle with bundletool. Or am I misunderstanding what you need the version code for?

PS: we do actually have an API for getting the max version code that you could theoretically use, but it's internal so there's no documentation and no efforts are made to maintain backwards compatibility.

growse commented 3 years ago

@SUPERCILEX makes sense. To elaborate a little. I publish a bundle on every commit, but on a tag I'd like to promote the artifact on GP but also build an apk with the same build number as on GP (I only build apks on tags).

I think the right answer here is for me to write a script that pulls the current build number from GP and then builds the apk specifically with that build number.

SUPERCILEX commented 3 years ago

If possible, I would recommend handling the tag release as part of the same build, otherwise things get complicated like this.

That said, you should be able to use our process version codes task and simply subtract 1 from the output. I believe the file it generates is called version-codes.txt. I'll write up an example after the 4th.

SUPERCILEX commented 3 years ago

Here you go (stick it at the bottom of your build.gradle.kts):

abstract class GetLatestVersionCodeMinusOne : DefaultTask() {
    @get:InputFile
    abstract val codes: RegularFileProperty

    @get:OutputFile
    abstract val outCode: RegularFileProperty

    @TaskAction
    fun read() {
        val code = codes.get().asFile.readLines().first().toInt() - 1
        outCode.get().asFile.writeText(code.toString())
    }
}

val codesTask = tasks.register<GetLatestVersionCodeMinusOne>("getLatestVersionCodeMinusOne") {
    dependsOn("processReleaseVersionCodes")

    codes.set(file("build/intermediates/gpp/release/available-version-codes.txt"))
    outCode.set(file("build/intermediates/version-code-minus-one.txt"))
}

androidComponents {
    onVariants { variant ->
        for (output in variant.outputs) {
            output.versionCode.set(codesTask.flatMap { it.outCode }.map { it.asFile.readText().toInt() })
        }
    }
}

You'll want some logic to only run the androidComponents block if you need the APK.

github-actions[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.