Fixed Custom app bundle CI failed to find the bundle for the version

This commit is contained in:
MohitMaliFtechiz 2023-05-19 18:59:43 +05:30 committed by Kelson
parent 1d386b869f
commit 8cde9a7191
2 changed files with 9 additions and 18 deletions

View File

@ -88,12 +88,13 @@ class Transaction(
ExpansionFile().apply { referencesVersion = versionCode } ExpansionFile().apply { referencesVersion = versionCode }
).execute().prettyPrint() ).execute().prettyPrint()
fun uploadBundle(outputFile: File) { fun uploadBundleAndReturnVersionCode(outputFile: File): Int {
publisher.edits().bundles().upload( val bundle = publisher.edits().bundles().upload(
packageName, packageName,
editId, editId,
FileContent("application/octet-stream", outputFile) FileContent("application/octet-stream", outputFile)
).execute().prettyPrint() ).execute().prettyPrint()
return bundle.versionCode
} }
fun addToTrackInDraft(versionCode: Int, versionName: String?): Track = fun addToTrackInDraft(versionCode: Int, versionName: String?): Track =

View File

@ -1,5 +1,3 @@
import com.android.build.gradle.api.ApplicationVariant
import com.android.build.gradle.api.ApkVariantOutput
import com.android.build.gradle.internal.dsl.ProductFlavor import com.android.build.gradle.internal.dsl.ProductFlavor
import custom.CustomApps import custom.CustomApps
import custom.createPublisher import custom.createPublisher
@ -26,7 +24,7 @@ android {
all { all {
File("$projectDir/src", "$name/$name.zim").let { File("$projectDir/src", "$name/$name.zim").let {
createDownloadTask(it) createDownloadTask(it)
createPublishBundleWithExpansionTask(it, applicationVariants) createPublishBundleWithExpansionTask(it)
} }
} }
} }
@ -66,8 +64,7 @@ fun ProductFlavor.fetchUrl(): String {
} }
fun ProductFlavor.createPublishBundleWithExpansionTask( fun ProductFlavor.createPublishBundleWithExpansionTask(
file: File, file: File
applicationVariants: DomainObjectSet<ApplicationVariant>
): Task { ): Task {
val capitalizedName = name.capitalize() val capitalizedName = name.capitalize()
return tasks.create("publish${capitalizedName}ReleaseBundleWithExpansionFile") { return tasks.create("publish${capitalizedName}ReleaseBundleWithExpansionFile") {
@ -78,18 +75,16 @@ fun ProductFlavor.createPublishBundleWithExpansionTask(
println("packageName $packageName") println("packageName $packageName")
createPublisher(File(rootDir, "playstore.json")) createPublisher(File(rootDir, "playstore.json"))
.transactionWithCommit(packageName) { .transactionWithCommit(packageName) {
val variants =
applicationVariants.releaseVariantsFor(this@createPublishBundleWithExpansionTask)
val generatedBundleFile = val generatedBundleFile =
File( File(
"$buildDir/outputs/bundle/${capitalizedName.toLowerCase()}" + "$buildDir/outputs/bundle/${capitalizedName.toLowerCase()}" +
"Release/custom-${capitalizedName.toLowerCase()}-release.aab" "Release/custom-${capitalizedName.toLowerCase()}-release.aab"
) )
if (generatedBundleFile.exists()) { if (generatedBundleFile.exists()) {
uploadBundle(generatedBundleFile) val versionCode = uploadBundleAndReturnVersionCode(generatedBundleFile)
uploadExpansionTo(file, variants[0].versionCode) uploadExpansionTo(file, versionCode)
attachExpansionTo(variants[0].versionCode) attachExpansionTo(versionCode)
addToTrackInDraft(variants[0].versionCode, versionName) addToTrackInDraft(versionCode, versionName)
} else { } else {
throw FileNotFoundException("Unable to find generated aab file") throw FileNotFoundException("Unable to find generated aab file")
} }
@ -98,11 +93,6 @@ fun ProductFlavor.createPublishBundleWithExpansionTask(
} }
} }
fun DomainObjectSet<ApplicationVariant>.releaseVariantsFor(productFlavor: ProductFlavor) =
find { it.name.equals("${productFlavor.name}Release", true) }!!
.outputs.filterIsInstance<ApkVariantOutput>()
.filter { it.baseName.contains("universal") }.sortedBy { it.versionCode }
afterEvaluate { afterEvaluate {
tasks.filter { it.name.contains("ReleaseBundleWithExpansionFile") }.forEach { tasks.filter { it.name.contains("ReleaseBundleWithExpansionFile") }.forEach {
val flavorName = val flavorName =