Skip to content

Commit

Permalink
Fix #55 and update dependencies (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
mirland authored Oct 26, 2020
1 parent 1ceeb3f commit 57c99d5
Show file tree
Hide file tree
Showing 20 changed files with 195 additions and 150 deletions.
15 changes: 10 additions & 5 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ Change Log
==========
All notable changes to this project will be documented in this file.

[Version 2.2.0 _UNDELIVERED_](https://github.com/xmartlabs/android-snapshot-publisher/releases/tag/v2.2.0)
- Upgrade Google Play Publisher dependency to [v3.0.0](https://github.com/Triple-T/gradle-play-publisher/releases/tag/3.0.0).
- Change min required gradle version to `6.5.0`.
- Change min Android Gradle plugin gradle version to `4.1.0`.

---

[Version 2.1.0 _(2020-01-31)_](https://github.com/xmartlabs/android-snapshot-publisher/releases/tag/v2.1.0)
---

Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ snapshotPublisher {
This value can be updated using these optional variables.
For example, if you want to keep the current version name and the hash commit and add a custom suffix such as `-SNAPSHOT`, you must assign the value `'{currentVersionName}-{commitHash}-SNAPSHOT'` to the `versionNameFormat` variable.

**Known Issue:** after AGP 4.1 the version name cannot be applied only to specific plugin tasks.
In turn, it's applied in the configuration step, causing all builds to contain `versionNameFormat`.
AGP 4.2 fixes this issue but is still in alpha.
If you're using a lower version of AGP, you can use the version of [2.1.0](https://github.com/xmartlabs/android-snapshot-publisher/releases/tag/v2.1.0).

### Release notes
The `releaseNotes` block allows you to perform build release notes customizations.
All fields in that block are optional and their default values are:
Expand Down
20 changes: 13 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@ buildscript {
plugins {
id("com.gradle.plugin-publish") version "0.10.1"
`kotlin-dsl`
kotlin("jvm") version "1.4.10"
groovy
id("io.gitlab.arturbosch.detekt") version "1.0.1"
jacoco
`java-gradle-plugin`
`maven-publish`
id("com.github.ben-manes.versions") version "0.25.0"
id("com.github.ben-manes.versions") version "0.33.0"
}

apply(from = "./scripts/dependency_updates.gradle")

repositories {
gradlePluginPortal()
google()
Expand All @@ -26,16 +29,19 @@ repositories {
}

dependencies {
compileOnly("com.android.tools.build:gradle:3.5.0")
compileOnly("com.android.tools.build:gradle:4.1.0") // Compile only to not force a specific AGP version

detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.0.0-RC12")

implementation("com.github.triplet.gradle:play-publisher:2.6.2")
implementation("com.google.apis:google-api-services-androidpublisher:v3-rev46-1.25.0")
implementation("com.google.firebase:firebase-appdistribution-gradle:1.0.0")
implementation("com.github.triplet.gradle:android-publisher:3.0.0")
implementation("com.github.triplet.gradle:play-publisher:3.0.0")
implementation("com.google.apis:google-api-services-androidpublisher:v3-rev20200526-1.30.9")
implementation("com.google.firebase:firebase-appdistribution-gradle:2.0.1")
implementation("com.google.guava:guava:29.0-jre")

testImplementation("com.android.tools.build:gradle:3.5.0")
testImplementation("junit:junit:4.12")
testImplementation("com.android.tools.build:gradle:4.1.0")
testImplementation( "org.mockito:mockito-inline:3.5.15")
testImplementation("junit:junit:4.13")
testImplementation("org.assertj:assertj-core:3.11.1")
testImplementation("org.eclipse.jgit:org.eclipse.jgit:3.5.0.201409260305-r")
testImplementation("org.jetbrains.kotlin:kotlin-test")
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
29 changes: 12 additions & 17 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -154,19 +154,19 @@ if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
i=`expr $i + 1`
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
0) set -- ;;
1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi

Expand All @@ -175,14 +175,9 @@ save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")
APP_ARGS=`save "$@"`

# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"

# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi

exec "$JAVACMD" "$@"
23 changes: 23 additions & 0 deletions scripts/dependency_updates.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apply plugin: "com.github.ben-manes.versions"

def isNonStable = { String version ->
return ['alpha', 'beta', 'rc', 'cr', 'm', 'preview', 'b', 'ea'].any { qualifier ->
version ==~ /(?i).*[.-]$qualifier[.\d-+]*/
}
}

dependencyUpdates {
resolutionStrategy {
componentSelection {
all {
if (isNonStable(candidate.version) && !isNonStable(currentVersion)) {
reject('Release candidate')
}
}
}
}
checkForGradleUpdate = true
outputFormatter = "html"
outputDir = "build/reports/dependencyUpdates"
reportfileName = "report"
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ internal object Constants {
const val SNAPSHOT_PUBLISHER_EXTENSION_NAME = "snapshotPublisher"
const val PREPARE_APK_VERSION_TASK_NAME = "prepareApkSnapshotBuild"
const val PREPARE_BUNDLE_VERSION_TASK_NAME = "prepareBundleSnapshotBuild"
const val UPDATE_ANDROID_VERSION_NAME_TASK_NAME = "updateAndroidVersionName"
const val GENERATE_SNAPSHOT_RELEASE_NOTES_TASK_NAME = "generateSnapshotReleaseNotes"

private const val OUTPUT_PATH = "snapshot-publisher"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.xmartlabs.snapshotpublisher

import com.android.build.gradle.api.ApkVariantOutput
import com.android.build.gradle.api.ApplicationVariant
import com.xmartlabs.snapshotpublisher.model.FirebaseAppDistributionReleaseConfig
import com.xmartlabs.snapshotpublisher.model.GooglePlayConfig
Expand All @@ -12,7 +13,6 @@ import com.xmartlabs.snapshotpublisher.task.ErrorTask
import com.xmartlabs.snapshotpublisher.task.GenerateReleaseNotesTask
import com.xmartlabs.snapshotpublisher.task.PrepareFirebaseAppDistributionReleaseTask
import com.xmartlabs.snapshotpublisher.task.PrepareGooglePlayReleaseTask
import com.xmartlabs.snapshotpublisher.task.UpdateAndroidVersionNameTask
import com.xmartlabs.snapshotpublisher.utils.ErrorHelper
import com.xmartlabs.snapshotpublisher.utils.createTask
import com.xmartlabs.snapshotpublisher.utils.snapshotReleaseExtension
Expand Down Expand Up @@ -43,44 +43,35 @@ class SnapshotPublisherPlugin : Plugin<Project> {
}

private fun Project.createTasksForVariant(variant: ApplicationVariant) {
updateVariantVersionName(variant)
val assembleTask = AndroidPluginHelper.getAssembleTask(this, variant)
val bundleTask = AndroidPluginHelper.getBundleTask(this, variant)
val updateVersionNameTask = createAndroidVersionTask(variant, assembleTask, bundleTask)
val generateReleaseNotesTask = createGenerateReleaseNotesTask(variant, updateVersionNameTask)
val preparationTasks = listOf(generateReleaseNotesTask, updateVersionNameTask)
val generateReleaseNotesTask = createGenerateReleaseNotesTask(variant)
val preparationTasks = listOf(generateReleaseNotesTask)

createPrepareApkSnapshotTask(variant, assembleTask, preparationTasks)
if (bundleTask != null) {
val prepareBundleTask = if (bundleTask != null) {
createPrepareBundleSnapshotTask(variant, bundleTask, preparationTasks)
}
createGooglePlayDeployTask(variant, preparationTasks)
} else null
createGooglePlayDeployTask(variant, assembleTask, prepareBundleTask, preparationTasks)
createFirebaseDeployTask(variant, assembleTask, preparationTasks)
}

private fun Project.createGenerateReleaseNotesTask(
variant: ApplicationVariant? = null,
updateVersionNameTask: UpdateAndroidVersionNameTask? = null
variant: ApplicationVariant? = null
) = createTask<GenerateReleaseNotesTask>(
name = Constants.GENERATE_SNAPSHOT_RELEASE_NOTES_TASK_NAME + (variant?.capitalizedName ?: ""),
description = "Generates release notes"
) {
this.variant = variant
updateVersionNameTask?.mustRunAfter(this)
}

private fun Project.createAndroidVersionTask(
variant: ApplicationVariant,
assembleTask: Task,
bundleTask: Task?
) = createTask<UpdateAndroidVersionNameTask>(
name = "${Constants.UPDATE_ANDROID_VERSION_NAME_TASK_NAME}${variant.capitalizedName}",
description = "Update Android Version name"
) {
this.variant = variant
@Suppress("UnstableApiUsage")
assembleTask.mustRunAfter(this)
@Suppress("UnstableApiUsage")
bundleTask?.mustRunAfter(this)
private fun Project.updateVariantVersionName(variant: ApplicationVariant) {
// TODO: This should be changed in AGP 4.2. It allows to change it in a specific task.
val versionName = AndroidPluginHelper.getVersionName(project, variant)
variant.outputs.all {
(this as? ApkVariantOutput)?.versionNameOverride = versionName
}
}

private fun Project.createPrepareApkSnapshotTask(
Expand Down Expand Up @@ -109,6 +100,8 @@ class SnapshotPublisherPlugin : Plugin<Project> {

private fun Project.createGooglePlayDeployTask(
variant: ApplicationVariant,
assembleApkTask: Task,
appBundleTask: Task?,
preparationTasks: List<Task>
) {
if (variant.buildType.isDebuggable) {
Expand All @@ -123,21 +116,13 @@ class SnapshotPublisherPlugin : Plugin<Project> {
} else {
PlayPublisherPluginHelper.getPublishApkTask(this, variant)
}
val preparePublishTask = createTask<PrepareGooglePlayReleaseTask>(
name = "${Constants.PREPARE_GOOGLE_PLAY_SNAPSHOT_DEPLOY_TASK_NAME}${variant.capitalizedName}",
group = null,
description = "Prepare and deploy snapshot build to Google Play"
) {
this.variant = variant
this.publishGooglePlayTask = publishGooglePlayTask
val compilationTask = if (googlePlayConfig.defaultToAppBundles) appBundleTask else assembleApkTask

val generateResourcesTask = PlayPublisherPluginHelper.getGenerateResourcesTask(project, variant)
mustRunAfter(generateResourcesTask)
preparationTasks.forEach { task ->
generateResourcesTask.mustRunAfter(task)
dependsOn(task)
}
}
val preparePublishTask = createGooglePlayReleasePreparationTask(
variant,
publishGooglePlayTask,
(preparationTasks + compilationTask).requireNoNulls()
)

createTask<DefaultTask>(
name = "${Constants.GOOGLE_PLAY_SNAPSHOT_DEPLOY_TASK_NAME}${variant.capitalizedName}",
Expand All @@ -152,6 +137,28 @@ class SnapshotPublisherPlugin : Plugin<Project> {
}
}

private fun Project.createGooglePlayReleasePreparationTask(
variant: ApplicationVariant,
publishGooglePlayTask: Task,
preparationTasks: List<Task>
): PrepareGooglePlayReleaseTask = createTask<PrepareGooglePlayReleaseTask>(
name = "${Constants.PREPARE_GOOGLE_PLAY_SNAPSHOT_DEPLOY_TASK_NAME}${variant.capitalizedName}",
group = null,
description = "Prepare and deploy snapshot build to Google Play"
) {
this.variant = variant
this.publishGooglePlayTask = publishGooglePlayTask

val generateResourcesTask = PlayPublisherPluginHelper.getGenerateResourcesTask(project, variant)
mustRunAfter(generateResourcesTask)

preparationTasks
.forEach { task ->
generateResourcesTask.mustRunAfter(task)
dependsOn(task)
}
}

private fun Project.createGooglePlayErrorTask(
googlePlayConfig: GooglePlayConfig,
variant: ApplicationVariant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ open class ReleaseNotesConfig {
var commitHistoryFormat: String = Constants.RELEASE_NOTES_CONFIG_COMMIT_HISTORY_FORMAT_DEFAULT_VALUE
var historyFormat: String = Constants.RELEASE_NOTES_CONFIG_HISTORY_FORMAT_DEFAULT_VALUE
var maxCommitHistoryLines: Int = Constants.RELEASE_NOTES_CONFIG_MAX_COMMIT_HISTORY_LINES_DEFAULT_VALUE

@Suppress("MemberVisibilityCanBePrivate")
var releaseNotesFormat: String = Constants.RELEASE_NOTES_CONFIG_FORMAT_DEFAULT_VALUE
var outputFile: File? = Constants.RELEASE_NOTES_OUTPUT_FILE_DEFAULT_VALUE
Expand All @@ -28,7 +29,7 @@ open class ReleaseNotesConfig {
.replace(Constants.RELEASE_NOTES_HISTORY_KEY, history, true)
.replace(Constants.RELEASE_NOTES_COMMIT_HISTORY_KEY, changelog, true)

internal fun getVersion(versionName: String, versionCode: Int) = versionFormat
internal fun getVersion(versionName: String, versionCode: Int?) = versionFormat
.replace(Constants.RELEASE_NOTES_VERSION_NAME_KEY, versionName, true)
.replace(Constants.RELEASE_NOTES_VERSION_CODE_KEY, versionCode.toString(), true)
.replace(Constants.RELEASE_NOTES_VERSION_CODE_KEY, versionCode?.toString() ?: "", true)
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.xmartlabs.snapshotpublisher.plugin

import com.android.build.api.variant.VariantOutput
import com.android.build.gradle.AppExtension
import com.android.build.gradle.api.ApkVariantOutput
import com.android.build.gradle.api.ApplicationVariant
import com.google.common.annotations.VisibleForTesting
import com.xmartlabs.snapshotpublisher.model.VersionConfig
Expand All @@ -23,12 +23,12 @@ internal object AndroidPluginHelper {

fun getVersionName(project: Project, variant: ApplicationVariant? = null): String {
val releaseSetup = project.snapshotReleaseExtension
val versionNameOverride = variant?.outputs
?.map { (it as? ApkVariantOutput)?.versionNameOverride }
?.filterNot { it.isNullOrBlank() }
?.first()
val versionName = variant?.outputs
?.map { (it as? VariantOutput)?.versionName?.orNull }
?.filterNot(String?::isNullOrBlank)
?.firstOrNull()

val currentVersionName = versionNameOverride
val currentVersionName = versionName
.orElse { variant?.versionName }
.orElse { getAndroidExtension(project).defaultConfig.versionName }
.orEmpty()
Expand All @@ -40,7 +40,7 @@ internal object AndroidPluginHelper {
fun getVersionName(versionConfig: VersionConfig, currentVersionName: String) =
versionConfig.getVersionName(currentVersionName, GitHelper.getCommitHash(), GitHelper.getBranchName())

fun getVersionCode(project: Project, variant: ApplicationVariant? = null): Int =
fun getVersionCode(project: Project, variant: ApplicationVariant? = null): Int? =
variant?.versionCode ?: getAndroidExtension(project).defaultConfig.versionCode

fun getBundleTask(project: Project, variant: ApplicationVariant) =
Expand Down
Loading

0 comments on commit 57c99d5

Please sign in to comment.