gradle: have sensible defaults for the version information

This commit is contained in:
Jacker 2024-01-24 18:43:31 +02:00
parent 66f28f9188
commit b517866731
No known key found for this signature in database
GPG key ID: 1ACCC1587C75F319
2 changed files with 10 additions and 6 deletions

View file

@ -32,7 +32,7 @@ jobs:
uses: android-actions/setup-android@v3 uses: android-actions/setup-android@v3
- name: Build and publish - name: Build and publish
run: ./gradlew publish --no-daemon run: ./gradlew publish --no-daemon --info
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View file

@ -14,14 +14,16 @@ buildscript {
} }
def parseGitVersion() { def parseGitVersion() {
def major = 0 def major = 1
def minor = 0 def minor = 2
def patch = 0 def patch = 0
def postfix = 'UNKNOWN' def postfix = '-UNKNOWN'
def hash = '' def hash = ''
def output = 'git describe --long --tags --dirty --always'.execute().text.trim() def output = 'git describe --long --tags --dirty --always'.execute().text.trim()
project.logger.info("Ran git describe with the output: {}", output)
(output =~ /^v(\d+)\.(\d+)\.(\d+)-(\d+)-(\w+)/).each { match, majorVal, minorVal, patchVal, commitVal, hashVal -> (output =~ /^v(\d+)\.(\d+)\.(\d+)-(\d+)-(\w+)/).each { match, majorVal, minorVal, patchVal, commitVal, hashVal ->
if (output.toLowerCase().endsWith('-dirty')) { if (output.toLowerCase().endsWith('-dirty')) {
patchVal = (patchVal as int + 1) as String
postfix = '-DIRTY' postfix = '-DIRTY'
} else if(commit as int > 0) { } else if(commit as int > 0) {
patchVal = (patchVal as int + 1) as String patchVal = (patchVal as int + 1) as String
@ -35,7 +37,9 @@ def parseGitVersion() {
patch = patchVal as int patch = patchVal as int
hash = hashVal hash = hashVal
} }
return [version: "${major}.${minor}.${patch}${postfix}", hash: hash] def outputHash = [version: "${major}.${minor}.${patch}${postfix}", hash: hash]
project.logger.info("Parsed version: {}", outputHash.version)
return outputHash
} }
def versionInfo = parseGitVersion() def versionInfo = parseGitVersion()