mirror of
https://github.com/rhunk/SnapEnhance.git
synced 2025-05-29 21:10:20 +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
|
val latestVersion = latestRelease.getAsJsonPrimitive("tag_name").asString
|
||||||
if (latestVersion.removePrefix("v") == BuildConfig.VERSION_NAME) return@runCatching null
|
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 {
|
}.onFailure {
|
||||||
AbstractLogger.directError("Failed to fetch latest release", it)
|
AbstractLogger.directError("Failed to fetch latest release", it)
|
||||||
}.getOrNull()
|
}.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 {
|
val latestRelease by lazy {
|
||||||
fetchLatestRelease()
|
if (BuildConfig.DEBUG) fetchLatestDebugCI() else fetchLatestRelease()
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -209,9 +209,7 @@ class HomeRootSection : Routes.Route() {
|
|||||||
context.database.getQuickTiles()
|
context.database.getQuickTiles()
|
||||||
}
|
}
|
||||||
|
|
||||||
val latestUpdate by rememberAsyncMutableState(defaultValue = null) {
|
val latestUpdate by rememberAsyncMutableState(defaultValue = null) { Updater.latestRelease }
|
||||||
if (!BuildConfig.DEBUG) Updater.latestRelease else null
|
|
||||||
}
|
|
||||||
|
|
||||||
if (latestUpdate != null) {
|
if (latestUpdate != null) {
|
||||||
Spacer(modifier = Modifier.height(10.dp))
|
Spacer(modifier = Modifier.height(10.dp))
|
||||||
@ -228,15 +226,21 @@ class HomeRootSection : Routes.Route() {
|
|||||||
fontWeight = FontWeight.Bold,
|
fontWeight = FontWeight.Bold,
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
fontSize = 12.sp, text = translation.format(
|
fontSize = 12.sp,
|
||||||
|
text = translation.format(
|
||||||
"update_content",
|
"update_content",
|
||||||
"version" to (latestUpdate?.versionName ?: "unknown")
|
"version" to (latestUpdate?.versionName ?: "unknown")
|
||||||
), lineHeight = 20.sp
|
),
|
||||||
|
lineHeight = 20.sp,
|
||||||
|
overflow = TextOverflow.Ellipsis,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Button(onClick = {
|
Button(
|
||||||
latestUpdate?.releaseUrl?.let { openExternalLink(it) }
|
modifier = Modifier.height(40.dp),
|
||||||
}, modifier = Modifier.height(40.dp)) {
|
onClick = {
|
||||||
|
latestUpdate?.releaseUrl?.let { openExternalLink(it) }
|
||||||
|
}
|
||||||
|
) {
|
||||||
Text(text = translation["update_button"])
|
Text(text = translation["update_button"])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user