From 22cd651405003db1a1d51006fde6938f64a0c142 Mon Sep 17 00:00:00 2001 From: Balazs Toldi Date: Wed, 6 Oct 2021 21:06:54 +0200 Subject: [PATCH] Changed version number to git commit count Signed-off-by: Balazs Toldi --- app/build.gradle | 3 +-- build.gradle | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 63417d2..f0caff0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -5,12 +5,11 @@ plugins { android { compileSdk 31 - defaultConfig { applicationId "eu.toldi.balazs.anotherfeedreader" minSdk 26 targetSdk 31 - versionCode 1 + versionCode project.getVersionCode() versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" diff --git a/build.gradle b/build.gradle index 5f8f4c3..cba324d 100644 --- a/build.gradle +++ b/build.gradle @@ -18,4 +18,18 @@ buildscript { task clean(type: Delete) { delete rootProject.buildDir +} + +ext.getVersionCode = { -> + try { + def stdout = new ByteArrayOutputStream() + exec { + commandLine 'git', 'rev-list', '--first-parent', '--count', 'origin/main' + standardOutput = stdout + } + return Integer.parseInt(stdout.toString().trim()) + } + catch (ignored) { + return -1; + } } \ No newline at end of file