chore(versioning): derive Android versionName from git describe to match __APP_VERSION__ from vite

This commit is contained in:
heaven 2026-05-13 22:53:48 +03:00
parent 30e477d2cd
commit 5c16649e0c
3 changed files with 28 additions and 7 deletions

View file

@ -1,8 +1,29 @@
apply plugin: 'com.android.application' apply plugin: 'com.android.application'
def packageJson = new groovy.json.JsonSlurper().parseText(file('../../package.json').text) // Mirror of resolveAppVersion() in ../../vite.config.js so the APK's
def semver = packageJson.version.split('\\.') // versionName matches __APP_VERSION__ rendered in the About screen.
def computedVersionCode = semver[0].toInteger() * 1000000 + semver[1].toInteger() * 1000 + semver[2].toInteger() // `git describe --tags --match 'v*'` against tag v0.2.0 yields
// `v0.2.0-<commits>-g<hash>`; patch = commit count since the tag.
// Falls back to package.json only when git is unavailable.
def gitDescribe = providers.exec {
it.commandLine 'git', 'describe', '--tags', '--match', 'v*', '--always'
it.workingDir rootDir.parentFile
it.ignoreExitValue = true
}
def appVersion = {
def fromGit = gitDescribe.result.get().exitValue == 0 ? gitDescribe.standardOutput.asText.get().trim() : null
def m = fromGit =~ /^v?(\d+)\.(\d+)\.(\d+)(?:-(\d+)-g[0-9a-f]+)?$/
if (fromGit && m.matches()) {
def major = m[0][1].toInteger()
def minor = m[0][2].toInteger()
def patch = (m[0][4] ?: m[0][3]).toInteger()
return [name: "${major}.${minor}.${patch}", major: major, minor: minor, patch: patch]
}
def pkg = new groovy.json.JsonSlurper().parseText(file('../../package.json').text)
def parts = pkg.version.split('\\.')
return [name: pkg.version, major: parts[0].toInteger(), minor: parts[1].toInteger(), patch: parts[2].toInteger()]
}()
def computedVersionCode = appVersion.major * 1000000 + appVersion.minor * 1000 + appVersion.patch
android { android {
namespace = "chat.vojo.app" namespace = "chat.vojo.app"
@ -12,7 +33,7 @@ android {
minSdkVersion rootProject.ext.minSdkVersion minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion
versionCode computedVersionCode versionCode computedVersionCode
versionName packageJson.version versionName appVersion.name
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
aaptOptions { aaptOptions {
// Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps. // Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.

View file

@ -26,7 +26,7 @@ npm run android:apk:debug # gradle debug build only
## Versioning ## Versioning
`versionCode` and `versionName` auto-derived from `package.json` version: `versionCode` and `versionName` are derived from `git describe --tags --match 'v*'` in [`android/app/build.gradle`](../../android/app/build.gradle), mirroring `resolveAppVersion()` in [`vite.config.js`](../../vite.config.js) so the APK's `versionName` matches `__APP_VERSION__` shown in About. Tag is `v0.2.0`; `patch` is the commit count since that tag (e.g. `v0.2.0-87-g…` → versionName `0.2.87`). When git is unavailable, falls back to `package.json` `version`.
``` ```
versionCode = major * 1_000_000 + minor * 1_000 + patch versionCode = major * 1_000_000 + minor * 1_000 + patch

View file

@ -1,7 +1,7 @@
{ {
"name": "vojo", "name": "vojo",
"version": "4.11.1", "version": "0.2.0",
"description": "Yet another matrix client", "description": "Vojo client for matrix server",
"main": "index.js", "main": "index.js",
"type": "module", "type": "module",
"engines": { "engines": {