Skip to content

Commit

Permalink
Add versioning code
Browse files Browse the repository at this point in the history
  • Loading branch information
nikteg committed Feb 4, 2019
1 parent cf4a7c6 commit 5d20b7b
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

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

5 changes: 5 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
applicationVariants.all { variant ->
variant.outputs.all {
outputFileName = "${variant.name}-${variant.versionName}.apk"
}
}
}

ext.anko_version='0.10.8'
Expand Down
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

apply from: 'versioning.gradle'

buildscript {
ext.kotlin_version = '1.3.11'
repositories {
Expand Down
21 changes: 5 additions & 16 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# Kotlin code style for this project: "official" or "obsolete":
#Mon Feb 04 16:51:32 CET 2019
appVersionCode=1
kotlin.code.style=official

android.enableJetifier=true
org.gradle.jvmargs=-Xmx1536m
android.useAndroidX=true
android.enableJetifier=true
appVersionName=1.0.0
72 changes: 72 additions & 0 deletions versioning.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
def getVersionName = { getVersionProps()['appVersionName'] }

def getVersionProps() {
def versionPropsFile = file('gradle.properties')
if (!versionPropsFile.exists()) {
versionPropsFile.createNewFile()
}
def versionProps = new Properties()
versionProps.load(new FileInputStream(versionPropsFile))
return versionProps
}

def getVersionNamePatch = { (getVersionName() =~ /\d+/)[2].toInteger() }

def getVersionNameMinor = { (getVersionName() =~ /\d+/)[1].toInteger() }

def getVersionNameMajor = { (getVersionName() =~ /\d+/)[0].toInteger() }

private void commitAndSetTag(versionName) {
Process addChanges = ['git', 'add', 'app/gradle.properties'].execute(null, project.rootDir)
addChanges.waitForProcessOutput(System.out, System.err)

Process createCommit = ['git', 'commit', "-m Release ${versionName}"].execute(null, project.rootDir)
createCommit.waitForProcessOutput(System.out, System.err)

Process createTag = ['git', 'tag', "v${versionName}".toString()].execute(null, project.rootDir)
createTag.waitForProcessOutput(System.out, System.err)
}

private def getAppVersionCode() { getVersionProps()['appVersionCode'].toInteger() }

private void save(major, minor, patch, versionCode) {
save("${major}.${minor}.${patch}".toString(), versionCode.toString())
}

private void save(versionName, versionCode) {
def versionProps = getVersionProps()
versionProps['appVersionName'] = versionName
versionProps['appVersionCode'] = versionCode
versionProps.store(file('gradle.properties').newWriter(), null)
commitAndSetTag(versionName)
}

task bumperInit() {
group = 'bumper'
doLast {
def versionName = project.hasProperty('bumperVersionName') ? bumperVersionName : '1.0.0'
def versionCode = project.hasProperty('bumperVersionCode') ? bumperVersionCode : '1'
save(versionName, versionCode)
}
}

task bumperVersionPatch () {
group = 'bumper'
doLast {
save(getVersionNameMajor(), getVersionNameMinor(), getVersionNamePatch() + 1, getAppVersionCode() + 1)
}
}

task bumperVersionMinor () {
group = 'bumper'
doLast {
save(getVersionNameMajor(), getVersionNameMinor() + 1, 0, getAppVersionCode() + 1)
}
}

task bumperVersionMajor () {
group = 'bumper'
doLast {
save(getVersionNameMajor() + 1, 0, 0, getAppVersionCode() + 1)
}
}

0 comments on commit 5d20b7b

Please sign in to comment.