Skip to content

Commit b2ac0d9

Browse files
Fix docs version detection for master branch builds
Use `git describe --tags --abbrev=0` instead of `--always` to get the latest tag without commit count suffix. This prevents the documentation from showing dev versions like "v3.21.2-2-g8d4e41c" when the master branch is pushed before its corresponding version tag is created. The issue occurred because: 1. Master branch push triggers docs build 2. Version tag is created after the push 3. git describe --always returns a dev version since no exact tag match Now the master docs will show the latest clean tag version regardless of the timing between master push and tag creation. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 8d4e41c commit b2ac0d9

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

docs/conf.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,19 @@
77

88

99
def get_version():
10-
# Use git commands to get version from the checked-out ref.
11-
# sphinx-multiversion checks out each ref to a temp directory and runs Sphinx there.
12-
# Use current working directory to get the version of the checked-out ref.
10+
"""Get version from git tags.
11+
12+
This function is used to determine the version for documentation builds.
13+
For the master branch, we use the latest tag (--abbrev=0) instead of
14+
git describe's default behavior which would show a dev version like
15+
"v3.21.2-2-g8d4e41c" when HEAD is ahead of the latest tag.
16+
17+
This ensures that when master and a tag point to the same commit,
18+
the documentation shows the clean version (e.g., "3.22.0") regardless
19+
of whether the tag was created before or after the docs build started.
20+
"""
21+
# Try to get exact tag (for tagged commits)
1322
try:
14-
# Try to get exact tag (for tagged commits)
1523
result = subprocess.run(
1624
["git", "describe", "--tags", "--exact-match"],
1725
capture_output=True,
@@ -25,18 +33,20 @@ def get_version():
2533
except (subprocess.CalledProcessError, FileNotFoundError):
2634
pass
2735

28-
# Try to get version using git describe (for non-tagged commits)
36+
# Get the latest tag (without commit count suffix)
37+
# This is used for master branch builds to show a clean version
38+
# instead of a dev version like "v3.21.2-2-g8d4e41c"
2939
try:
3040
result = subprocess.run(
31-
["git", "describe", "--tags", "--always"],
41+
["git", "describe", "--tags", "--abbrev=0"],
3242
capture_output=True,
3343
text=True,
3444
check=True,
3545
)
36-
version_str = result.stdout.strip()
37-
if version_str and version_str.startswith("v"):
38-
return version_str[1:] # Remove 'v' prefix
39-
return version_str
46+
tag = result.stdout.strip()
47+
if tag and tag.startswith("v"):
48+
return tag[1:] # Remove 'v' prefix
49+
return tag
4050
except (subprocess.CalledProcessError, FileNotFoundError):
4151
pass
4252

0 commit comments

Comments
 (0)