Skip to content

Commit 6fde950

Browse files
committed
Add version_requirement with the sha if we can get it from Git
The macros plugin already offer easy access to git info, so we can do a last resort try of getting the current sha from there. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 831faf0 commit 6fde950

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/frequenz/repo/config/mkdocs/mkdocstrings_macros.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ def add_version_variables(
175175
"No repo_url provided, can't build the 'version_requirement' variable"
176176
)
177177

178+
version_info = None
178179
try:
179180
version_info = get_repo_version_info()
180181
except Exception as exc: # pylint: disable=broad-except
@@ -183,11 +184,13 @@ def add_version_variables(
183184
env.variables["version"] = version_info
184185
if version_info.current_tag:
185186
env.variables["version_requirement"] = f" == {version_info.current_tag}"
186-
elif version_info.current_branch or version_info.sha:
187-
if repo_url is not None:
188-
env.variables["version_requirement"] = (
189-
f" @ git+{repo_url}@{version_info.current_branch or version_info.sha}"
190-
)
187+
188+
ref = None
189+
if version_info is not None:
190+
ref = version_info.current_branch or version_info.sha
191+
ref = ref or env.variables.get("git", {}).get("commit")
192+
if ref and repo_url is not None:
193+
env.variables["version_requirement"] = f" @ git+{repo_url}@{ref}"
191194

192195

193196
def hook_macros_plugin(env: macros.MacrosPlugin) -> None:

0 commit comments

Comments
 (0)