-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrelease_self_healer.py
More file actions
72 lines (61 loc) · 2.47 KB
/
Copy pathrelease_self_healer.py
File metadata and controls
72 lines (61 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python3
"""
Autonomous Release Self-Healer.
Detects and fixes common CI/CD blockers:
1. Version code conflicts
2. Broken preflight regex
3. Missing build artifacts
"""
import re
import sys
import time
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parent.parent
def bump_android_version():
"""Bumps Android versionCode to a unique timestamp to avoid Play Store conflicts."""
gradle_path = REPO_ROOT / "native-android" / "app" / "build.gradle.kts"
if not gradle_path.exists():
return
new_code = int(time.time())
content = gradle_path.read_text()
new_content = re.sub(r'versionCode\s*=\s*\d+', f'versionCode = {new_code}', content)
gradle_path.write_text(new_content)
print(f"✅ Auto-healed Android versionCode to {new_code}")
def bump_ios_build_number():
"""Bumps iOS CURRENT_PROJECT_VERSION."""
project_path = REPO_ROOT / "native-ios" / "RandomTimer.xcodeproj" / "project.pbxproj"
if not project_path.exists():
return
content = project_path.read_text()
# Find current max version
matches = re.findall(r'CURRENT_PROJECT_VERSION = (\d+);', content)
if matches:
current_max = max(int(m) for m in matches)
new_version = current_max + 1
new_content = re.sub(r'CURRENT_PROJECT_VERSION = \d+;', f'CURRENT_PROJECT_VERSION = {new_version};', content)
project_path.write_text(new_content)
print(f"✅ Auto-healed iOS Build Number to {new_version}")
def fix_preflight_regex():
"""Ensures the source_versions script is robust."""
script_path = REPO_ROOT / "scripts" / "source_versions.py"
if not script_path.exists():
return
content = script_path.read_text()
robust_regex = r'ANDROID_VERSION_CODE_RE = re.compile(r"versionCode\s*=\s*(?:[^\n]*?\?:\s*)?(\d+)")'
if 'versionCode\\s*=\\s*(?:[^\\n]*?\\?:\\s*)?(\\d+)' not in content:
# Re-apply the robust regex we discovered today
new_content = re.sub(
r'ANDROID_VERSION_CODE_RE = re.compile\(.*?\)',
robust_regex.replace('\\', '\\\\'), # Escape backslashes for re.sub
content
)
script_path.write_text(new_content)
print("✅ Auto-healed source_versions.py regex")
def main():
print("🛠️ Running Release Self-Healer...")
bump_android_version()
bump_ios_build_number()
fix_preflight_regex()
print("✨ Self-healing complete. System is ready for distribution.")
if __name__ == "__main__":
main()