Skip to content

Commit

Permalink
extract old version from git tags
Browse files Browse the repository at this point in the history
  • Loading branch information
premnirmal committed Feb 13, 2022
1 parent 94172f0 commit 896bff2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
17 changes: 17 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ def getVersionName = { ->
}
}

def getOldGitVersion = { ->
try {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'sh', '-c', 'git tag --sort=-committerdate | head -5 | tail -1'
standardOutput = stdout
}
return stdout.toString().trim()
}
catch (ignored) {
return null;
}
}

android {
compileSdkVersion 31
buildToolsVersion "31.0.0"
Expand All @@ -51,6 +65,7 @@ android {
def final minor = name.split("\\.")[1].toInteger()
def final patch = name.split("\\.")[2].toInteger()
def final code = (major * 100000000) + (minor * 100000) + patch
def final oldGitVersion = getOldGitVersion()
def final appIdBase = "com.github.premnirmal.tickerwidget"

defaultConfig {
Expand All @@ -63,6 +78,8 @@ android {
versionName = name
multiDexEnabled true

buildConfigField "String", "PREVIOUS_VERSION", "\"$oldGitVersion\""

javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ class CommitsProvider @Inject constructor(
return withContext(Dispatchers.IO) {
try {
val currentVersion = BuildConfig.VERSION_NAME
val major = currentVersion.split("\\.")[0].toInt()
val minor = currentVersion.split("\\.")[1].toInt()
val patch = currentVersion.split("\\.")[2].toInt()
val previousVersion = "$major.$minor.${patch - 2}"
val previousVersion = BuildConfig.PREVIOUS_VERSION
val comparison = githubApi.compareTags(
previousVersion, currentVersion
)
Expand Down

0 comments on commit 896bff2

Please sign in to comment.