From 935fcc8d262cdcb308bc0c05094867c161c6f9a9 Mon Sep 17 00:00:00 2001 From: Cloudburst <18114966+C10udburst@users.noreply.github.com> Date: Mon, 16 Aug 2021 11:51:31 +0200 Subject: [PATCH 01/12] create build workflow --- .github/workflows/main.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..59736b0f --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,25 @@ +# This workflow will build a Java project with Gradle +# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle + +name: Artifact Build + +on: [push, pull_request] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Run Gradle command + uses: Raul6469/android-gradle-action@2.0.0 + with: + # The gradle command you wish to run (required) + # Here, `./gradlew test` will be run + script: assembleDebug + - name: Upload Artifact + uses: actions/upload-artifact@v2 + with: + name: pull-request-build + path: "*/*/build/outputs/apk/*.apk" From 763392a857459025a7b3a61a2727f38655a9ba87 Mon Sep 17 00:00:00 2001 From: Cloudburst <18114966+C10udburst@users.noreply.github.com> Date: Mon, 16 Aug 2021 12:00:34 +0200 Subject: [PATCH 02/12] wrong path ig --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 59736b0f..d1fa318d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -22,4 +22,4 @@ jobs: uses: actions/upload-artifact@v2 with: name: pull-request-build - path: "*/*/build/outputs/apk/*.apk" + path: "build/outputs/apk/*.apk" From d20c94d03404bb48324e788bc5a55cf1b4a959f7 Mon Sep 17 00:00:00 2001 From: Cloudburst <18114966+C10udburst@users.noreply.github.com> Date: Mon, 16 Aug 2021 12:12:11 +0200 Subject: [PATCH 03/12] bruh --- .github/workflows/main.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d1fa318d..39078d75 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -7,19 +7,21 @@ on: [push, pull_request] jobs: build: - runs-on: ubuntu-latest - steps: - uses: actions/checkout@v2 - name: Run Gradle command uses: Raul6469/android-gradle-action@2.0.0 with: - # The gradle command you wish to run (required) - # Here, `./gradlew test` will be run script: assembleDebug + # In some cases, you may need to provide + # Android licence agreement id + # You can find it on your own machine under `$ANDROID_HOME/license`, + # and add the file content as a GitHub secret named `$ANDROID_LICENCE`. + # android-licence: ${{ secrets.ANDROID_LICENCE }} + - name: Upload Artifact uses: actions/upload-artifact@v2 with: name: pull-request-build - path: "build/outputs/apk/*.apk" + path: "app/build/outputs/apk/debug/*.apk" From da8a476236fb27392da62dfc73f49cbdaf8edbe9 Mon Sep 17 00:00:00 2001 From: Cloudburst Date: Mon, 16 Aug 2021 12:27:45 +0200 Subject: [PATCH 04/12] separate into pre-release and pull_request --- .github/workflows/prerelease.yml | 28 +++++++++++++++++++ .../workflows/{main.yml => pull_request.yml} | 5 +--- 2 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/prerelease.yml rename .github/workflows/{main.yml => pull_request.yml} (77%) diff --git a/.github/workflows/prerelease.yml b/.github/workflows/prerelease.yml new file mode 100644 index 00000000..affef485 --- /dev/null +++ b/.github/workflows/prerelease.yml @@ -0,0 +1,28 @@ +name: Pre-release + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Run Gradle command + uses: Raul6469/android-gradle-action@2.0.0 + with: + script: assembleDebug + # In some cases, you may need to provide + # Android licence agreement id + # You can find it on your own machine under `$ANDROID_HOME/license`, + # and add the file content as a GitHub secret named `$ANDROID_LICENCE`. + # android-licence: ${{ secrets.ANDROID_LICENCE }} + + - 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 diff --git a/.github/workflows/main.yml b/.github/workflows/pull_request.yml similarity index 77% rename from .github/workflows/main.yml rename to .github/workflows/pull_request.yml index 39078d75..67d4fcc6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/pull_request.yml @@ -1,9 +1,6 @@ -# This workflow will build a Java project with Gradle -# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle - name: Artifact Build -on: [push, pull_request] +on: [pull_request] jobs: build: From 1861f292b50cb2d04149b952091df7f04af23352 Mon Sep 17 00:00:00 2001 From: Cloudburst <18114966+C10udburst@users.noreply.github.com> Date: Mon, 16 Aug 2021 12:37:32 +0200 Subject: [PATCH 05/12] Concurrency --- .github/workflows/prerelease.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/prerelease.yml b/.github/workflows/prerelease.yml index affef485..4215e17b 100644 --- a/.github/workflows/prerelease.yml +++ b/.github/workflows/prerelease.yml @@ -2,6 +2,10 @@ name: Pre-release on: [push] +concurrency: + group: "pre-release" + cancel-in-progress: true + jobs: build: runs-on: ubuntu-latest From df093d5e720b732eb9dca75ec9d835054cb71186 Mon Sep 17 00:00:00 2001 From: Cloudburst Date: Mon, 16 Aug 2021 16:54:58 +0200 Subject: [PATCH 06/12] filter out prereleases from updater --- .../java/com/lagradost/cloudstream3/utils/InAppUpdater.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/InAppUpdater.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/InAppUpdater.kt index cc70366b..98544376 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/InAppUpdater.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/InAppUpdater.kt @@ -38,6 +38,7 @@ class InAppUpdater { @JsonProperty("body") val body: String, // Desc @JsonProperty("assets") val assets: List, @JsonProperty("target_commitish") val target_commitish: String, // branch + @JsonProperty("prerelease") var prerelease: Boolean, ) data class Update( @@ -67,7 +68,9 @@ class InAppUpdater { versionRegex.find(it.name)?.groupValues?.get(2) }).toList().lastOrNull()*/ val found = - response.sortedWith(compareBy { release -> + 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( From 8f511a8707453af6fd4490e4c25f7f15336612d4 Mon Sep 17 00:00:00 2001 From: C10udburst Date: Tue, 17 Aug 2021 09:42:28 +0200 Subject: [PATCH 07/12] try to shave 2min from the build Signed-off-by: C10udburst --- .github/workflows/prerelease.yml | 21 +++++++++++---------- .github/workflows/pull_request.yml | 17 ++++++++--------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/.github/workflows/prerelease.yml b/.github/workflows/prerelease.yml index 4215e17b..8d55e22a 100644 --- a/.github/workflows/prerelease.yml +++ b/.github/workflows/prerelease.yml @@ -1,6 +1,8 @@ name: Pre-release -on: [push] +on: + push: + branches: [ master ] concurrency: group: "pre-release" @@ -11,16 +13,15 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - name: Run Gradle command - uses: Raul6469/android-gradle-action@2.0.0 + - name: Set up JDK 8 + uses: actions/setup-java@v2 with: - script: assembleDebug - # In some cases, you may need to provide - # Android licence agreement id - # You can find it on your own machine under `$ANDROID_HOME/license`, - # and add the file content as a GitHub secret named `$ANDROID_LICENCE`. - # android-licence: ${{ secrets.ANDROID_LICENCE }} - + java-version: '8' + distribution: 'adopt' + - name: Grant execute permission for gradlew + run: chmod +x gradlew + - name: Run Gradle + run: ./gradlew assembleDebug - name: Create pre-release uses: "marvinpinto/action-automatic-releases@latest" with: diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 67d4fcc6..281bb10b 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -7,16 +7,15 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - name: Run Gradle command - uses: Raul6469/android-gradle-action@2.0.0 + - name: Set up JDK 8 + uses: actions/setup-java@v2 with: - script: assembleDebug - # In some cases, you may need to provide - # Android licence agreement id - # You can find it on your own machine under `$ANDROID_HOME/license`, - # and add the file content as a GitHub secret named `$ANDROID_LICENCE`. - # android-licence: ${{ secrets.ANDROID_LICENCE }} - + 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: From cb12c76ee6534a00c1e35e5c4eba5d11e8c49e83 Mon Sep 17 00:00:00 2001 From: Arjix <53124886+ArjixWasTaken@users.noreply.github.com> Date: Tue, 17 Aug 2021 15:22:51 +0300 Subject: [PATCH 08/12] changed json property prerelease to val --- .../java/com/lagradost/cloudstream3/utils/InAppUpdater.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/InAppUpdater.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/InAppUpdater.kt index 98544376..42daa043 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/InAppUpdater.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/InAppUpdater.kt @@ -38,7 +38,7 @@ class InAppUpdater { @JsonProperty("body") val body: String, // Desc @JsonProperty("assets") val assets: List, @JsonProperty("target_commitish") val target_commitish: String, // branch - @JsonProperty("prerelease") var prerelease: Boolean, + @JsonProperty("prerelease") val prerelease: Boolean, ) data class Update( @@ -283,4 +283,4 @@ class InAppUpdater { return false } } -} \ No newline at end of file +} From 64b302132cfcb7e7c70d311af086dac5987ecb8d Mon Sep 17 00:00:00 2001 From: Cloudburst Date: Tue, 17 Aug 2021 15:23:50 +0200 Subject: [PATCH 09/12] add setting for updating to prereleases --- .../com/lagradost/cloudstream3/utils/InAppUpdater.kt | 10 ++++++++++ .../res/drawable/ic_baseline_developer_mode_24.xml | 10 ++++++++++ app/src/main/res/values/strings.xml | 3 +++ app/src/main/res/xml/settings.xml | 7 +++++++ 4 files changed, 30 insertions(+) create mode 100644 app/src/main/res/drawable/ic_baseline_developer_mode_24.xml diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/InAppUpdater.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/InAppUpdater.kt index 98544376..094078fb 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/InAppUpdater.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/InAppUpdater.kt @@ -41,6 +41,16 @@ class InAppUpdater { @JsonProperty("prerelease") var 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 object: GithubObject, + ) + data class Update( @JsonProperty("shouldUpdate") val shouldUpdate: Boolean, @JsonProperty("updateURL") val updateURL: String?, diff --git a/app/src/main/res/drawable/ic_baseline_developer_mode_24.xml b/app/src/main/res/drawable/ic_baseline_developer_mode_24.xml new file mode 100644 index 00000000..ded6b035 --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_developer_mode_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 781eb895..960400b7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -84,5 +84,8 @@ Search using providers Search using types auto_update + prerelease_update manual_check_update + + unknown_prerelease \ No newline at end of file diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml index 1dd14dbd..b5643ab9 100644 --- a/app/src/main/res/xml/settings.xml +++ b/app/src/main/res/xml/settings.xml @@ -91,6 +91,13 @@ app:defaultValue="true" android:icon="@drawable/ic_baseline_notifications_active_24" /> + Date: Tue, 17 Aug 2021 16:04:10 +0200 Subject: [PATCH 10/12] update inuppupdater --- .../cloudstream3/utils/InAppUpdater.kt | 115 ++++++++++++------ .../ic_baseline_developer_mode_24.xml | 13 +- 2 files changed, 79 insertions(+), 49 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/InAppUpdater.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/InAppUpdater.kt index 7ab8cf59..7e171f0e 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/InAppUpdater.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/InAppUpdater.kt @@ -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 @@ -48,7 +49,7 @@ class InAppUpdater { ) data class GithubTag( - @JsonProperty("object") val object: GithubObject, + @JsonProperty("object") val github_object: GithubObject, ) data class Update( @@ -63,53 +64,87 @@ 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>(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) + 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>(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 { + // TODO: change url + val tagUrl = "https://api.github.com/repos/C10udburst/CloudStream-3/git/ref/tags/pre-release" + val releaseUrl = "https://api.github.com/repos/C10udburst/CloudStream-3/releases" + val headers = mapOf("Accept" to "application/vnd.github.v3+json") + val response = + mapper.readValue>(khttp.get(releaseUrl, headers = headers).text) + + val found = + response.lastOrNull { rel -> + rel.prerelease + } + val foundAsset = found?.assets?.getOrNull(0) + + val tagResponse = + mapper.readValue(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 diff --git a/app/src/main/res/drawable/ic_baseline_developer_mode_24.xml b/app/src/main/res/drawable/ic_baseline_developer_mode_24.xml index ded6b035..55febeee 100644 --- a/app/src/main/res/drawable/ic_baseline_developer_mode_24.xml +++ b/app/src/main/res/drawable/ic_baseline_developer_mode_24.xml @@ -1,10 +1,5 @@ - - + + From e11e9fcce73d8e192f4185032ab2ee456b85be70 Mon Sep 17 00:00:00 2001 From: Cloudburst Date: Tue, 17 Aug 2021 16:05:48 +0200 Subject: [PATCH 11/12] ficks link --- .../java/com/lagradost/cloudstream3/utils/InAppUpdater.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/InAppUpdater.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/InAppUpdater.kt index 7e171f0e..02a36991 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/InAppUpdater.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/InAppUpdater.kt @@ -120,9 +120,8 @@ class InAppUpdater { } private fun Activity.getPreReleaseUpdate(): Update { - // TODO: change url - val tagUrl = "https://api.github.com/repos/C10udburst/CloudStream-3/git/ref/tags/pre-release" - val releaseUrl = "https://api.github.com/repos/C10udburst/CloudStream-3/releases" + 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>(khttp.get(releaseUrl, headers = headers).text) From da40074019add2b90c3af09073c83ce684377e18 Mon Sep 17 00:00:00 2001 From: Cloudburst <18114966+C10udburst@users.noreply.github.com> Date: Tue, 17 Aug 2021 16:13:48 +0200 Subject: [PATCH 12/12] make workflow update prerelease_commit_hash --- .github/workflows/prerelease.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/prerelease.yml b/.github/workflows/prerelease.yml index 8d55e22a..86d1a1a4 100644 --- a/.github/workflows/prerelease.yml +++ b/.github/workflows/prerelease.yml @@ -20,6 +20,10 @@ jobs: 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/unknown_prerelease<\/string>/$COMMIT_HASH<\/string>/g" app/src/main/res/values/strings.xml - name: Run Gradle run: ./gradlew assembleDebug - name: Create pre-release