Skip to content

Commit

Permalink
Moved task configuration from build.gralde.kts to the plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentMasselis committed Jul 26, 2023
1 parent b40c513 commit a90f918
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main-promotion.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ jobs:
- name: Promotion
uses: ./.github/actions/run-emulator
with:
script: ./gradlew promoteToMain
script: ./gradlew promoteToMainNormalRelease
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ jobs:
- name: Upload release
uses: gradle/gradle-build-action@v2
with:
arguments: tagCommitAndPublishToBeta
arguments: tagCommitAndPublishToBetaNormalRelease
15 changes: 2 additions & 13 deletions app/phone/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
@file:Suppress("LocalVariableName")
@file:Suppress("LocalVariableName", "UnstableApiUsage")

import com.masselis.tpmsadvanced.publisher.AndroidPublisherExtension
import com.masselis.tpmsadvanced.publisher.AndroidPublisherPlugin
import com.masselis.tpmsadvanced.publisher.PromoteToMain
import com.masselis.tpmsadvanced.publisher.TagCommitAndPublishToBeta

plugins {
id("android-app")
Expand Down Expand Up @@ -122,17 +121,7 @@ if (isDecrypted) {
configure<AndroidPublisherExtension> {
serviceAccountCredentials = file("../../secrets/publisher-service-account.json")
}
tasks.create<TagCommitAndPublishToBeta>("tagCommitAndPublishToBeta") {
dependsOn("bundleNormalRelease")
packageName = android.defaultConfig.applicationId
currentVc = tpmsAdvancedVersionCode
releaseBundle = layout.buildDirectory.file("outputs/bundle/normalRelease/phone-normal-release.aab")
releaseNotes = layout.projectDirectory.file("src/normal/play/release-notes/en-US/beta.txt")
}
tasks.create<PromoteToMain>("promoteToMain") {
tasks.withType<PromoteToMain> {
dependsOn("copyScreenshot")
packageName = android.defaultConfig.applicationId
currentVc = tpmsAdvancedVersionCode
screenshotDirectory = layout.projectDirectory.dir("src/normal/play/listings/en-US/graphics/phone-screenshots")
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,56 @@
package com.masselis.tpmsadvanced.publisher

import com.android.build.api.artifact.SingleArtifact
import com.android.build.api.dsl.ApplicationExtension
import com.android.build.api.variant.ApplicationAndroidComponentsExtension
import com.android.build.api.variant.impl.ApplicationVariantImpl
import com.android.build.api.variant.impl.dirName
import com.android.build.gradle.internal.dsl.BaseAppModuleExtension
import com.android.build.gradle.internal.scope.getOutputPath
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.configurationcache.extensions.capitalized
import org.gradle.kotlin.dsl.assign
import org.gradle.kotlin.dsl.create
import org.gradle.kotlin.dsl.getByType

public class AndroidPublisherPlugin : Plugin<Project> {
override fun apply(project: Project) {
val ext = project.extensions.create<AndroidPublisherExtension>("androidPublisher")
project.gradle.sharedServices.registerIfAbsent(
"android-publisher-service",
AndroidPublisherService::class.java
"android-publisher-service", AndroidPublisherService::class.java
) {
parameters.serviceAccountCredentials = ext.serviceAccountCredentials
}
with(project.extensions.getByType(ApplicationAndroidComponentsExtension::class)) {
onVariants { variant ->
if (variant.isMinifyEnabled) {
project.tasks.create<TagCommitAndPublishToBeta>("tagCommitAndPublishToBeta${variant.name.capitalized()}") {
dependsOn("bundle${variant.name.capitalized()}")
packageName = variant.applicationId
currentVc = variant.outputs.single().versionCode
releaseBundle.set {
SingleArtifact
.BUNDLE
.getOutputPath(project.layout.buildDirectory, variant.name)
.listFiles()
.single { it.extension == "aab" }
}
releaseNotes = project
.layout
.projectDirectory
.file("src/${variant.flavorName}/play/release-notes/en-US/beta.txt")
}
project.tasks.create<PromoteToMain>("promoteToMain${variant.name.capitalized()}") {
packageName = variant.applicationId
currentVc = variant.outputs.single().versionCode
screenshotDirectory = project
.layout
.projectDirectory
.dir("src/${variant.flavorName}/play/listings/en-US/graphics/phone-screenshots")
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ package com.masselis.tpmsadvanced.publisher
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport
import com.google.api.client.http.HttpRequest
import com.google.api.client.http.HttpRequestInitializer
import com.google.api.client.http.javanet.NetHttpTransport
import com.google.api.client.json.gson.GsonFactory
import com.google.api.services.androidpublisher.AndroidPublisher
import com.google.api.services.androidpublisher.AndroidPublisherScopes
import com.google.api.services.androidpublisher.AndroidPublisherScopes.ANDROIDPUBLISHER
import com.google.auth.http.HttpCredentialsAdapter
import com.google.auth.oauth2.GoogleCredentials
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.provider.Property
import org.gradle.api.services.BuildService
import org.gradle.api.services.BuildServiceParameters
import java.util.concurrent.locks.Lock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ import javax.inject.Inject

public abstract class TagCommitAndPublishToBeta : DefaultTask(), ServiceHolder {

@get:InputFile
public abstract val releaseBundle: RegularFileProperty

@get:InputFile
public abstract val releaseNotes: RegularFileProperty

@get:Input
public abstract val packageName: Property<String>

@get:Input
public abstract val currentVc: Property<Int>

@get:InputFile
public abstract val releaseBundle: RegularFileProperty

@get:InputFile
public abstract val releaseNotes: RegularFileProperty

@get:Inject
internal abstract val execOperations: ExecOperations

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ kotlin.code.style=official
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
android.enableR8.fullMode=true
agpVersion=8.1.0-rc01
agpVersion=8.1.0
kotlinVersion=1.8.22
coroutineVersion=1.7.2
daggerVersion=2.46.1
Expand Down

0 comments on commit a90f918

Please sign in to comment.