From 12cbbf3e55a982d361d5ad51d7494854157ff6c9 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 5 May 2025 17:09:14 +0300 Subject: use git-based version like tt-rss proper --- org.fox.ttrss/build.gradle | 47 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) (limited to 'org.fox.ttrss/build.gradle') diff --git a/org.fox.ttrss/build.gradle b/org.fox.ttrss/build.gradle index b057a364..ab434f5e 100755 --- a/org.fox.ttrss/build.gradle +++ b/org.fox.ttrss/build.gradle @@ -15,7 +15,7 @@ android { targetSdkVersion 31 compileSdkVersion 35 versionCode 558 - versionName "1.323" + versionName getVersion() } signingConfigs { @@ -56,6 +56,51 @@ android { } } +def getGitTimestamp() { + // gitlab CI iso-8601 timestamp + if (System.getenv("CI_COMMIT_TIMESTAMP")) { + return Date.parse("yyyy-MM-dd'T'HH:mm:ssXXX", System.getenv("CI_COMMIT_TIMESTAMP")).format('YY.MM') + } + + // try to get version from git repo in current dir + try { + def stdout = new ByteArrayOutputStream() + exec { + commandLine 'git', '--no-pager', 'log', '--pretty=%ct', '-n1', 'HEAD' + standardOutput = stdout + } + + return new Date(stdout.toString().trim().toLong() * 1000).format('YY.MM') + } + catch (ignored) { + return 0; + } + +} + +def getGitCommitHash() { + // gitlab CI + if (System.getenv("CI_COMMIT_SHORT_SHA")) + return System.getenv("CI_COMMIT_SHORT_SHA"); + + // try to get version from git repo in current dir + try { + def stdout = new ByteArrayOutputStream() + exec { + commandLine 'git', '--no-pager', 'log', '--pretty=%h', '-n1', 'HEAD' + standardOutput = stdout + } + return stdout.toString().trim() + } + catch (ignored) { + return 'UNKNOWN'; + } +} + +def getVersion() { + return getGitTimestamp() + '-' + getGitCommitHash(); +} + dependencies { implementation 'com.squareup.okhttp3:okhttp:3.12.5' implementation('com.github.bumptech.glide:okhttp3-integration:1.5.0') { -- cgit v1.2.3-54-g00ecf