Skip to content

Native Android client for Spotify, built with Jetpack Compose

Betas numbered as strict semver pre-releases of the next version (v2.2.1-beta.1 after the stable 2.2.0), checked by tools/check_tag.py before the release job builds (a beta must be newer than every tag, a stable newer than every stable), APKs named myspoti-beta-<version>.apk and myspoti-stable-<version>.apk so Obtainium can filter each channel (the in-app update check accepts the new and the old names), prerelease flag kept on beta releases, Obtainium settings for both channels in the README [skip ci]

kota-zo69bf125c66d7
diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml
index f2120898..cde79786 100644
--- a/.github/workflows/android.yml
+++ b/.github/workflows/android.yml
@@ -82,6 +82,12 @@ jobs:
- uses: gradle/actions/setup-gradle@v6
+ # Strict semver tags, so Obtainium and the app compare versions right: "v2.2.1-beta.1" (a beta
+ # of the next version, above the last stable) or "v2.2.1". See tools/check_tag.py.
+ - name: Tag format
+ working-directory: .
+ run: python3 tools/check_tag.py "$GITHUB_REF_NAME"
+
# Two keys, one per channel (they install side by side as two apps):
# betas ("v2.0.0-beta.3") use MYSPOTI_KEYSTORE_BASE64, MYSPOTI_KEYSTORE_PASSWORD,
# MYSPOTI_KEY_ALIAS, MYSPOTI_KEY_PASSWORD; releases use the same names with
@@ -104,11 +110,13 @@ jobs:
MYSPOTI_KEY_PASSWORD: ${{ contains(github.ref_name, '-') && secrets.MYSPOTI_KEY_PASSWORD || secrets.MYSPOTI_STABLE_KEY_PASSWORD }}
run: |
VERSION="${GITHUB_REF_NAME#v}"
+ # myspoti-beta-2.2.1-beta.1.apk / myspoti-stable-2.2.1.apk: Obtainium filters on the channel.
+ CHANNEL=stable; case "$VERSION" in *-*) CHANNEL=beta ;; esac
./gradlew assembleRelease \
-PappVersionName="$VERSION" \
-PappVersionCode="$((1000 + GITHUB_RUN_NUMBER))" \
-PupdateRepo="$GITHUB_REPOSITORY"
- mv app/build/outputs/apk/release/app-release.apk "app/build/outputs/apk/release/myspoti-$VERSION.apk"
+ mv app/build/outputs/apk/release/app-release.apk "app/build/outputs/apk/release/myspoti-$CHANNEL-$VERSION.apk"
# This version's section of CHANGELOG.md becomes the release description.
- name: Release notes
diff --git a/README.md b/README.md
index 8d732a89..2ed9fab8 100644
--- a/README.md
+++ b/README.md
@@ -44,6 +44,11 @@ Under the hood, the official Spotify Web Player plays the music, hidden inside t
New versions are offered inside the app: one tap downloads and installs them.
+Obtainium (add `https://github.com/kota-zo/myspoti`; the stable app and the beta app are two apps and each release carries one APK named for its channel):
+- **Stable** (`app.myspoti.stable`): leave "Include prereleases" off and set the APK filter to `^myspoti-stable-.*\.apk$`.
+- **Beta** (`app.myspoti`): turn "Include prereleases" on and set the APK filter to `^myspoti-beta-.*\.apk$`.
+- Betas are named `<next version>-beta.<n>` (`2.2.1-beta.1`, then `2.2.1-beta.2`...), marked prerelease on GitHub, and always newer than the last stable.
+
## What you get
**Listening**
@@ -155,7 +160,7 @@ google-chrome --user-data-dir="$HOME/.myspoti-chrome" --remote-debugging-port=92
./gradlew :host-cdp:test -Pcdp=http://localhost:9222
```
-Every push builds and tests on GitHub Actions. A `v*` tag publishes a signed APK in Releases.
+Every push builds and tests on GitHub Actions. A `vX.Y.Z` tag publishes a stable APK in Releases and a `vX.Y.Z-beta.N` tag a beta one (a prerelease, `tools/check_tag.py` checks the number).
## Credits
diff --git a/base/app/src/main/java/com/music/spotui/data/api/UpdateChecker.kt b/base/app/src/main/java/com/music/spotui/data/api/UpdateChecker.kt
index 917a8a1f..748de272 100644
--- a/base/app/src/main/java/com/music/spotui/data/api/UpdateChecker.kt
+++ b/base/app/src/main/java/com/music/spotui/data/api/UpdateChecker.kt
@@ -119,14 +119,15 @@ object UpdateChecker {
return Release(version, url, prefs.getString("notes", null).orEmpty(), prefs.getString("apk", null).orEmpty()).takeIf { isNewer(version, BuildConfig.VERSION_NAME) }
}
- /** The release's APK download link (the CI uploads one `myspoti-<version>.apk`). */
+ /** The release's APK download link (the CI uploads one `myspoti-<beta|stable>-<version>.apk`; older releases `myspoti-<version>.apk`). */
internal fun apkAsset(release: JSONObject): String {
val assets = release.optJSONArray("assets") ?: return ""
val all = (0 until assets.length()).map { assets.getJSONObject(it) }
// This release's own APK first: a release carrying several APKs (both
// channels) must not hand a phone the other channel's build.
- val want = "myspoti-${release.optString("tag_name").removePrefix("v")}.apk"
- return (all.firstOrNull { it.optString("name") == want }
+ val version = release.optString("tag_name").removePrefix("v")
+ val want = setOf("myspoti-beta-$version.apk", "myspoti-stable-$version.apk", "myspoti-$version.apk")
+ return (all.firstOrNull { it.optString("name") in want }
?: all.firstOrNull { it.optString("name").endsWith(".apk", ignoreCase = true) })
?.optString("browser_download_url").orEmpty()
}
diff --git a/base/app/src/test/java/com/music/spotui/data/api/UpdateCheckerTest.kt b/base/app/src/test/java/com/music/spotui/data/api/UpdateCheckerTest.kt
index ca4fa3f8..b84a7374 100644
--- a/base/app/src/test/java/com/music/spotui/data/api/UpdateCheckerTest.kt
+++ b/base/app/src/test/java/com/music/spotui/data/api/UpdateCheckerTest.kt
@@ -40,6 +40,10 @@ class UpdateCheckerTest {
{"name":"checksums.txt","browser_download_url":"https://x/c.txt"},
{"name":"myspoti-2.0.0-beta.4.apk","browser_download_url":"https://x/myspoti.apk"}]}""")
assertEquals("https://x/myspoti.apk", UpdateChecker.apkAsset(release))
+ val both = org.json.JSONObject("""{"tag_name":"v2.2.1-beta.1","assets":[
+ {"name":"myspoti-stable-2.2.0.apk","browser_download_url":"https://x/stable.apk"},
+ {"name":"myspoti-beta-2.2.1-beta.1.apk","browser_download_url":"https://x/beta.apk"}]}""")
+ assertEquals("https://x/beta.apk", UpdateChecker.apkAsset(both))
assertEquals("", UpdateChecker.apkAsset(org.json.JSONObject("{}")))
}
}
diff --git a/tools/check_tag.py b/tools/check_tag.py
new file mode 100755
index 00000000..bdd67af3
--- /dev/null
+++ b/tools/check_tag.py
@@ -0,0 +1,51 @@
+#!/usr/bin/env python3
+"""Checks a release tag before the CI builds it, so Obtainium (and the app's own update check)
+can always compare versions in strict semver.
+
+ python3 tools/check_tag.py v2.2.1-beta.1
+
+A tag is `vX.Y.Z` (stable) or `vX.Y.Z-beta.N` (beta, N from 1). A beta must be newer than every
+existing tag: its X.Y.Z is the next version (above the last stable), N counts up from 1.
+A stable must be newer than every other stable (a hotfix may follow a newer beta line).
+Run from a clone that has the tags; exits 1 with a message when the tag does not fit.
+"""
+import re
+import subprocess
+import sys
+
+TAG = re.compile(r"^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-beta\.([1-9]\d*))?$")
+
+
+def key(tag):
+ """Semver order: X.Y.Z, then a stable above its betas, then the beta number."""
+ m = TAG.match(tag)
+ if not m:
+ return None
+ n = m.group(4)
+ return (int(m.group(1)), int(m.group(2)), int(m.group(3)), 1 if n is None else 0, int(n or 0))
+
+
+def check(tag, others):
+ mine = key(tag)
+ if mine is None:
+ return f'"{tag}" is not vX.Y.Z or vX.Y.Z-beta.N (strict semver, N from 1).'
+ stable = mine[3] == 1
+ for other in others:
+ k = key(other)
+ if k is None or other == tag:
+ continue # older tags in another format are not compared
+ if (not stable or k[3] == 1) and k >= mine:
+ return (f'"{tag}" must be newer than the existing "{other}": a beta follows the last stable '
+ f'(2.2.0 -> 2.2.1-beta.1 or 2.3.0-beta.1, then beta.2...), a stable follows its betas.')
+ return None
+
+
+if __name__ == "__main__":
+ if len(sys.argv) != 2:
+ sys.exit("usage: check_tag.py vX.Y.Z[-beta.N]")
+ existing = subprocess.run(["git", "tag", "-l", "v*"], capture_output=True, text=True, check=True).stdout.split()
+ problem = check(sys.argv[1], existing)
+ if problem:
+ print(f"::error::{problem}")
+ sys.exit(1)
+ print(f"{sys.argv[1]} is a valid next tag.")