Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Clean up tasks, use new options/register APIs, truncate whatsnew
  • Loading branch information
ZacSweers committed Jul 14, 2018
1 parent ccd0b8c commit 01733f6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 23 deletions.
52 changes: 31 additions & 21 deletions app/build.gradle.kts
Expand Up @@ -223,17 +223,30 @@ tasks.withType<KotlinCompile> {

open class CutChangelogTask : DefaultTask() {

@Input
@get:Input
lateinit var versionName: String

@TaskAction
fun run() {
val changelog = project.rootProject.file("CHANGELOG.md")

val whatsNewPath = "${project.projectDir}/src/main/play/en-US/whatsnew"
val newChangelog = getChangelog(changelog, "")
if (newChangelog.length > 500) {
throw IllegalStateException("Changelog length exceeds 500ch max. Is ${newChangelog.length}")
val newChangelog = getChangelog(changelog, "").let {
if (it.length > 500) {
logger.log(LogLevel.WARN, "Changelog length (${it.length}) exceeds 500 char max. Truncating...")
val warning = "\n(Truncated due to store restrictions. Full changelog in app!)"
val warningLength = warning.length
val remainingAmount = 500 - warningLength
val builder = StringBuilder()
for (line in it.lineSequence()) {
if (builder.length + line.length + 1 < remainingAmount) {
builder.appendln(line)
} else {
break
}
}
builder.append(warning).toString()
} else it
}
if (!newChangelog.isEmpty()) {
project.file(whatsNewPath).writer().use {
Expand Down Expand Up @@ -269,12 +282,10 @@ open class CutChangelogTask : DefaultTask() {
}
}

tasks {
"cutChangelog"(CutChangelogTask::class) {
versionName = deps.build.gitTag(project)
group = "build"
description = "Cuts the current changelog version and updates the play store changelog file"
}
tasks.register("cutChangelog", CutChangelogTask::class.java) {
versionName = deps.build.gitTag(project)
group = "build"
description = "Cuts the current changelog version and updates the play store changelog file"
}

fun getChangelog(): String {
Expand Down Expand Up @@ -309,7 +320,9 @@ fun getChangelog(): String {
}

open class UpdateVersion : DefaultTask() {
@Input

@set:Option(option = "updateType", description = "Configures the version update type. Can be (major|minor|patch).")
@get:Input
lateinit var type: String

@TaskAction
Expand All @@ -321,20 +334,20 @@ open class UpdateVersion : DefaultTask() {
}
var (major, minor, patch) = latestTag.split(".").map(String::toInt)
when (type) {
"M" -> {
"major" -> {
major++
minor = 0
patch = 0
}
"m" -> {
"minor" -> {
minor++
patch = 0
}
"p" -> {
"patch" -> {
patch++
}
else -> {
throw IllegalArgumentException("Unrecognized version type \"$type\"")
throw IllegalArgumentException("Unrecognized updateType \"$type\"")
}
}
val latestVersionString = "$major.$minor.$patch"
Expand All @@ -356,12 +369,9 @@ open class UpdateVersion : DefaultTask() {
}
}

tasks {
"updateVersion"(UpdateVersion::class) {
type = properties["version"].toString()
group = "build"
description = "Updates the current version. Supports CLI property flag -Pversion={type} where type is (Mmp)"
}
tasks.create("updateVersion", UpdateVersion::class.java) {
group = "build"
description = "Updates the current version. Supports CLI option --updateType={type} where type is (major|minor|patch)"
}

dependencies {
Expand Down
4 changes: 2 additions & 2 deletions createRelease.sh
Expand Up @@ -14,7 +14,7 @@ trap cleanup EXIT
WORKING_DIR=`pwd`

#### CLI options
# -t Can be set to (Mmp) for version updates
# -t Can be set to (major|minor|patch) for version updates
VERSION_UPDATE_TYPE=""
# -c Updates changelog with a new cut, off by default
UPDATE_CHANGELOG=false
Expand Down Expand Up @@ -109,7 +109,7 @@ if [[ ! -z ${VERSION_UPDATE_TYPE} ]]
then
# Update the version first. Easiest to do this in gradle because my bash-fu is not great
echo "Updating version '${VERSION_UPDATE_TYPE}' via gradle..."
execIfNotDry execGradle :app:updateVersion -Pversion=${VERSION_UPDATE_TYPE}
execIfNotDry execGradle :app:updateVersion -updateType=${VERSION_UPDATE_TYPE}
fi

#### Changelog cuts
Expand Down

0 comments on commit 01733f6

Please sign in to comment.