check_version_consistency.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/usr/bin/env python3
  2. import os
  3. import re
  4. import sys
  5. from typing import Set, Tuple
  6. def find_version_references(directory: str) -> Tuple[Set[str], Set[str]]:
  7. openhands_versions = set()
  8. runtime_versions = set()
  9. version_pattern_openhands = re.compile(r'openhands:(\d{1})\.(\d{2})')
  10. version_pattern_runtime = re.compile(r'runtime:(\d{1})\.(\d{2})')
  11. for root, _, files in os.walk(directory):
  12. # Skip .git directory
  13. if '.git' in root:
  14. continue
  15. for file in files:
  16. if file.endswith(
  17. ('.md', '.yml', '.yaml', '.txt', '.html', '.py', '.js', '.ts')
  18. ):
  19. file_path = os.path.join(root, file)
  20. try:
  21. with open(file_path, 'r', encoding='utf-8') as f:
  22. content = f.read()
  23. # Find all openhands version references
  24. matches = version_pattern_openhands.findall(content)
  25. openhands_versions.update(matches)
  26. # Find all runtime version references
  27. matches = version_pattern_runtime.findall(content)
  28. runtime_versions.update(matches)
  29. except Exception as e:
  30. print(f'Error reading {file_path}: {e}', file=sys.stderr)
  31. return openhands_versions, runtime_versions
  32. def main():
  33. repo_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
  34. openhands_versions, runtime_versions = find_version_references(repo_root)
  35. exit_code = 0
  36. if len(openhands_versions) > 1:
  37. print('Error: Multiple openhands versions found:', file=sys.stderr)
  38. print('Found versions:', sorted(openhands_versions), file=sys.stderr)
  39. exit_code = 1
  40. elif len(openhands_versions) == 0:
  41. print('Warning: No openhands version references found', file=sys.stderr)
  42. if len(runtime_versions) > 1:
  43. print('Error: Multiple runtime versions found:', file=sys.stderr)
  44. print('Found versions:', sorted(runtime_versions), file=sys.stderr)
  45. exit_code = 1
  46. elif len(runtime_versions) == 0:
  47. print('Warning: No runtime version references found', file=sys.stderr)
  48. sys.exit(exit_code)
  49. if __name__ == '__main__':
  50. main()