Updater: similar to Mihon

- Preview version now name Beta, use different package & repo
- Drop syDebugVersion, use commitCount
- Fix Firebase analytics for both Release & Preview build
- Create separate variant for Preview build instead of using syDebugVersion
- Preview version showing changelog_debug.xml
- Release version showing changelog_release.xml
This commit is contained in:
Cuong M. Tran 2024-05-08 11:42:21 +07:00
parent 4161b6cac9
commit 1eefa745ea
No known key found for this signature in database
GPG key ID: 733AA7624B9315C2
13 changed files with 169 additions and 86 deletions

View file

@ -68,13 +68,6 @@ jobs:
changelog="<?xml version=\"1.0\" encoding=\"utf-8\"?><changelog bulletedList=\"true\"><changelogversion versionName=\"${{ github.run_number }}\" changeDate=\"\">$changelog</changelogversion></changelog>"
echo "CHANGELOG=$changelog" >> $GITHUB_ENV
- name: Write Version.kt
uses: DamianReeves/write-file-action@v1.3
with:
path: app/src/main/java/exh/Version.kt
contents: 'package exh const val syDebugVersion: String = "${{ github.run_number }}"'
write-mode: overwrite
- name: Write changelog_debug.xml
uses: DamianReeves/write-file-action@v1.3
with:

View file

@ -71,20 +71,6 @@ jobs:
changelog="<?xml version=\"1.0\" encoding=\"utf-8\"?><changelog bulletedList=\"true\"><changelogversion versionName=\"${{ github.run_number }}\" changeDate=\"\">$changelog</changelogversion></changelog>"
echo "CHANGELOG=$changelog" >> $GITHUB_ENV
- name: Write Version.kt
uses: DamianReeves/write-file-action@v1.3
with:
path: app/src/main/java/exh/Version.kt
contents: 'package exh const val syDebugVersion: String = "${{ github.run_number }}"'
write-mode: overwrite
# - name: Write changelog_debug.xml
# uses: DamianReeves/write-file-action@v1.3
# with:
# path: app/src/main/res/raw/changelog_debug.xml
# contents: "${{ env.CHANGELOG }}"
# write-mode: overwrite
- name: Write google-services.json
uses: DamianReeves/write-file-action@v1.3
with:

View file

