update
This commit is contained in:
@@ -18,6 +18,7 @@ import fnmatch
|
||||
import ast
|
||||
import tokenize
|
||||
import io
|
||||
import re
|
||||
|
||||
def minify_python_code(source_code: str) -> str:
|
||||
"""
|
||||
@@ -265,20 +266,44 @@ def create_zip_package(source_dir: Path, output_file: Path, addon_name: str):
|
||||
|
||||
def get_version_from_git() -> Optional[str]:
|
||||
"""Get version from git tags."""
|
||||
project_root = get_project_root()
|
||||
try:
|
||||
config = load_config()
|
||||
version_pattern = config['versions']['git_tag_pattern']
|
||||
except Exception as e:
|
||||
print(f"Warning: Could not load version pattern: {e}")
|
||||
version_pattern = r"^v?([0-9]+\.[0-9]+\.[0-9]+)$"
|
||||
|
||||
version_regex = re.compile(version_pattern)
|
||||
|
||||
try:
|
||||
result = subprocess.run(
|
||||
['python3', 'build/sync_version.py', '--version'],
|
||||
capture_output=True, text=True, cwd=get_project_root()
|
||||
['git', 'tag', '-l', '--sort=-version:refname'],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
cwd=project_root,
|
||||
check=True
|
||||
)
|
||||
if result.returncode == 0:
|
||||
# Extract version from output
|
||||
lines = result.stdout.strip().split('\n')
|
||||
for line in lines:
|
||||
if 'Synchronizing version:' in line:
|
||||
return line.split(':')[1].strip().split()[0]
|
||||
except Exception as e:
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"Warning: Could not get version from git: {e}")
|
||||
|
||||
return None
|
||||
except FileNotFoundError:
|
||||
print("Warning: Git executable not found.")
|
||||
return None
|
||||
except Exception as e:
|
||||
print(f"Warning: Unexpected error while reading git tags: {e}")
|
||||
return None
|
||||
|
||||
for tag in result.stdout.splitlines():
|
||||
tag = tag.strip()
|
||||
if not tag:
|
||||
continue
|
||||
match = version_regex.match(tag)
|
||||
if match:
|
||||
# Prefer captured group when pattern defines one
|
||||
if match.lastindex:
|
||||
return match.group(1)
|
||||
return tag.lstrip('v')
|
||||
return None
|
||||
|
||||
def build_addon(version_type: str, version: Optional[str] = None, output_dir: Optional[Path] = None, minify: bool = True):
|
||||
@@ -408,4 +433,4 @@ def main():
|
||||
sys.exit(1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user