mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
commit
c237b71f52
6 changed files with 160 additions and 38 deletions
37
.github/workflows/prerelease.yml
vendored
Normal file
37
.github/workflows/prerelease.yml
vendored
Normal file
|
@ -0,0 +1,37 @@
|
|||
name: Pre-release
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
|
||||
concurrency:
|
||||
group: "pre-release"
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up JDK 8
|
||||
uses: actions/setup-java@v2
|
||||
with:
|
||||
java-version: '8'
|
||||
distribution: 'adopt'
|
||||
- name: Grant execute permission for gradlew
|
||||
run: chmod +x gradlew
|
||||
- name: Update prerelease_commit_hash
|
||||
run: |
|
||||
COMMIT_HASH="$(git log -1 --format='%H')"
|
||||
sed -i "s/<string name=\"prerelease_commit_hash\">unknown_prerelease<\/string>/<string name=\"prerelease_commit_hash\">$COMMIT_HASH<\/string>/g" app/src/main/res/values/strings.xml
|
||||
- name: Run Gradle
|
||||
run: ./gradlew assembleDebug
|
||||
- name: Create pre-release
|
||||
uses: "marvinpinto/action-automatic-releases@latest"
|
||||
with:
|
||||
repo_token: "${{ secrets.GITHUB_TOKEN }}"
|
||||
automatic_release_tag: "pre-release"
|
||||
prerelease: true
|
||||
title: "Pre-release Build"
|
||||
files: |
|
||||
app/build/outputs/apk/debug/*.apk
|
23
.github/workflows/pull_request.yml
vendored
Normal file
23
.github/workflows/pull_request.yml
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
name: Artifact Build
|
||||
|
||||
on: [pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up JDK 8
|
||||
uses: actions/setup-java@v2
|
||||
with:
|
||||
java-version: '8'
|
||||
distribution: 'adopt'
|
||||
- name: Grant execute permission for gradlew
|
||||
run: chmod +x gradlew
|
||||
- name: Run Gradle
|
||||
run: ./gradlew assembleDebug
|
||||
- name: Upload Artifact
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: pull-request-build
|
||||
path: "app/build/outputs/apk/debug/*.apk"
|
|
@ -16,6 +16,7 @@ import com.fasterxml.jackson.module.kotlin.KotlinModule
|
|||
import com.fasterxml.jackson.module.kotlin.readValue
|
||||
import com.lagradost.cloudstream3.BuildConfig
|
||||
import com.lagradost.cloudstream3.R
|
||||
import com.lagradost.cloudstream3.utils.InAppUpdater.Companion.runAutoUpdate
|
||||
import java.io.*
|
||||
import java.net.URL
|
||||
import java.net.URLConnection
|
||||
|
@ -38,8 +39,19 @@ class InAppUpdater {
|
|||
@JsonProperty("body") val body: String, // Desc
|
||||
@JsonProperty("assets") val assets: List<GithubAsset>,
|
||||
@JsonProperty("target_commitish") val target_commitish: String, // branch
|
||||
@JsonProperty("prerelease") val prerelease: Boolean,
|
||||
)
|
||||
|
||||
data class GithubObject(
|
||||
@JsonProperty("sha") val sha: String, // sha 256 hash
|
||||
@JsonProperty("type") val type: String, // object type
|
||||
@JsonProperty("url") val url: String,
|
||||
)
|
||||
|
||||
data class GithubTag(
|
||||
@JsonProperty("object") val github_object: GithubObject,
|
||||
)
|
||||
|
||||
data class Update(
|
||||
@JsonProperty("shouldUpdate") val shouldUpdate: Boolean,
|
||||
@JsonProperty("updateURL") val updateURL: String?,
|
||||
|
@ -52,51 +64,86 @@ class InAppUpdater {
|
|||
|
||||
private fun Activity.getAppUpdate(): Update {
|
||||
try {
|
||||
val url = "https://api.github.com/repos/LagradOst/CloudStream-3/releases"
|
||||
val headers = mapOf("Accept" to "application/vnd.github.v3+json")
|
||||
val response =
|
||||
mapper.readValue<List<GithubRelease>>(khttp.get(url, headers = headers).text)
|
||||
|
||||
val versionRegex = Regex("""(.*?((\d)\.(\d)\.(\d)).*\.apk)""")
|
||||
|
||||
/*
|
||||
val releases = response.map { it.assets }.flatten()
|
||||
.filter { it.content_type == "application/vnd.android.package-archive" }
|
||||
val found =
|
||||
releases.sortedWith(compareBy {
|
||||
versionRegex.find(it.name)?.groupValues?.get(2)
|
||||
}).toList().lastOrNull()*/
|
||||
val found =
|
||||
response.sortedWith(compareBy { release ->
|
||||
release.assets.filter { it.content_type == "application/vnd.android.package-archive" }
|
||||
.getOrNull(0)?.name?.let { it1 ->
|
||||
versionRegex.find(
|
||||
it1
|
||||
)?.groupValues?.get(2)
|
||||
}
|
||||
}).toList().lastOrNull()
|
||||
val foundAsset = found?.assets?.getOrNull(0)
|
||||
val currentVersion = packageName?.let {
|
||||
packageManager.getPackageInfo(it,
|
||||
0)
|
||||
}
|
||||
|
||||
val foundVersion = foundAsset?.name?.let { versionRegex.find(it) }
|
||||
val shouldUpdate = if (found != null && foundAsset?.browser_download_url != "" && foundVersion != null) currentVersion?.versionName?.compareTo(
|
||||
foundVersion.groupValues[2]
|
||||
)!! < 0 else false
|
||||
return if (foundVersion != null) {
|
||||
Update(shouldUpdate, foundAsset.browser_download_url, foundVersion.groupValues[2], found.body)
|
||||
val settingsManager = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
return if (settingsManager.getBoolean(getString(R.string.prerelease_update_key), false)) {
|
||||
getPreReleaseUpdate()
|
||||
} else {
|
||||
Update(false, null, null, null)
|
||||
getReleaseUpdate()
|
||||
}
|
||||
|
||||
} catch (e: Exception) {
|
||||
println(e)
|
||||
return Update(false, null, null, null)
|
||||
}
|
||||
}
|
||||
|
||||
private fun Activity.getReleaseUpdate(): Update {
|
||||
val url = "https://api.github.com/repos/LagradOst/CloudStream-3/releases"
|
||||
val headers = mapOf("Accept" to "application/vnd.github.v3+json")
|
||||
val response =
|
||||
mapper.readValue<List<GithubRelease>>(khttp.get(url, headers = headers).text)
|
||||
|
||||
val versionRegex = Regex("""(.*?((\d)\.(\d)\.(\d)).*\.apk)""")
|
||||
|
||||
/*
|
||||
val releases = response.map { it.assets }.flatten()
|
||||
.filter { it.content_type == "application/vnd.android.package-archive" }
|
||||
val found =
|
||||
releases.sortedWith(compareBy {
|
||||
versionRegex.find(it.name)?.groupValues?.get(2)
|
||||
}).toList().lastOrNull()*/
|
||||
val found =
|
||||
response.filter { rel ->
|
||||
!rel.prerelease
|
||||
}.sortedWith(compareBy { release ->
|
||||
release.assets.filter { it.content_type == "application/vnd.android.package-archive" }
|
||||
.getOrNull(0)?.name?.let { it1 ->
|
||||
versionRegex.find(
|
||||
it1
|
||||
)?.groupValues?.get(2)
|
||||
}
|
||||
}).toList().lastOrNull()
|
||||
val foundAsset = found?.assets?.getOrNull(0)
|
||||
val currentVersion = packageName?.let {
|
||||
packageManager.getPackageInfo(it,
|
||||
0)
|
||||
}
|
||||
|
||||
val foundVersion = foundAsset?.name?.let { versionRegex.find(it) }
|
||||
val shouldUpdate = if (found != null && foundAsset?.browser_download_url != "" && foundVersion != null) currentVersion?.versionName?.compareTo(
|
||||
foundVersion.groupValues[2]
|
||||
)!! < 0 else false
|
||||
return if (foundVersion != null) {
|
||||
Update(shouldUpdate, foundAsset.browser_download_url, foundVersion.groupValues[2], found.body)
|
||||
} else {
|
||||
Update(false, null, null, null)
|
||||
}
|
||||
}
|
||||
|
||||
private fun Activity.getPreReleaseUpdate(): Update {
|
||||
val tagUrl = "https://api.github.com/repos/LagradOst/CloudStream-3/git/ref/tags/pre-release"
|
||||
val releaseUrl = "https://api.github.com/repos/LagradOst/CloudStream-3/releases"
|
||||
val headers = mapOf("Accept" to "application/vnd.github.v3+json")
|
||||
val response =
|
||||
mapper.readValue<List<GithubRelease>>(khttp.get(releaseUrl, headers = headers).text)
|
||||
|
||||
val found =
|
||||
response.lastOrNull { rel ->
|
||||
rel.prerelease
|
||||
}
|
||||
val foundAsset = found?.assets?.getOrNull(0)
|
||||
|
||||
val tagResponse =
|
||||
mapper.readValue<GithubTag>(khttp.get(tagUrl, headers = headers).text)
|
||||
|
||||
val shouldUpdate = (getString(R.string.prerelease_commit_hash) != tagResponse.github_object.sha)
|
||||
|
||||
return if (foundAsset != null) {
|
||||
Update(shouldUpdate, foundAsset.browser_download_url, tagResponse.github_object.sha, found.body)
|
||||
} else {
|
||||
Update(false, null, null, null)
|
||||
}
|
||||
}
|
||||
|
||||
private fun Activity.downloadUpdate(url: String): Boolean {
|
||||
println("DOWNLOAD UPDATE $url")
|
||||
var fullResume = false // IF FULL RESUME
|
||||
|
@ -280,4 +327,4 @@ class InAppUpdater {
|
|||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
<vector android:height="24dp" android:tint="#FFFFFF"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M7,5h10v2h2L19,3c0,-1.1 -0.9,-1.99 -2,-1.99L7,1c-1.1,0 -2,0.9 -2,2v4h2L7,5zM15.41,16.59L20,12l-4.59,-4.59L14,8.83 17.17,12 14,15.17l1.41,1.42zM10,15.17L6.83,12 10,8.83 8.59,7.41 4,12l4.59,4.59L10,15.17zM17,19L7,19v-2L5,17v4c0,1.1 0.9,2 2,2h10c1.1,0 2,-0.9 2,-2v-4h-2v2z"/>
|
||||
</vector>
|
|
@ -84,5 +84,8 @@
|
|||
<string name="search_provider_text_providers">Search using providers</string>
|
||||
<string name="search_provider_text_types">Search using types</string>
|
||||
<string name="auto_update_key">auto_update</string>
|
||||
<string name="prerelease_update_key">prerelease_update</string>
|
||||
<string name="manual_check_update_key">manual_check_update</string>
|
||||
|
||||
<string name="prerelease_commit_hash">unknown_prerelease</string>
|
||||
</resources>
|
|
@ -91,6 +91,13 @@
|
|||
app:defaultValue="true"
|
||||
android:icon="@drawable/ic_baseline_notifications_active_24"
|
||||
/>
|
||||
<SwitchPreference
|
||||
app:key="@string/prerelease_update_key"
|
||||
android:title="Update to prereleases"
|
||||
android:summary="Search for prerelease updates instead of full releases only"
|
||||
app:defaultValue="false"
|
||||
android:icon="@drawable/ic_baseline_developer_mode_24"
|
||||
/>
|
||||
<Preference
|
||||
android:title="Check for Update"
|
||||
app:key="@string/manual_check_update_key"
|
||||
|
|
Loading…
Reference in a new issue