Skip to content

A cross platform Audiobookshelf client for Android and iOS

Dart

Give each beta build its own release tag and teach the updater to compare build numbers

Barnabasb770cc16f168
diff --git a/.github/workflows/all-release.yml b/.github/workflows/all-release.yml
index ab9951ac..41c78ab8 100644
--- a/.github/workflows/all-release.yml
+++ b/.github/workflows/all-release.yml
@@ -14,7 +14,7 @@ on:
workflow_dispatch:
inputs:
prerelease:
- description: "Pre-release? Uploads to v<version>-pre, marks it prerelease, adds -pre to the filenames"
+ description: "Pre-release? Uploads to a per-build v<version>-<build> tag, marks it prerelease, adds -pre to the filenames"
required: false
type: boolean
default: false
@@ -76,11 +76,15 @@ jobs:
run: |
RAW=$(grep '^version:' pubspec.yaml | sed 's/version: *//')
VERSION_NAME="${RAW%%+*}"
+ BUILD="${RAW##*+}"
# Unified artifact basename: dash (URL-safe, unlike +) between version
# and build number, plus a -pre suffix for prereleases.
BASE="absorb-${RAW//+/-}"
if [ "$PRE" = "true" ]; then
- echo "tag=v${VERSION_NAME}-pre" >> "$GITHUB_OUTPUT"
+ # Per-build tag: Obtainium and the in-app updater key on the tag,
+ # so each beta build needs its own. Finals keep the clean tag,
+ # which is also the only shape F-Droid's checkupdates matches.
+ echo "tag=v${VERSION_NAME}-${BUILD}" >> "$GITHUB_OUTPUT"
echo "fname=${BASE}-pre" >> "$GITHUB_OUTPUT"
else
echo "tag=v${VERSION_NAME}" >> "$GITHUB_OUTPUT"
diff --git a/.github/workflows/android-release.yml b/.github/workflows/android-release.yml
index f1275899..f77759b9 100644
--- a/.github/workflows/android-release.yml
+++ b/.github/workflows/android-release.yml
@@ -13,7 +13,7 @@ on:
workflow_dispatch:
inputs:
prerelease:
- description: "Pre-release? Uploads to v<version>-pre, marks it prerelease, adds -pre to the filenames"
+ description: "Pre-release? Uploads to a per-build v<version>-<build> tag, marks it prerelease, adds -pre to the filenames"
required: false
type: boolean
default: false
@@ -48,11 +48,15 @@ jobs:
run: |
RAW=$(grep '^version:' pubspec.yaml | sed 's/version: *//')
VERSION_NAME="${RAW%%+*}"
+ BUILD="${RAW##*+}"
# Unified artifact basename: dash (URL-safe, unlike +) between version
# and build number, plus a -pre suffix for prereleases.
BASE="absorb-${RAW//+/-}"
if [ "$PRE" = "true" ]; then
- echo "tag=v${VERSION_NAME}-pre" >> "$GITHUB_OUTPUT"
+ # Per-build tag: Obtainium and the in-app updater key on the tag,
+ # so each beta build needs its own. Finals keep the clean tag,
+ # which is also the only shape F-Droid's checkupdates matches.
+ echo "tag=v${VERSION_NAME}-${BUILD}" >> "$GITHUB_OUTPUT"
echo "fname=${BASE}-pre" >> "$GITHUB_OUTPUT"
else
echo "tag=v${VERSION_NAME}" >> "$GITHUB_OUTPUT"
diff --git a/.github/workflows/github-release.yml b/.github/workflows/github-release.yml
index 68361959..c0f7b4e3 100644
--- a/.github/workflows/github-release.yml
+++ b/.github/workflows/github-release.yml
@@ -10,6 +10,12 @@ name: GitHub APK Only
on:
workflow_dispatch:
+ inputs:
+ prerelease:
+ description: "Pre-release? Uploads to a per-build v<version>-<build> tag, marks it prerelease, adds -pre to the filename"
+ required: false
+ type: boolean
+ default: false
jobs:
build:
@@ -36,11 +42,27 @@ jobs:
- name: Read pubspec version
id: version
+ env:
+ PRE: ${{ inputs.prerelease }}
run: |
RAW=$(grep '^version:' pubspec.yaml | sed 's/version: *//')
VERSION_NAME="${RAW%%+*}"
+ BUILD="${RAW##*+}"
+ # Unified artifact basename: dash (URL-safe, unlike +) between version
+ # and build number, plus a -pre suffix for prereleases.
+ BASE="absorb-${RAW//+/-}"
+ if [ "$PRE" = "true" ]; then
+ # Per-build tag: Obtainium and the in-app updater key on the tag,
+ # so each beta build needs its own. Finals keep the clean tag,
+ # which is also the only shape F-Droid's checkupdates matches.
+ echo "tag=v${VERSION_NAME}-${BUILD}" >> "$GITHUB_OUTPUT"
+ echo "fname=${BASE}-pre" >> "$GITHUB_OUTPUT"
+ else
+ echo "tag=v${VERSION_NAME}" >> "$GITHUB_OUTPUT"
+ echo "fname=${BASE}" >> "$GITHUB_OUTPUT"
+ fi
echo "raw=$RAW" >> "$GITHUB_OUTPUT"
- echo "tag=v$VERSION_NAME" >> "$GITHUB_OUTPUT"
+ echo "pre=$PRE" >> "$GITHUB_OUTPUT"
- name: Notify Discord (build started)
if: env.DISCORD_WEBHOOK_URL != ''
@@ -74,28 +96,30 @@ jobs:
- name: Rename APK with version
env:
- RAW: ${{ steps.version.outputs.raw }}
+ FNAME: ${{ steps.version.outputs.fname }}
run: |
# gradle already names the APK absorb-<version>-<code>.apk, so skip
# the mv when source and destination are the same file.
APK_SRC=$(ls build/app/outputs/apk/github/release/*.apk | head -1)
- APK_DST="build/app/outputs/apk/github/release/absorb-${RAW//+/-}.apk"
+ APK_DST="build/app/outputs/apk/github/release/${FNAME}.apk"
[ "$APK_SRC" = "$APK_DST" ] || mv "$APK_SRC" "$APK_DST"
- name: Upload APK to GitHub draft release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION_TAG: ${{ steps.version.outputs.tag }}
+ PRE: ${{ steps.version.outputs.pre }}
run: |
if gh release view "$VERSION_TAG" &>/dev/null; then
gh release upload "$VERSION_TAG" \
build/app/outputs/apk/github/release/*.apk \
--clobber
else
+ CREATE_ARGS=(--draft --title "$VERSION_TAG")
+ [ "$PRE" = "true" ] && CREATE_ARGS+=(--prerelease)
gh release create "$VERSION_TAG" \
build/app/outputs/apk/github/release/*.apk \
- --draft \
- --title "$VERSION_TAG"
+ "${CREATE_ARGS[@]}"
fi
- name: Notify Discord (build finished)
diff --git a/.github/workflows/ios-release.yml b/.github/workflows/ios-release.yml
index deff1657..2748c5c1 100644
--- a/.github/workflows/ios-release.yml
+++ b/.github/workflows/ios-release.yml
@@ -9,7 +9,7 @@ on:
workflow_dispatch:
inputs:
prerelease:
- description: "Pre-release? Uploads to v<version>-pre, marks it prerelease, adds -pre to the filename"
+ description: "Pre-release? Uploads to a per-build v<version>-<build> tag, marks it prerelease, adds -pre to the filename"
required: false
type: boolean
default: false
@@ -64,11 +64,15 @@ jobs:
run: |
RAW=$(grep '^version:' pubspec.yaml | sed 's/version: *//')
VERSION_NAME="${RAW%%+*}"
+ BUILD="${RAW##*+}"
# Unified artifact basename: dash (URL-safe, unlike +) between version
# and build number, plus a -pre suffix for prereleases.
BASE="absorb-${RAW//+/-}"
if [ "$PRE" = "true" ]; then
- echo "tag=v${VERSION_NAME}-pre" >> "$GITHUB_OUTPUT"
+ # Per-build tag: Obtainium and the in-app updater key on the tag,
+ # so each beta build needs its own. Finals keep the clean tag,
+ # which is also the only shape F-Droid's checkupdates matches.
+ echo "tag=v${VERSION_NAME}-${BUILD}" >> "$GITHUB_OUTPUT"
echo "fname=${BASE}-pre" >> "$GITHUB_OUTPUT"
else
echo "tag=v${VERSION_NAME}" >> "$GITHUB_OUTPUT"
diff --git a/lib/services/update_checker_service.dart b/lib/services/update_checker_service.dart
index 1e6123be..2c3804b9 100644
--- a/lib/services/update_checker_service.dart
+++ b/lib/services/update_checker_service.dart
@@ -27,18 +27,27 @@ class UpdateInfo {
bool get hasUpdate => _compareVersions(latestVersion, currentVersion) > 0;
}
-/// Compare semver strings. Returns positive if a > b, negative if a < b, 0 if equal.
+/// Compare versions like v1.9.1, v1.9.1-176, or 1.9.1+176: semver first, then
+/// the trailing build number. Returns positive if a > b, negative if a < b,
+/// 0 if equal. Builds only compare when both sides have one, so a clean final
+/// tag never out-ranks the beta build it was promoted from.
int _compareVersions(String a, String b) {
- final aParts = a.replaceAll(RegExp(r'^v'), '').split('.').map((s) => int.tryParse(s) ?? 0).toList();
- final bParts = b.replaceAll(RegExp(r'^v'), '').split('.').map((s) => int.tryParse(s) ?? 0).toList();
+ final (aSem, aBuild) = _parseVersion(a);
+ final (bSem, bBuild) = _parseVersion(b);
for (int i = 0; i < 3; i++) {
- final av = i < aParts.length ? aParts[i] : 0;
- final bv = i < bParts.length ? bParts[i] : 0;
- if (av != bv) return av - bv;
+ if (aSem[i] != bSem[i]) return aSem[i] - bSem[i];
}
+ if (aBuild != null && bBuild != null) return aBuild - bBuild;
return 0;
}
+(List<int>, int?) _parseVersion(String v) {
+ final sem = RegExp(r'(\d+)\.(\d+)\.(\d+)').firstMatch(v);
+ final parts = [for (var i = 1; i <= 3; i++) int.parse(sem?.group(i) ?? '0')];
+ final build = RegExp(r'[-+](\d+)$').firstMatch(v);
+ return (parts, build == null ? null : int.parse(build.group(1)!));
+}
+
class UpdateCheckerService {
static const _repo = 'pounat/absorb'; // Update this to your repo
static const _checkInterval = Duration(hours: 12);
@@ -98,7 +107,7 @@ class UpdateCheckerService {
}
final packageInfo = await PackageInfo.fromPlatform();
- final currentVersion = packageInfo.version;
+ final currentVersion = '${packageInfo.version}+${packageInfo.buildNumber}';
final info = UpdateInfo(
latestVersion: tagName,