mirror of
https://github.com/rhunk/SnapEnhance.git
synced 2025-05-28 20:40:13 +02:00
feat(app/updater): debug CI builds
This commit is contained in:
parent
6a22224d58
commit
4fe386e227
@ -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()
|
||||
}
|
||||
}
|
@ -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"])
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user