Skip to content

Commit e3e0b18

Browse files
committed
example: Set versionCode as git commit count
1 parent 8d824c5 commit e3e0b18

File tree

4 files changed

+48
-4
lines changed

4 files changed

+48
-4
lines changed

.github/workflows/simple.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ jobs:
1111
steps:
1212
- name: Checkout
1313
uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0
1416
- name: Set up JDK
1517
uses: actions/setup-java@v4
1618
with:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ local.properties
1010
xcuserdata
1111
.kotlin
1212
*.lock
13+
composeApp/src/commonMain/kotlin/utils/VersionInfo.kt

composeApp/build.gradle.kts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.android.build.gradle.internal.api.BaseVariantOutputImpl
44
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
55
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
66
import org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFramework
7+
import java.io.ByteArrayOutputStream
78
import java.util.Properties
89

910
plugins {
@@ -16,6 +17,7 @@ plugins {
1617
val appName = "Miuix"
1718
val pkgName = "top.yukonga.miuix.uitest"
1819
val verName = "1.0.2"
20+
val verCode = getVersionCode()
1921
val xcf = XCFramework(appName + "Framework")
2022

2123
kotlin {
@@ -101,7 +103,7 @@ android {
101103
applicationId = pkgName
102104
minSdk = libs.versions.android.minSdk.get().toInt()
103105
targetSdk = libs.versions.android.targetSdk.get().toInt()
104-
versionCode = 21
106+
versionCode = verCode
105107
versionName = verName
106108
}
107109
val properties = Properties()
@@ -168,6 +170,40 @@ compose.desktop {
168170
}
169171
}
170172

173+
174+
fun getGitCommitCount(): Int {
175+
val out = ByteArrayOutputStream()
176+
exec {
177+
commandLine("git", "rev-list", "--count", "HEAD")
178+
standardOutput = out
179+
}
180+
return out.toString().trim().toInt()
181+
}
182+
183+
fun getVersionCode(): Int {
184+
return getGitCommitCount()
185+
}
186+
187+
val generateVersionInfo by tasks.registering {
188+
doLast {
189+
val file = file("src/commonMain/kotlin/utils/VersionInfo.kt")
190+
file.writeText(
191+
"""
192+
package misc
193+
194+
object VersionInfo {
195+
const val VERSION_NAME = "$verName"
196+
const val VERSION_CODE = $verCode
197+
}
198+
""".trimIndent()
199+
)
200+
}
201+
}
202+
203+
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
204+
dependsOn(generateVersionInfo)
205+
}
206+
171207
tasks.register<Exec>("assembleMiuixMacosArm64ReleaseBinary") {
172208
dependsOn(":composeApp:desktopTest", ":composeApp:linkReleaseExecutableMacosArm64")
173209
commandLine("lipo", "-create", "-output", "Miuix_macOSArm64", "bin/macosArm64/releaseExecutable/Miuix.kexe")

composeApp/src/commonMain/kotlin/ThirdPage.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ import androidx.compose.runtime.Composable
55
import androidx.compose.runtime.MutableState
66
import androidx.compose.ui.Modifier
77
import androidx.compose.ui.unit.dp
8+
import misc.VersionInfo
89
import top.yukonga.miuix.kmp.basic.Card
910
import top.yukonga.miuix.kmp.basic.LazyColumn
1011
import top.yukonga.miuix.kmp.basic.ScrollBehavior
12+
import top.yukonga.miuix.kmp.basic.SmallTitle
1113
import top.yukonga.miuix.kmp.extra.SuperDropdown
1214
import top.yukonga.miuix.kmp.extra.SuperSwitch
1315
import top.yukonga.miuix.kmp.utils.getWindowSize
@@ -37,7 +39,7 @@ fun ThirdPage(
3739
Card(
3840
modifier = Modifier
3941
.padding(horizontal = 12.dp)
40-
.padding(top = 12.dp, bottom = 12.dp + padding.calculateBottomPadding())
42+
.padding(top = 12.dp, bottom = 6.dp)
4143
) {
4244
SuperSwitch(
4345
title = "Show FPS Monitor",
@@ -68,10 +70,13 @@ fun ThirdPage(
6870
title = "Color Mode",
6971
items = listOf("System", "Light", "Dark"),
7072
selectedIndex = colorMode.value,
71-
onSelectedIndexChange = { colorMode.value = it },
72-
horizontalPadding = 12.dp
73+
onSelectedIndexChange = { colorMode.value = it }
7374
)
7475
}
76+
SmallTitle(
77+
modifier = Modifier.padding(bottom = 6.dp + padding.calculateBottomPadding()),
78+
text = "Current Version: " + VersionInfo.VERSION_NAME + " (" + VersionInfo.VERSION_CODE + ")"
79+
)
7580
}
7681
}
7782
}

0 commit comments

Comments
 (0)