commit 4fe386e2273976de75fbb5a0259bea9d195686b0
parent 6a22224d58c1e91cfaf688e3d3f6596303d54afb
Author: rhunk <101876869+rhunk@users.noreply.github.com>
Date: Sun, 8 Sep 2024 21:25:42 +0200
feat(app/updater): debug CI builds
Diffstat:
2 files changed, 39 insertions(+), 10 deletions(-)
diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/data/Updater.kt b/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/data/Updater.kt
@@ -27,12 +27,37 @@ object Updater {
val latestVersion = latestRelease.getAsJsonPrimitive("tag_name").asString
if (latestVersion.removePrefix("v") == BuildConfig.VERSION_NAME) return@runCatching null
- LatestRelease(latestVersion, endpoint.url.toString().replace("api.", "").replace("repos/", ""))
+ LatestRelease(
+ versionName = latestVersion,
+ releaseUrl = endpoint.url.toString().replace("api.", "").replace("repos/", "")
+ )
}.onFailure {
AbstractLogger.directError("Failed to fetch latest release", it)
}.getOrNull()
+ private fun fetchLatestDebugCI() = runCatching {
+ val actionRuns = OkHttpClient().newCall(Request.Builder().url("https://api.github.com/repos/rhunk/SnapEnhance/actions/runs?event=workflow_dispatch").build()).execute().use {
+ if (!it.isSuccessful) throw Throwable("Failed to fetch CI runs: ${it.code}")
+ JsonParser.parseString(it.body.string()).asJsonObject
+ }
+ val debugRuns = actionRuns.getAsJsonArray("workflow_runs")?.mapNotNull { it.asJsonObject }?.filter { run ->
+ run.getAsJsonPrimitive("conclusion")?.asString == "success" && run.getAsJsonPrimitive("path")?.asString == ".github/workflows/debug.yml"
+ } ?: throw Throwable("No debug CI runs found")
+
+ val latestRun = debugRuns.firstOrNull() ?: throw Throwable("No debug CI runs found")
+ val headSha = latestRun.getAsJsonPrimitive("head_sha")?.asString ?: throw Throwable("No head sha found")
+
+ if (headSha == BuildConfig.GIT_HASH) return@runCatching null
+
+ LatestRelease(
+ versionName = headSha.substring(0, headSha.length.coerceAtMost(7)) + "-debug",
+ releaseUrl = latestRun.getAsJsonPrimitive("html_url")?.asString?.replace("github.com", "nightly.link") ?: return@runCatching null
+ )
+ }.onFailure {
+ AbstractLogger.directError("Failed to fetch latest debug CI", it)
+ }.getOrNull()
+
val latestRelease by lazy {
- fetchLatestRelease()
+ if (BuildConfig.DEBUG) fetchLatestDebugCI() else fetchLatestRelease()
}
}
\ No newline at end of file
diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/pages/home/HomeRootSection.kt b/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/pages/home/HomeRootSection.kt
@@ -209,9 +209,7 @@ class HomeRootSection : Routes.Route() {
context.database.getQuickTiles()
}
- val latestUpdate by rememberAsyncMutableState(defaultValue = null) {
- if (!BuildConfig.DEBUG) Updater.latestRelease else null
- }
+ val latestUpdate by rememberAsyncMutableState(defaultValue = null) { Updater.latestRelease }
if (latestUpdate != null) {
Spacer(modifier = Modifier.height(10.dp))
@@ -228,15 +226,21 @@ class HomeRootSection : Routes.Route() {
fontWeight = FontWeight.Bold,
)
Text(
- fontSize = 12.sp, text = translation.format(
+ fontSize = 12.sp,
+ text = translation.format(
"update_content",
"version" to (latestUpdate?.versionName ?: "unknown")
- ), lineHeight = 20.sp
+ ),
+ lineHeight = 20.sp,
+ overflow = TextOverflow.Ellipsis,
)
}
- Button(onClick = {
- latestUpdate?.releaseUrl?.let { openExternalLink(it) }
- }, modifier = Modifier.height(40.dp)) {
+ Button(
+ modifier = Modifier.height(40.dp),
+ onClick = {
+ latestUpdate?.releaseUrl?.let { openExternalLink(it) }
+ }
+ ) {
Text(text = translation["update_button"])
}
}