Skip to content

Commit bda580f

Browse files
committed
Merge branch 'doc/version_specific_inc_bugfix' into 'master'
docs: wrong version specific includes Closes DOC-322 and IDFGH-3734 See merge request espressif/esp-idf!9809
2 parents 2ad8f8c + b529b75 commit bda580f

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

docs/idf_extensions/gen_version_specific_includes.py

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -190,31 +190,26 @@ def write_version_note(template, out_dir, version, ver_type, is_stable):
190190

191191
def get_version():
192192
"""
193-
Returns a tuple of (name of branch/tag, type branch/tag, is_stable)
193+
Returns a tuple of (name of branch/tag/commit-id, type branch/tag/commit, is_stable)
194194
"""
195-
# Trust what RTD says our version is, if it is set
196-
version = os.environ.get("READTHEDOCS_VERSION", None)
197-
if version == "latest":
198-
return ("master", "branch", False)
199-
200-
# Otherwise, use git to look for a tag
195+
# Use git to look for a tag
201196
try:
202197
tag = subprocess.check_output(["git", "describe", "--tags", "--exact-match"]).strip().decode('utf-8')
203198
is_stable = re.match(r"v[0-9\.]+$", tag) is not None
204199
return (tag, "tag", is_stable)
205200
except subprocess.CalledProcessError:
206201
pass
207202

208-
# No tag, look for a branch
209-
refs = subprocess.check_output(["git", "for-each-ref", "--points-at", "HEAD", "--format", "%(refname)"]).decode('utf-8')
210-
print("refs:\n%s" % refs)
211-
refs = refs.split("\n")
212-
# Note: this looks for branches in 'origin' because GitLab CI doesn't check out a local branch
213-
branches = [r.replace("refs/remotes/origin/","").strip() for r in refs if r.startswith("refs/remotes/origin/")]
214-
if len(branches) == 0:
215-
# last resort, return the commit (may happen on Gitlab CI sometimes, unclear why)
216-
return (subprocess.check_output(["git", "rev-parse", "--short", "HEAD"]).strip().decode('utf-8'), "commit", False)
217-
if "master" in branches:
218-
return ("master", "branch", False)
219-
else:
220-
return (branches[0], "branch", False) # take whatever the first branch is
203+
# No tag, look at branch name from CI, this will give the correct branch name even if the ref for the branch we
204+
# merge into has moved forward before the pipeline runs
205+
branch = os.environ.get("CI_COMMIT_REF_NAME", None)
206+
if branch is not None:
207+
return (branch, "branch", False)
208+
209+
# Try to find the branch name even if docs are built locally
210+
branch = subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"]).decode('utf-8')
211+
if branch != "HEAD":
212+
return (branch, "branch", False)
213+
214+
# As a last resort we return commit SHA-1, should never happen in CI/docs that should be published
215+
return (subprocess.check_output(["git", "rev-parse", "--short", "HEAD"]).strip().decode('utf-8'), "commit", False)

0 commit comments

Comments
 (0)