Skip to content

Speakr is a personal, self-hosted web application designed for transcribing audio recordings

Python

Version-sync infrastructure + bump VERSION to v0.9.0 — fixes the long-standing problem where VERSION at repo root drifted out of sync with the README version badge and the docs (the About page in the Speakr app reads VERSION via src/config/version.py's get_version(), so when VERSION lags behind a release commit the in-app About page silently shows a stale version even though the README and docs already advertise the new one); two-part fix: (1) bumps VERSION from v0.8.21-alpha to v0.9.0 to match the README badge, docs/index.md banner, release_notes_v0.9.0.md, and the v0.9.0 docs Wave 1+2 commits; (2) extends scripts/pre-commit (the hook is already symlinked into .git/hooks/pre-commit per the existing install line) to detect drift on every commit that touches README.md or VERSION — when either is staged the hook parses the version out of the shields.io badge URL in the README, compares it to the VERSION file contents, and if they differ rewrites VERSION + git-adds it so the commit captures the sync; the hook is intentionally non-blocking (no exit 1) since the auto-fix is safe, just prints a 'Syncing VERSION file: old → new' line so the author sees what happened; also upgrades scripts/update_version.py so the manual flow (python scripts/update_version.py v0.9.1) now updates BOTH the VERSION file AND the README badge in one shot, then optionally creates the git tag — previously the script only touched VERSION which is what got us into this drift situation; the README badge is the single source of truth in both flows so it doesn't matter whether you bump README and let the hook fix VERSION, or run the script which fixes both at once

Murtaza Nasir587f6a4dc618
diff --git a/VERSION b/VERSION
index b0af4174..f979adec 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-v0.8.21-alpha
+v0.9.0
diff --git a/scripts/pre-commit b/scripts/pre-commit
index 592cd0d5..77667610 100755
--- a/scripts/pre-commit
+++ b/scripts/pre-commit
@@ -1,13 +1,18 @@
#!/bin/sh
#
-# Pre-commit hook: runs PostgreSQL migration compatibility tests
-# when migration-related files are staged.
+# Pre-commit hook:
+# 1. Runs PostgreSQL migration compatibility tests when migration-related
+# files are staged.
+# 2. Keeps the VERSION file in sync with the README version badge so the
+# About page in the app never lags behind a release commit.
#
# Install: ln -sf ../../scripts/pre-commit .git/hooks/pre-commit
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM)
-# Only run if migration-related files are staged
+# ---------------------------------------------------------------------------
+# 1. Migration compatibility check
+# ---------------------------------------------------------------------------
if echo "$STAGED_FILES" | grep -qE '^(src/init_db\.py|src/utils/database\.py|src/models/)'; then
echo "Migration files changed — running PostgreSQL compatibility checks..."
python tests/test_migration_compatibility.py
@@ -19,3 +24,33 @@ if echo "$STAGED_FILES" | grep -qE '^(src/init_db\.py|src/utils/database\.py|src
fi
echo "All migration compatibility checks passed."
fi
+
+# ---------------------------------------------------------------------------
+# 2. VERSION-file sync
+# ---------------------------------------------------------------------------
+# Source of truth: the version inside the README shields.io badge
+# https://img.shields.io/badge/version-X.Y.Z[-suffix]-<colour>.svg
+# When that badge moves (typical release commit edit), or when somebody
+# touches VERSION directly, we make sure both files end up with the same
+# value and re-stage them so the commit captures it.
+if echo "$STAGED_FILES" | grep -qE '^(README\.md|VERSION)$'; then
+ if [ -f README.md ] && [ -f VERSION ]; then
+ # Extract version from README badge. Accepts X.Y.Z or X.Y.Z-suffix.
+ README_VER=$(grep -oE 'shields\.io/badge/version-[0-9]+\.[0-9]+\.[0-9]+[A-Za-z0-9.-]*-[a-z]+\.svg' README.md \
+ | head -1 \
+ | sed -E 's|shields\.io/badge/version-([0-9]+\.[0-9]+\.[0-9]+[A-Za-z0-9.-]*)-[a-z]+\.svg|\1|')
+
+ if [ -z "$README_VER" ]; then
+ echo "Version-sync skipped: could not parse version from README badge."
+ else
+ EXPECTED="v${README_VER}"
+ CURRENT=$(tr -d '[:space:]' < VERSION)
+
+ if [ "$CURRENT" != "$EXPECTED" ]; then
+ echo "Syncing VERSION file: $CURRENT → $EXPECTED (from README badge)"
+ printf '%s\n' "$EXPECTED" > VERSION
+ git add VERSION
+ fi
+ fi
+ fi
+fi
diff --git a/scripts/update_version.py b/scripts/update_version.py
index 15128646..f8ee1de5 100644
--- a/scripts/update_version.py
+++ b/scripts/update_version.py
@@ -1,60 +1,73 @@
#!/usr/bin/env python3
"""
-Simple script to update the VERSION file.
-Usage: python update_version.py v0.4.3
+Update the VERSION file and the README shields.io version badge in lockstep,
+then optionally create + push a git tag.
+
+Usage:
+ python scripts/update_version.py v0.9.0
+ python scripts/update_version.py 0.9.0
"""
-import sys
+import os
import re
+import subprocess
+import sys
+
+
+REPO_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+VERSION_FILE = os.path.join(REPO_ROOT, "VERSION")
+README_FILE = os.path.join(REPO_ROOT, "README.md")
+
+BADGE_RE = re.compile(
+ r"(shields\.io/badge/version-)"
+ r"[0-9]+\.[0-9]+\.[0-9]+[A-Za-z0-9.-]*"
+ r"(-[a-z]+\.svg)"
+)
+
+
+def update_version(raw):
+ if not re.match(r"^v?\d+\.\d+\.\d+", raw):
+ print(f"Warning: '{raw}' doesn't look like X.Y.Z[-suffix]")
+
+ tag = raw if raw.startswith("v") else f"v{raw}"
+ bare = tag[1:]
+
+ with open(VERSION_FILE, "w") as f:
+ f.write(f"{tag}\n")
+ print(f"VERSION → {tag}")
+
+ if os.path.exists(README_FILE):
+ with open(README_FILE) as f:
+ text = f.read()
+ new_text, n = BADGE_RE.subn(lambda m: f"{m.group(1)}{bare}{m.group(2)}", text, count=1)
+ if n == 0:
+ print("README badge not found — skipped")
+ elif new_text != text:
+ with open(README_FILE, "w") as f:
+ f.write(new_text)
+ print(f"README badge → {bare}")
+ else:
+ print("README badge already in sync")
-def update_version(new_version):
- # Validate version format (basic check)
- if not re.match(r'^v?\d+\.\d+\.\d+', new_version):
- print(f"Warning: Version '{new_version}' doesn't follow standard format (v1.2.3)")
-
- # Ensure version starts with 'v'
- if not new_version.startswith('v'):
- new_version = 'v' + new_version
-
- # Write to VERSION file
try:
- with open('VERSION', 'w') as f:
- f.write(new_version)
- print(f"✅ Updated VERSION file to: {new_version}")
-
- # Optional: Create git tag if in a git repo
- import subprocess
- try:
- # Check if we're in a git repo
- subprocess.check_output(['git', 'status'], stderr=subprocess.DEVNULL)
-
- # Create and push tag
- subprocess.check_output(['git', 'tag', new_version], stderr=subprocess.DEVNULL)
- print(f"✅ Created git tag: {new_version}")
-
- # Ask user if they want to push
- response = input("Push tag to remote? (y/N): ").strip().lower()
- if response == 'y':
- subprocess.check_output(['git', 'push', 'origin', new_version])
- print(f"✅ Pushed tag {new_version} to remote")
-
- except subprocess.CalledProcessError:
- print("ℹ️ Not in a git repo or git tag already exists")
- except Exception as e:
- print(f"ℹ️ Git operations failed: {e}")
-
- except Exception as e:
- print(f"❌ Failed to update VERSION file: {e}")
- return False
-
+ subprocess.check_output(["git", "rev-parse", "--git-dir"], stderr=subprocess.DEVNULL)
+ except (subprocess.CalledProcessError, FileNotFoundError):
+ print("Not in a git repo — skipping tag step")
+ return True
+
+ try:
+ subprocess.check_output(["git", "tag", tag], stderr=subprocess.DEVNULL)
+ print(f"Created git tag: {tag}")
+ if input("Push tag to remote? (y/N): ").strip().lower() == "y":
+ subprocess.check_output(["git", "push", "origin", tag])
+ print(f"Pushed {tag}")
+ except subprocess.CalledProcessError:
+ print(f"Tag {tag} already exists locally — skipping")
+
return True
+
if __name__ == "__main__":
if len(sys.argv) != 2:
- print("Usage: python update_version.py <version>")
- print("Example: python update_version.py v0.4.3")
- print("Example: python update_version.py 0.4.3-alpha")
+ print("Usage: python scripts/update_version.py vX.Y.Z[-suffix]")
sys.exit(1)
-
- new_version = sys.argv[1]
- success = update_version(new_version)
- sys.exit(0 if success else 1)
\ No newline at end of file
+ sys.exit(0 if update_version(sys.argv[1]) else 1)