mirror of
https://git.citron-emu.org/citron/emulator
synced 2026-02-01 15:23:32 +00:00
92 lines
2.9 KiB
Python
92 lines
2.9 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Version management script for Citron
|
|
Generates version information from git and environment variables
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
import subprocess
|
|
import json
|
|
from datetime import datetime
|
|
|
|
def run_git_command(cmd):
|
|
"""Run a git command and return its output"""
|
|
try:
|
|
result = subprocess.run(cmd, shell=True, capture_output=True, text=True, check=True)
|
|
return result.stdout.strip()
|
|
except subprocess.CalledProcessError:
|
|
return None
|
|
|
|
def get_version_info():
|
|
"""Get version information from git and environment"""
|
|
|
|
# Get git information
|
|
git_commit_short = run_git_command("git rev-parse --short HEAD") or "unknown"
|
|
git_commit_full = run_git_command("git rev-parse HEAD") or "unknown"
|
|
git_branch = run_git_command("git branch --show-current") or "unknown"
|
|
git_tag = run_git_command("git describe --tags --exact-match HEAD 2>/dev/null")
|
|
|
|
# Get build information
|
|
build_date = datetime.utcnow().strftime("%Y-%m-%d")
|
|
build_time = datetime.utcnow().strftime("%H:%M:%S")
|
|
build_timestamp = datetime.utcnow().strftime("%Y%m%d%H%M%S")
|
|
|
|
# Determine version based on branch and environment
|
|
ci_branch = os.environ.get('CI_COMMIT_BRANCH', git_branch)
|
|
ci_commit_ref = os.environ.get('CI_COMMIT_REF_NAME', git_branch)
|
|
|
|
if ci_branch in ['main', 'master']:
|
|
base_version = "0.7.0"
|
|
build_suffix = ""
|
|
package_suffix = "stable"
|
|
elif ci_branch == 'develop':
|
|
base_version = "0.7.0-dev"
|
|
build_suffix = "-dev"
|
|
package_suffix = "dev"
|
|
else:
|
|
base_version = "0.7.0-canary"
|
|
build_suffix = "-canary"
|
|
package_suffix = "canary"
|
|
|
|
# Add commit info for non-stable builds
|
|
if package_suffix != "stable":
|
|
version_name = f"{base_version}+{git_commit_short}"
|
|
else:
|
|
version_name = base_version
|
|
|
|
# Check if this is a tagged release
|
|
if git_tag:
|
|
version_name = git_tag
|
|
package_suffix = "stable"
|
|
|
|
return {
|
|
'version_name': version_name,
|
|
'base_version': base_version,
|
|
'build_suffix': build_suffix,
|
|
'package_suffix': package_suffix,
|
|
'git_commit_short': git_commit_short,
|
|
'git_commit_full': git_commit_full,
|
|
'git_branch': git_branch,
|
|
'git_tag': git_tag,
|
|
'build_date': build_date,
|
|
'build_time': build_time,
|
|
'build_timestamp': build_timestamp,
|
|
'package_version': version_name,
|
|
'package_name': f"Citron-{package_suffix.title()}"
|
|
}
|
|
|
|
def main():
|
|
"""Main function"""
|
|
if len(sys.argv) > 1 and sys.argv[1] == '--json':
|
|
# Output as JSON
|
|
print(json.dumps(get_version_info(), indent=2))
|
|
else:
|
|
# Output as environment variables
|
|
info = get_version_info()
|
|
for key, value in info.items():
|
|
print(f"export {key.upper()}='{value}'")
|
|
|
|
if __name__ == '__main__':
|
|
main()
|