diff --git a/scripts/run-docs-build b/scripts/run-docs-build
index acd8a24..090e5b0 100755
--- a/scripts/run-docs-build
+++ b/scripts/run-docs-build
@@ -111,7 +111,12 @@ mkdir $outputdir/bitbake
 # see the latest releases.
 first_sphinx_commit=84ccba0f4aff91528f764523fe1205a354c889ed
 
-latest_branch=$(git branch --remote --contains "$first_sphinx_commit" --format '%(refname:lstrip=3)' --sort='-version:refname' | grep --max-count=1 "[0-9]*\.[0-9]*")
+latest_branch=$(./setversions.py --get-latest-branch 2>/dev/null)
+if ! echo "$latest_branch" | grep -qE "^[0-9]+\.[0-9]+$"; then
+  echo "Got unexpected branch from ./set_versions.py: $latest_branch"
+  echo "Should be in X.Y format"
+  exit 1
+fi
 
 for branch in 1.46 $(git branch --remote --contains "$first_sphinx_commit" --format '%(refname:lstrip=3)'); do
     if [ "$branch" = "HEAD" ]; then
