Skip to content
This repository has been archived by the owner on Sep 30, 2023. It is now read-only.

Commit

Permalink
Adding publishBundle task (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergej Shafarenka committed Oct 10, 2018
1 parent a4d14b6 commit 827fd5d
Show file tree
Hide file tree
Showing 14 changed files with 331 additions and 130 deletions.
4 changes: 2 additions & 2 deletions .gitignore
@@ -1,6 +1,6 @@
./build/
build/
!autoplay/src/test/resources/sample-app/app/build/

autoplay/build/
captures/
out/
userHome/
Expand Down
8 changes: 4 additions & 4 deletions autoplay/build.gradle.kts
Expand Up @@ -12,10 +12,10 @@ repositories {
}

dependencies {
compileOnly("com.android.tools.build:gradle:3.0.1")
compileOnly("com.android.tools.build:gradle:3.2.0")

implementation(kotlin("stdlib", "1.2.61"))
implementation("com.google.apis:google-api-services-androidpublisher:v3-rev12-1.23.0")
implementation(kotlin("stdlib", "1.2.71"))
implementation("com.google.apis:google-api-services-androidpublisher:v3-rev30-1.25.0")

testImplementation("junit:junit:4.12")
testImplementation("com.google.truth:truth:0.40")
Expand All @@ -33,7 +33,7 @@ gradlePlugin {
}

group = "de.halfbit"
version = "0.3.3"
version = "1.0.0"

publishing {

Expand Down
@@ -1,5 +1,22 @@
/*
* Copyright (C) 2018 Sergej Shafarenka, www.halfbit.de
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package de.halfbit.tools.autoplay

import de.halfbit.tools.autoplay.publisher.ArtifactType
import de.halfbit.tools.autoplay.publisher.ReleaseStatus

internal const val RELEASE_NOTES_PATH = "src/main/autoplay/release-notes"
Expand All @@ -11,4 +28,5 @@ internal open class AutoplayPublisherExtension {
var secretJsonBase64: String? = null
var secretJsonPath: String? = null
var releaseNotesPath: String? = RELEASE_NOTES_PATH
var artifactType = ArtifactType.Apk.name
}
@@ -1,3 +1,19 @@
/*
* Copyright (C) 2018 Sergej Shafarenka, www.halfbit.de
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package de.halfbit.tools.autoplay

import com.android.build.gradle.AppExtension
Expand Down Expand Up @@ -29,30 +45,59 @@ internal class PlayPublisherPlugin : Plugin<Project> {
val applicationVariant = this@whenObjectAdded
val variantName = name.capitalize()

project.createTask("publishApk$variantName", PublishApkTask::class) {
description = "Publish $variantName apk, mapping and release-notes to Google Play."
group = TASK_GROUP

applicationId = applicationVariant.applicationId
artifactFiles = getArtifactFiles()
obfuscationMappingFile = getObfuscationMappingFile()
releaseTrack = extension.getReleaseTrack()
releaseStatus = extension.getReleaseStatus()
releaseNotes = extension.getReleaseNotes(project.projectDir)
credentials = extension.getCredentials()
when (extension.artifactType) {
ArtifactType.Apk.name -> {
project.createTask("publishApk$variantName", PublishTask::class) {
description = "Publish $variantName apk, mapping and release-notes to Google Play."
group = TASK_GROUP

applicationId = applicationVariant.applicationId
artifactType = ArtifactType.Apk
artifacts = collectArtifacts(ArtifactType.Apk, project)
obfuscationMappingFile = getObfuscationMappingFile()
releaseTrack = extension.getReleaseTrack()
releaseStatus = extension.getReleaseStatus()
releaseNotes = extension.getReleaseNotes(project.projectDir)
credentials = extension.getCredentials()
}
}

ArtifactType.Bundle.name -> {
project.createTask("publishBundle$variantName", PublishTask::class) {
description = "Publish $variantName bundle and release-notes to Google Play."
group = TASK_GROUP

applicationId = applicationVariant.applicationId
artifactType = ArtifactType.Bundle
artifacts = collectArtifacts(ArtifactType.Bundle, project)
releaseTrack = extension.getReleaseTrack()
releaseStatus = extension.getReleaseStatus()
releaseNotes = extension.getReleaseNotes(project.projectDir)
credentials = extension.getCredentials()
}
}
}
}

}

companion object {

private const val MINIMAL_ANDROID_PLUGIN_VERSION = "3.0.1"

private fun ApplicationVariant.getArtifactFiles(): List<File> {
return this.outputs
.filterIsInstance<ApkVariantOutput>()
.map { it.outputFile }
private fun ApplicationVariant.collectArtifacts(
artifactType: ArtifactType, project: Project
): List<File> {

return when (artifactType) {
ArtifactType.Apk -> this.outputs
.filterIsInstance<ApkVariantOutput>()
.map { it.outputFile }

ArtifactType.Bundle -> {
val archivesBaseName = project.properties["archivesBaseName"] as String
listOf(File(project.buildDir, "outputs/bundle/$name/$archivesBaseName.aab"))
}
}
}

private fun ApplicationVariant.getObfuscationMappingFile(): File? {
Expand Down

This file was deleted.

86 changes: 86 additions & 0 deletions autoplay/src/main/kotlin/de/halfbit/tools/autoplay/PublishTask.kt
@@ -0,0 +1,86 @@
/*
* Copyright (C) 2018 Sergej Shafarenka, www.halfbit.de
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package de.halfbit.tools.autoplay

import de.halfbit.tools.autoplay.publisher.*
import de.halfbit.tools.autoplay.publisher.v3.V3GooglePlayPublisher
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.*
import org.gradle.api.tasks.incremental.IncrementalTaskInputs
import java.io.File

internal open class PublishTask : DefaultTask() {

@get:Input
lateinit var artifactType: ArtifactType

@get:InputFiles
@get:PathSensitive(PathSensitivity.ABSOLUTE)
lateinit var artifacts: List<File>

@get:Optional
@get:InputFile
var obfuscationMappingFile: File? = null

@get:Input
lateinit var releaseNotes: List<ReleaseNotes>

@get:Input
lateinit var applicationId: String

@get:Input
lateinit var credentials: Credentials

@get:Input
lateinit var releaseTrack: ReleaseTrack

@get:Input
var releaseStatus: ReleaseStatus = ReleaseStatus.Completed

@TaskAction
@Suppress("UNUSED_PARAMETER", "unused")
fun execute(inputs: IncrementalTaskInputs) {
credentials.validate()

V3GooglePlayPublisher
.getGooglePlayPublisher(credentials, applicationId)
.publish(
ReleaseData(
applicationId,
artifacts.map { it.toReleaseArtifact(artifactType) },
obfuscationMappingFile,
releaseNotes,
releaseStatus,
releaseTrack
)
)
}

}

private fun File.toReleaseArtifact(artifactType: ArtifactType): ReleaseArtifact = when (artifactType) {
ArtifactType.Apk -> ReleaseArtifact.Apk(this)
ArtifactType.Bundle -> ReleaseArtifact.Bundle(this)
}

private fun Credentials.validate() {
if (!secretJson.isNullOrEmpty() && !secretJsonPath.isNullOrEmpty()) {
error("Either $EXTENSION_NAME { secretJsonBase64 } or" +
" $EXTENSION_NAME { secretJsonPath } must be specified, never both.")
}
}

@@ -1,3 +1,19 @@
/*
* Copyright (C) 2018 Sergej Shafarenka, www.halfbit.de
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package de.halfbit.tools.autoplay.publisher

import java.io.File
Expand All @@ -11,7 +27,7 @@ internal interface GooglePlayPublisher {

internal class ReleaseData(
val applicationId: String,
val artifacts: List<File>,
val artifacts: List<ReleaseArtifact>,
val obfuscationMappingFile: File?,
val releaseNotes: List<ReleaseNotes>,
val releaseStatus: ReleaseStatus,
Expand All @@ -31,6 +47,16 @@ internal sealed class ReleaseTrack(val name: String) : Serializable {
object Production : ReleaseTrack("production")
}

internal sealed class ReleaseArtifact(val file: File) {
class Apk(file: File) : ReleaseArtifact(file)
class Bundle(file: File) : ReleaseArtifact(file)
}

internal sealed class ArtifactType(val name: String) : Serializable {
object Apk : ArtifactType("apk")
object Bundle : ArtifactType("bundle")
}

internal sealed class ReleaseStatus(val name: String) : Serializable {
object Completed : ReleaseStatus("completed")
object Draft : ReleaseStatus("draft")
Expand Down

0 comments on commit 827fd5d

Please sign in to comment.