Skip to content

Commit 1d1cb63

Browse files
committed
Generate versionCode from number of commits
1 parent 378efdd commit 1d1cb63

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

app/calendar-widget/build.gradle

+19-6
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ android {
2525
buildToolsVersion '22.0.1'
2626

2727
defaultConfig {
28-
versionName = '1.9.2' + getGitCommitId()
29-
versionCode = 30
28+
versionName = '1.9.2' + getVersionNameSuffix()
29+
versionCode = getVersionCodeInteger()
3030
minSdkVersion 15
3131
targetSdkVersion 22
3232

@@ -61,11 +61,24 @@ android {
6161
}
6262
}
6363

64-
Object getGitCommitId() {
64+
String getVersionNameSuffix() {
6565
try {
6666
def git = org.ajoberstar.grgit.Grgit.open(dir: '../..')
67-
return "-${git.head().abbreviatedId}"
68-
} catch (Exception) {
67+
def versionNameSuffix = "-${git.head().abbreviatedId}"
68+
git.close()
69+
return versionNameSuffix
70+
} catch (ignored) {
6971
return ""
7072
}
71-
}
73+
}
74+
75+
def getVersionCodeInteger() {
76+
try {
77+
def git = org.ajoberstar.grgit.Grgit.open(dir: '../..')
78+
def versionCode = git.log().size()
79+
git.close()
80+
return versionCode
81+
} catch (ignored) {
82+
return 1
83+
}
84+
}

0 commit comments

Comments
 (0)