From e72912511116e8f5de3f443c4e2fe56e9573d693 Mon Sep 17 00:00:00 2001 From: Super12138 <70494801+Super12138@users.noreply.github.com> Date: Tue, 4 Feb 2025 16:38:06 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=80=82=E9=85=8D=20CI=20=E6=9E=84?= =?UTF-8?q?=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle.kts | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 56afb9d..fecda5a 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -10,21 +10,43 @@ ksp { arg("room.schemaLocation", "$projectDir/schemas") } +// 配置版本信息 +val baseVersionName = "compose-refactor" +val commitHash by lazy { "git rev-parse --short HEAD".exec() } +val verCode by lazy { "git rev-list --count HEAD".exec().toInt() } + android { namespace = "cn.super12138.todo" compileSdk = 35 + // 获取 Release 签名 + val releaseSigning = if (project.hasProperty("releaseStoreFile")) { + signingConfigs.create("release") { + storeFile = File(project.properties["releaseStoreFile"] as String) + storePassword = project.properties["releaseStorePassword"] as String + keyAlias = project.properties["releaseKeyAlias"] as String + keyPassword = project.properties["releaseKeyPassword"] as String + } + } else { + signingConfigs.getByName("debug") + } + defaultConfig { applicationId = "cn.super12138.todo" minSdk = 24 targetSdk = 35 - versionCode = 1 - versionName = "1.0" + versionCode = verCode + versionName = "${baseVersionName}-${commitHash}" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + + base.archivesName.set("todo-${baseVersionName}") } buildTypes { + all { + signingConfig = releaseSigning + } release { isMinifyEnabled = true isShrinkResources = true @@ -96,4 +118,11 @@ dependencies { androidTestImplementation(libs.androidx.ui.test.junit4) debugImplementation(libs.androidx.ui.tooling) debugImplementation(libs.androidx.ui.test.manifest) -} \ No newline at end of file +} + +// 命令执行工具类 +fun String.exec(): String = exec(this) + +fun Project.exec(command: String): String = providers.exec { + commandLine(command.split(" ")) +}.standardOutput.asText.get().trim() \ No newline at end of file