Skip to content

Commit a49a293

Browse files
authored
Merge pull request #17 from rfkhx/build/diff_channel
区分不同channel,保存数据到不同的db中
2 parents 7b13e5a + e2cb6ef commit a49a293

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

.github/workflows/push.yml

+8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ jobs:
1818
distribution: 'temurin'
1919
cache: gradle
2020

21+
- name: Select CHANNEL
22+
run: mkdir build; echo release > build/CHANNEL
2123
- name: Grant execute permission for gradlew
2224
run: chmod +x gradlew
2325
- name: Build with Gradle
@@ -46,6 +48,8 @@ jobs:
4648
distribution: 'temurin'
4749
cache: gradle
4850

51+
- name: Select CHANNEL
52+
run: mkdir build; echo release > build/CHANNEL
4953
- name: Grant execute permission for gradlew
5054
run: chmod +x gradlew
5155
- name: Build with Gradle
@@ -74,6 +78,8 @@ jobs:
7478
distribution: 'temurin'
7579
cache: gradle
7680

81+
- name: Select CHANNEL
82+
run: mkdir build; echo release > build/CHANNEL
7783
- name: Grant execute permission for gradlew
7884
run: chmod +x gradlew
7985
- name: Build with Gradle
@@ -102,6 +108,8 @@ jobs:
102108
distribution: 'temurin'
103109
cache: gradle
104110

111+
- name: Select CHANNEL
112+
run: mkdir build; echo release > build/CHANNEL
105113
- name: Grant execute permission for gradlew
106114
run: chmod +x gradlew
107115
- name: Build with Gradle

common/build.gradle.kts

+9
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ plugins {
1111

1212
val appVersionCode: String by ext
1313
val appVersionName: String by ext
14+
val channel by lazy {
15+
try {
16+
File(rootProject.projectDir, "build/CHANNEL").readText().trim().ifBlank { "local_test" }
17+
} catch (e: Exception) {
18+
e.printStackTrace()
19+
"local_test"
20+
}
21+
}
1422

1523
group = "top.ntutn"
1624
version = appVersionName
@@ -94,6 +102,7 @@ val generateAppInfoFile = tasks.register("generateAppInfoFile") {
94102
object AppInfo {
95103
const val VERSION_CODE = $appVersionCode
96104
const val VERSION_NAME = "$appVersionName"
105+
const val CHANNEL = "$channel"
97106
}
98107
""".trimIndent()
99108
val appInfoDir = File(project.buildDir, "generated/source/appInfo")

common/src/commonMain/kotlin/top/ntutn/common/ui/AboutPage.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ import androidx.compose.ui.Modifier
1010
@Composable
1111
fun AboutPage() {
1212
Column(modifier = Modifier.fillMaxSize()) {
13-
Text("海瑞待办 ${AppInfo.VERSION_NAME}")
13+
Text("海瑞待办 ${AppInfo.VERSION_NAME}, channel=${AppInfo.CHANNEL}")
1414
}
1515
}

common/src/desktopMain/kotlin/top/ntutn/common/DriverFactory.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package top.ntutn.common
22

3+
import AppInfo
34
import com.google.auto.service.AutoService
45
import com.squareup.sqldelight.db.SqlDriver
56
import com.squareup.sqldelight.sqlite.driver.JdbcSqliteDriver
@@ -22,7 +23,7 @@ class DriverFactory: IDriverFactory {
2223
configFolder
2324
}
2425

25-
private val sqliteFile get() = File(currentConfigDir, "todo.db")
26+
private val sqliteFile get() = File(currentConfigDir, if(AppInfo.CHANNEL == "local_test") "todo_test.db" else "todo.db")
2627
private val sqliteUrl get() = "jdbc:sqlite:${sqliteFile.canonicalPath}"
2728

2829
override fun createDriver(): SqlDriver {

0 commit comments

Comments
 (0)