@ -36,6 +36,7 @@ android {
buildConfigField("String", "COMMIT_SHA", "\"${getGitSha()}\"")
buildConfigField("String", "BUILD_TIME", "\"${getBuildTime()}\"")
buildConfigField("boolean", "INCLUDE_UPDATER", "false")
buildConfigField("boolean", "PREVIEW", "false")
ndk {
abiFilters += SUPPORTED_ABIS
@ -66,10 +67,20 @@ android {
matchingFallbacks.add("release")
}
named("release") {
isMinifyEnabled = true
isShrinkResources = true
isMinifyEnabled = true
setProguardFiles(listOf(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"))
}
create("preview") {
initWith(getByName("release"))
buildConfigField("boolean", "PREVIEW", "true")
matchingFallbacks.add("release")
versionNameSuffix = "-${getCommitCount()}"
applicationIdSuffix = ".beta"
signingConfig = signingConfigs.getByName("debug")
// signingConfig = signingConfigs.getByName("debug")
}
create("benchmark") {
initWith(getByName("release"))
@ -77,12 +88,13 @@ android {
matchingFallbacks.add("release")
isDebuggable = false
isProfileable = true
versionNameSuffix = "-benchmark"
versionNameSuffix = "-${getCommitCount()}-benchmark"
applicationIdSuffix = ".benchmark"
}
}
sourceSets {
getByName("preview").res.srcDirs("src/beta/res")
getByName("benchmark").res.srcDirs("src/debug/res")
}

View file

@ -32,9 +32,7 @@ import eu.kanade.tachiyomi.ui.more.NewUpdateScreen
import eu.kanade.tachiyomi.util.CrashLogUtil
import eu.kanade.tachiyomi.util.lang.toDateTimestampString
import eu.kanade.tachiyomi.util.system.copyToClipboard
import eu.kanade.tachiyomi.util.system.isPreviewBuildType
import eu.kanade.tachiyomi.util.system.toast
import exh.syDebugVersion
import kotlinx.coroutines.launch
import logcat.LogPriority
import tachiyomi.core.common.util.lang.withIOContext
@ -54,6 +52,7 @@ import java.time.Instant
import java.time.LocalDateTime
import java.time.ZoneId
@Suppress("JavaIoSerializableObjectMustHaveReadResolve")
object AboutScreen : Screen() {
@Composable
@ -259,9 +258,8 @@ object AboutScreen : Screen() {
}
}
}
// SY -->
isPreviewBuildType -> {
"Preview r$syDebugVersion".let {
BuildConfig.PREVIEW -> {
"Beta r${BuildConfig.COMMIT_COUNT}".let {
if (withBuildDate) {
"$it (${BuildConfig.COMMIT_SHA}, ${getFormattedBuildTime()})"
} else {
@ -269,7 +267,6 @@ object AboutScreen : Screen() {
}
}
}
// SY <--
else -> {
"Stable ${BuildConfig.VERSION_NAME}".let {
if (withBuildDate) {

View file

@ -58,6 +58,7 @@ import eu.kanade.tachiyomi.util.system.WebViewUtil
import eu.kanade.tachiyomi.util.system.animatorDurationScale
import eu.kanade.tachiyomi.util.system.cancelNotification
import eu.kanade.tachiyomi.util.system.isDevFlavor
import eu.kanade.tachiyomi.util.system.isPreviewBuildType
import eu.kanade.tachiyomi.util.system.isReleaseBuildType
import eu.kanade.tachiyomi.util.system.notify
import exh.log.CrashlyticsPrinter
@ -65,7 +66,6 @@ import exh.log.EHLogLevel
import exh.log.EnhancedFilePrinter
import exh.log.XLogLogcatLogger
import exh.log.xLogD
import exh.syDebugVersion
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
@ -102,7 +102,7 @@ class App : Application(), DefaultLifecycleObserver, SingletonImageLoader.Factor
// SY -->
if (!isDevFlavor) {
Firebase.crashlytics.setCrashlyticsCollectionEnabled(isReleaseBuildType)
Firebase.crashlytics.setCrashlyticsCollectionEnabled(isReleaseBuildType || isPreviewBuildType)
}
// SY <--
GlobalExceptionHandler.initialize(applicationContext, CrashActivity::class.java)
@ -329,7 +329,7 @@ class App : Application(), DefaultLifecycleObserver, SingletonImageLoader.Factor
xLogD(
"""
App version: ${BuildConfig.VERSION_NAME} (${BuildConfig.FLAVOR}, ${BuildConfig.COMMIT_SHA}, ${BuildConfig.VERSION_CODE})
Preview build: $syDebugVersion
Build version: ${BuildConfig.COMMIT_COUNT}
Android version: ${Build.VERSION.RELEASE} (SDK ${Build.VERSION.SDK_INT})
Android build ID: ${Build.DISPLAY}
Device brand: ${Build.BRAND}

View file

@ -3,8 +3,6 @@ package eu.kanade.tachiyomi.data.updater
import android.content.Context
import eu.kanade.tachiyomi.BuildConfig
import eu.kanade.tachiyomi.util.system.isInstalledFromFDroid
import eu.kanade.tachiyomi.util.system.isPreviewBuildType
import exh.syDebugVersion
import tachiyomi.core.common.util.lang.withIOContext
import tachiyomi.domain.release.interactor.GetApplicationRelease
import uy.kohesive.injekt.injectLazy
@ -22,17 +20,12 @@ class AppUpdateChecker {
return withIOContext {
val result = getApplicationRelease.await(
GetApplicationRelease.Arguments(
// SY -->
isPreviewBuildType,
// SY <--
context.isInstalledFromFDroid(),
BuildConfig.COMMIT_COUNT.toInt(),
BuildConfig.VERSION_NAME,
GITHUB_REPO,
// SY -->
syDebugVersion,
// SY <--
forceCheck,
isPreview = BuildConfig.PREVIEW,
isThirdParty = context.isInstalledFromFDroid(),
commitCount = BuildConfig.COMMIT_COUNT.toInt(),
versionName = BuildConfig.VERSION_NAME,
repository = GITHUB_REPO,
forceCheck = forceCheck,
),
)
@ -50,12 +43,19 @@ class AppUpdateChecker {
}
val GITHUB_REPO: String by lazy {
// SY -->
if (isPreviewBuildType) {
"komikku-app/komikku"
if (BuildConfig.PREVIEW) {
"komikku-app/komikku-preview"
} else {
"komikku-app/komikku"
}
}
val RELEASE_TAG: String by lazy {
if (BuildConfig.PREVIEW) {
"r${BuildConfig.COMMIT_COUNT}"
} else {
"v${BuildConfig.VERSION_NAME}"
}
}
val RELEASE_URL = "https://github.com/$GITHUB_REPO/releases/tag/$RELEASE_TAG"

View file

@ -75,8 +75,10 @@ import eu.kanade.tachiyomi.ui.manga.MangaScreen
import eu.kanade.tachiyomi.ui.more.NewUpdateScreen
import eu.kanade.tachiyomi.ui.more.OnboardingScreen
import eu.kanade.tachiyomi.util.system.dpToPx
import eu.kanade.tachiyomi.util.system.isDevFlavor
import eu.kanade.tachiyomi.util.system.isNavigationBarNeedsScrim
import eu.kanade.tachiyomi.util.system.isPreviewBuildType
import eu.kanade.tachiyomi.util.system.isReleaseBuildType
import eu.kanade.tachiyomi.util.view.setComposeContent
import exh.debug.DebugToggles
import exh.eh.EHentaiUpdateWorker
@ -84,7 +86,6 @@ import exh.log.DebugModeOverlay
import exh.source.BlacklistedSources
import exh.source.EH_SOURCE_ID
import exh.source.EXH_SOURCE_ID
import exh.syDebugVersion
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.collectLatest
@ -520,8 +521,8 @@ class MainActivity : BaseActivity() {
// SY -->
private fun addAnalytics() {
if (!BuildConfig.DEBUG && isPreviewBuildType) {
Firebase.analytics.setUserProperty("preview_version", syDebugVersion)
if (!isDevFlavor && (isReleaseBuildType || isPreviewBuildType)) {
Firebase.analytics.setUserProperty("preview_version", BuildConfig.COMMIT_COUNT)
}
}
// SY <--

View file

@ -9,7 +9,6 @@ import eu.kanade.tachiyomi.util.system.WebViewUtil
import eu.kanade.tachiyomi.util.system.createFileInCacheDir
import eu.kanade.tachiyomi.util.system.toShareIntent
import eu.kanade.tachiyomi.util.system.toast
import exh.syDebugVersion
import tachiyomi.core.common.util.lang.withNonCancellableContext
import tachiyomi.core.common.util.lang.withUIContext
import uy.kohesive.injekt.Injekt
@ -39,7 +38,7 @@ class CrashLogUtil(
fun getDebugInfo(): String {
return """
App version: ${BuildConfig.VERSION_NAME} (${BuildConfig.FLAVOR}, ${BuildConfig.COMMIT_SHA}, ${BuildConfig.VERSION_CODE}, ${BuildConfig.BUILD_TIME})
Preview build: $syDebugVersion
Build version: ${BuildConfig.COMMIT_COUNT}
Android version: ${Build.VERSION.RELEASE} (SDK ${Build.VERSION.SDK_INT}; build ${Build.DISPLAY})
Device brand: ${Build.BRAND}
Device manufacturer: ${Build.MANUFACTURER}

View file

@ -1,13 +1,12 @@
package eu.kanade.tachiyomi.util.system
import eu.kanade.tachiyomi.BuildConfig
import exh.syDebugVersion
val isDevFlavor: Boolean
get() = BuildConfig.FLAVOR == "dev"
val isPreviewBuildType: Boolean
get() = BuildConfig.BUILD_TYPE == "release" /* SY --> */ && syDebugVersion != "0" /* SY <-- */
get() = BuildConfig.BUILD_TYPE == "preview"
val isReleaseBuildType: Boolean
get() = BuildConfig.BUILD_TYPE == "release" /* SY --> */ && syDebugVersion == "0" /* SY <-- */
get() = BuildConfig.BUILD_TYPE == "release"

View file

@ -1 +0,0 @@
package exh const val syDebugVersion: String = "0"

View file

@ -32,10 +32,12 @@ class GetApplicationRelease(
lastChecked.set(now.toEpochMilli())
// Check if latest version is different from current version
// SY -->
val isNewVersion =
isNewVersion(arguments.isPreview, arguments.syDebugVersion, arguments.versionName, release.version)
// SY <--
val isNewVersion = isNewVersion(
isPreview = arguments.isPreview,
commitCount = arguments.commitCount,
versionName = arguments.versionName,
versionTag = release.version,
)
return when {
isNewVersion && arguments.isThirdParty -> Result.ThirdPartyInstallation
isNewVersion -> Result.NewUpdate(release)
@ -43,28 +45,45 @@ class GetApplicationRelease(
}
}
// SY -->
/**
* [isPreview] is if current version is Preview (beta) build
*
* [versionTag] is the version of new release
*
* Release (stable) version will compare with current's [versionName] ("v0.1.2")
*
* Preview (beta) version will compare with current's [commitCount] ("r1234")
*/
private fun isNewVersion(
isPreview: Boolean,
syDebugVersion: String,
commitCount: Int,
versionName: String,
versionTag: String,
): Boolean {
// Removes prefixes like "r" or "v"
val newVersion = versionTag.replace("[^\\d.]".toRegex(), "")
return if (isPreview) {
// Preview builds: based on releases in "jobobby04/TachiyomiSYPreview" repo
// tagged as something like "508"
val currentInt = syDebugVersion.toIntOrNull()
currentInt != null && newVersion.toInt() > currentInt
// Preview builds: based on releases in "komikku-app/komikku-preview" repo
// tagged as something like "r1234"
// KMK -->
// When has stable update but current app is preview version (same repo) expect new update
// TODO: remove this when all users has finished switching from preview to stable
if (newVersion.matches("""\d.\d.\d""".toRegex())) return true
// KMK <--
newVersion.toInt() > commitCount
} else {
// Release builds: based on releases in "komikku-app/komikku" repo
// tagged as something like "0.1.2"
// tagged as something like "v0.1.2"
val oldVersion = versionName.replace("[^\\d.]".toRegex(), "")
val newSemVer = newVersion.split(".").map { it.toInt() }
val oldSemVer = oldVersion.split(".").map { it.toInt() }
// KMK -->
// When has stable update with preview version but current app is stable version expect no update
// TODO: remove this when all users has finished switching from preview to stable
if (newSemVer.size != oldSemVer.size) return false
// KMK <--
oldSemVer.mapIndexed { index, i ->
if (newSemVer[index] > i) {
return true
@ -74,17 +93,19 @@ class GetApplicationRelease(
false
}
}
// SY <--
data class Arguments(
/** If current version is Preview (beta) build */
val isPreview: Boolean,
/** If current version is from third party */
val isThirdParty: Boolean,
/** Commit count of current version */
val commitCount: Int,
/** Current version name, could be version tag (v0.1.2) or commit count (r1234) */
val versionName: String,
/** Repository name */
val repository: String,
// SY -->
val syDebugVersion: String,
// SY <--
/** Force check for new update */
val forceCheck: Boolean = false,
)

View file

@ -49,7 +49,6 @@ class GetApplicationReleaseTest {
commitCount = 0,
versionName = "v1.0.0",
repository = "test",
syDebugVersion = "0",
),
)
@ -62,7 +61,7 @@ class GetApplicationReleaseTest {
every { preference.set(any()) }.answers { }
val release = Release(
"200",
"r2000",
"info",
"http://example.com/release_link",
listOf("http://example.com/assets"),
@ -77,13 +76,10 @@ class GetApplicationReleaseTest {
commitCount = 1000,
versionName = "",
repository = "test",
syDebugVersion = "100",
),
)
(result as GetApplicationRelease.Result.NewUpdate).release shouldBe GetApplicationRelease.Result.NewUpdate(
release,
).release
result shouldBe GetApplicationRelease.Result.NewUpdate(release)
}
@Test
@ -106,14 +102,11 @@ class GetApplicationReleaseTest {
isThirdParty = false,
commitCount = 0,
versionName = "v1.0.0",
syDebugVersion = "0",
repository = "test",
),
)
(result as GetApplicationRelease.Result.NewUpdate).release shouldBe GetApplicationRelease.Result.NewUpdate(
release,
).release
result shouldBe GetApplicationRelease.Result.NewUpdate(release)
}
@Test
@ -136,7 +129,6 @@ class GetApplicationReleaseTest {
isThirdParty = false,
commitCount = 0,
versionName = "v2.0.0",
syDebugVersion = "0",
repository = "test",
),
)
@ -150,7 +142,7 @@ class GetApplicationReleaseTest {
every { preference.set(any()) }.answers { }
val release = Release(
"v1.0.0",
"v2.0.0",
"info",
"http://example.com/release_link",
listOf("http://example.com/assets"),
@ -163,8 +155,7 @@ class GetApplicationReleaseTest {
isPreview = false,
isThirdParty = false,
commitCount = 0,
versionName = "v2.0.0",
syDebugVersion = "0",
versionName = "v1.0.0",
repository = "test",
),
)
@ -172,4 +163,88 @@ class GetApplicationReleaseTest {
coVerify(exactly = 0) { releaseService.latest(any()) }
result shouldBe GetApplicationRelease.Result.NoNewUpdate
}
// KMK -->
// TODO: remove below tests when all users finished switching from preview to stable
@Test
fun `When preview version updating to new stable version with preview tag expect new update`() = runTest {
every { preference.get() } returns 0
every { preference.set(any()) }.answers { }
val release = Release(
"r1234",
"info",
"http://example.com/release_link",
listOf("http://example.com/assets"),
)
coEvery { releaseService.latest(any()) } returns release
val result = getApplicationRelease.await(
GetApplicationRelease.Arguments(
isPreview = true,
isThirdParty = false,
commitCount = 25,
versionName = "",
repository = "test",
),
)
result shouldBe GetApplicationRelease.Result.NewUpdate(release)
}
@Test
fun `When has stable update with preview version but current app is stable version expect no update`() = runTest {
every { preference.get() } returns 0
every { preference.set(any()) }.answers { }
val release = Release(
"r1234",
"info",
"http://example.com/release_link",
listOf("http://example.com/assets"),
)
coEvery { releaseService.latest(any()) } returns release
val result = getApplicationRelease.await(
GetApplicationRelease.Arguments(
isPreview = false,
isThirdParty = false,
commitCount = 0,
versionName = "v1.0.0",
repository = "test",
),
)
result shouldBe GetApplicationRelease.Result.NoNewUpdate
}
@Test
fun `When has stable update but current app is preview version (same repo) expect new update`() = runTest {
every { preference.get() } returns 0
every { preference.set(any()) }.answers { }
val release = Release(
"v2.0.0",
"info",
"http://example.com/release_link",
listOf("http://example.com/assets"),
)
coEvery { releaseService.latest(any()) } returns release
val result = getApplicationRelease.await(
GetApplicationRelease.Arguments(
isPreview = true,
isThirdParty = false,
commitCount = 25,
versionName = "",
repository = "test",
),
)
result shouldBe GetApplicationRelease.Result.NewUpdate(release)
}
// KMK <--
}

View file

@ -28,6 +28,7 @@
<!-- About -->
<string name="changelog_version">Version %1$s</string>
<string name="changelogs">Change Logs</string>
<!-- EH Settings -->
<string name="ehentai_prefs_account_settings">E-Hentai Website Account Settings</string>