Skip to content

Commit c83ae77

Browse files
committed
Get tag from VERSION manifest
Signed-off-by: Keshav Priyadarshi <[email protected]>
1 parent 79f181c commit c83ae77

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = vulnerablecode
3-
version = 36.1.0
3+
version = 36.1.2
44
license = Apache-2.0 AND CC-BY-SA-4.0
55

66
# description must be on ONE line https://github.com/pypa/setuptools/issues/1390

vulnerabilities/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2005,7 +2005,7 @@ def set_vulnerablecode_version_and_commit(self):
20052005
msg = f"Field vulnerablecode_version already set to {self.vulnerablecode_version}"
20062006
raise ValueError(msg)
20072007

2008-
self.vulnerablecode_version = VULNERABLECODE_VERSION
2008+
self.vulnerablecode_version = vulnerablecode.get_git_tag()
20092009
self.vulnerablecode_commit = vulnerablecode.get_short_commit()
20102010
self.save(update_fields=["vulnerablecode_version", "vulnerablecode_commit"])
20112011

vulnerablecode/__init__.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import git
1616

17-
__version__ = "36.1.0"
17+
__version__ = "36.1.2"
1818

1919

2020
PROJECT_DIR = Path(__file__).resolve().parent
@@ -49,6 +49,29 @@ def get_git_commit_from_version_file():
4949
return
5050

5151

52+
def get_git_tag_from_version_file():
53+
"""Return the tag from the ".VERSION" file."""
54+
version_file = ROOT_DIR / ".VERSION"
55+
if not version_file.exists():
56+
return
57+
58+
try:
59+
lines = version_file.read_text().splitlines()
60+
ref_line = lines[0]
61+
if "tag:" in ref_line:
62+
if vcio_tag := ref_line.split("tag:")[-1].strip():
63+
return vcio_tag
64+
except (UnicodeDecodeError):
65+
return
66+
67+
68+
def get_git_tag():
69+
"""Return the tag from the ".VERSION" file or __version__."""
70+
if vcio_tag := get_git_tag_from_version_file():
71+
return vcio_tag
72+
return __version__
73+
74+
5275
def get_short_commit():
5376
"""
5477
Return the short commit hash from the .VERSION file or from `git describe`

0 commit comments

Comments
 (0)