Skip to content

Commit 1b278ca

Browse files
hannesa2niqdev
andauthored
Automatic version code (#115)
Co-authored-by: niqdev <niqdev@users.noreply.github.com>
1 parent abf09d5 commit 1b278ca

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ android {
77
applicationId "com.github.niqdev.ipcam"
88
minSdkVersion 16
99
targetSdkVersion 28
10-
versionCode 12
11-
versionName "1.9.0"
10+
versionCode getGitCommitCount()
11+
versionName getTag()
1212
}
1313

1414
buildTypes {

build.gradle

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ buildscript {
1111

1212
allprojects {
1313
group = 'com.github.niqdev'
14-
version = '1.7.0'
14+
version = getTag()
1515

1616
repositories {
1717
google()
@@ -22,3 +22,21 @@ allprojects {
2222
task clean(type: Delete) {
2323
delete rootProject.buildDir
2424
}
25+
26+
@SuppressWarnings("unused")
27+
static def getGitCommitCount() {
28+
def process = "git rev-list HEAD --count".execute()
29+
return process.text.toInteger()
30+
}
31+
32+
@SuppressWarnings("unused")
33+
static def getTag() {
34+
// with local un-commited changes a -DIRTY is added
35+
def processChanges = "git diff-index --name-only HEAD --".execute()
36+
def dirty = ""
37+
if (!processChanges.text.toString().trim().isEmpty())
38+
dirty = "-DIRTY"
39+
40+
def process = "git describe --tags".execute()
41+
return process.text.toString().trim() + dirty
42+
}

mjpeg-view/build.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ android {
66
defaultConfig {
77
minSdkVersion 16
88
targetSdkVersion 28
9-
versionCode 1
10-
versionName project.version
9+
versionName getTag()
1110
}
1211

1312
compileOptions {

0 commit comments

Comments
 (0)