commit-updater 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- CommitUpdater/CommitFetcher.py +68 -0
- CommitUpdater/ComponentGitFinder.py +174 -0
- CommitUpdater/LockFileUpdater.py +58 -0
- CommitUpdater/MainProjUpdater.py +79 -0
- CommitUpdater/__init__.py +8 -0
- CommitUpdater/main.py +39 -0
- commit_updater-0.1.0.dist-info/METADATA +128 -0
- commit_updater-0.1.0.dist-info/RECORD +11 -0
- commit_updater-0.1.0.dist-info/WHEEL +5 -0
- commit_updater-0.1.0.dist-info/entry_points.txt +2 -0
- commit_updater-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: UTF-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
@Project :BBScriptToolBundle
|
|
5
|
+
@File :CommitFetcher.py
|
|
6
|
+
@Author :Aron
|
|
7
|
+
@Date :2026/3/13 11:06
|
|
8
|
+
"""
|
|
9
|
+
import os
|
|
10
|
+
import subprocess
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class CommitFetcher:
|
|
14
|
+
|
|
15
|
+
def __init__(self, POD_REPO_ROOT):
|
|
16
|
+
self.POD_REPO_ROOT = POD_REPO_ROOT
|
|
17
|
+
|
|
18
|
+
def get_latest_commit(self, component_name, repo_path):
|
|
19
|
+
"""
|
|
20
|
+
Get the latest commit hash from a git repository.
|
|
21
|
+
|
|
22
|
+
Args:
|
|
23
|
+
component_name (str): Name of the component repository
|
|
24
|
+
|
|
25
|
+
Returns:
|
|
26
|
+
str: Latest commit hash or None if an error occurs
|
|
27
|
+
"""
|
|
28
|
+
try:
|
|
29
|
+
# Check if the directory exists
|
|
30
|
+
if not os.path.isdir(repo_path):
|
|
31
|
+
print(f"[!] Repository for {component_name} not found at {repo_path}")
|
|
32
|
+
return None
|
|
33
|
+
|
|
34
|
+
# Change to the repository directory
|
|
35
|
+
current_path = os.getcwd()
|
|
36
|
+
os.chdir(repo_path)
|
|
37
|
+
|
|
38
|
+
# Make sure we're up to date
|
|
39
|
+
subprocess.run(["git", "fetch"], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
40
|
+
|
|
41
|
+
# Get the latest commit hash
|
|
42
|
+
result = subprocess.run(
|
|
43
|
+
["git", "rev-parse", "HEAD"],
|
|
44
|
+
check=True,
|
|
45
|
+
capture_output=True,
|
|
46
|
+
text=True
|
|
47
|
+
)
|
|
48
|
+
commit_hash = result.stdout.strip()
|
|
49
|
+
|
|
50
|
+
# Return to the original directory
|
|
51
|
+
os.chdir(current_path)
|
|
52
|
+
|
|
53
|
+
print(f"[✓] Found latest commit for {component_name}: {commit_hash}")
|
|
54
|
+
return commit_hash
|
|
55
|
+
|
|
56
|
+
except subprocess.CalledProcessError as e:
|
|
57
|
+
print(f"[!] Git command failed: {e}")
|
|
58
|
+
# Return to the original directory if an error occurred
|
|
59
|
+
if 'current_path' in locals():
|
|
60
|
+
os.chdir(current_path)
|
|
61
|
+
return None
|
|
62
|
+
except Exception as e:
|
|
63
|
+
print(f"[!] Error getting latest commit for {component_name}: {e}")
|
|
64
|
+
# Return to the original directory if an error occurred
|
|
65
|
+
if 'current_path' in locals():
|
|
66
|
+
os.chdir(current_path)
|
|
67
|
+
return None
|
|
68
|
+
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: UTF-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
@Project :BBScriptToolBundle
|
|
5
|
+
@File :ComponentGitFinder.py
|
|
6
|
+
@Author :Aron
|
|
7
|
+
@Date :2026/3/13 11:10
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import os
|
|
11
|
+
import re
|
|
12
|
+
from typing import List, Optional, Tuple
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class ComponentGitFinder:
|
|
16
|
+
|
|
17
|
+
PATHES_START_PATTERN = re.compile(r":pathes\s*=>\s*\[")
|
|
18
|
+
QUOTED_PATH_PATTERN = re.compile(r"""['"]([^'"]+)['"]""")
|
|
19
|
+
|
|
20
|
+
def __init__(self, repo_root: Optional[str] = None, current_proj_dir: Optional[str] = None):
|
|
21
|
+
self.repo_root = repo_root
|
|
22
|
+
self.current_proj_dir = current_proj_dir or os.getcwd()
|
|
23
|
+
|
|
24
|
+
def _get_member_modules_dir(self) -> str:
|
|
25
|
+
return os.path.join(self.current_proj_dir, "cocoapods", "Member_modules")
|
|
26
|
+
|
|
27
|
+
def _parse_repo_roots_from_config(self, file_path: str) -> List[str]:
|
|
28
|
+
try:
|
|
29
|
+
with open(file_path, "r", encoding="utf-8") as f:
|
|
30
|
+
content = f.read()
|
|
31
|
+
except (OSError, UnicodeDecodeError):
|
|
32
|
+
return []
|
|
33
|
+
|
|
34
|
+
pathes_body = self._extract_pathes_body(content)
|
|
35
|
+
if pathes_body is None:
|
|
36
|
+
return []
|
|
37
|
+
|
|
38
|
+
# Remove ruby comments in the array body while preserving quoted strings.
|
|
39
|
+
pathes_body = self._strip_ruby_comments(pathes_body)
|
|
40
|
+
paths = self.QUOTED_PATH_PATTERN.findall(pathes_body)
|
|
41
|
+
normalized_paths = []
|
|
42
|
+
for path in paths:
|
|
43
|
+
normalized_path = os.path.abspath(os.path.expanduser(path.strip()))
|
|
44
|
+
normalized_paths.append(normalized_path)
|
|
45
|
+
return normalized_paths
|
|
46
|
+
|
|
47
|
+
def _extract_pathes_body(self, content: str) -> Optional[str]:
|
|
48
|
+
"""
|
|
49
|
+
Extract text inside :pathes => [ ... ].
|
|
50
|
+
Handles multiline arrays and nested brackets safely.
|
|
51
|
+
"""
|
|
52
|
+
match = self.PATHES_START_PATTERN.search(content)
|
|
53
|
+
if not match:
|
|
54
|
+
return None
|
|
55
|
+
|
|
56
|
+
start_idx = match.end() - 1 # index of '['
|
|
57
|
+
bracket_depth = 0
|
|
58
|
+
in_single_quote = False
|
|
59
|
+
in_double_quote = False
|
|
60
|
+
escape_next = False
|
|
61
|
+
|
|
62
|
+
for idx in range(start_idx, len(content)):
|
|
63
|
+
ch = content[idx]
|
|
64
|
+
|
|
65
|
+
if escape_next:
|
|
66
|
+
escape_next = False
|
|
67
|
+
continue
|
|
68
|
+
|
|
69
|
+
if (in_single_quote or in_double_quote) and ch == "\\":
|
|
70
|
+
escape_next = True
|
|
71
|
+
continue
|
|
72
|
+
|
|
73
|
+
if ch == "'" and not in_double_quote:
|
|
74
|
+
in_single_quote = not in_single_quote
|
|
75
|
+
continue
|
|
76
|
+
|
|
77
|
+
if ch == '"' and not in_single_quote:
|
|
78
|
+
in_double_quote = not in_double_quote
|
|
79
|
+
continue
|
|
80
|
+
|
|
81
|
+
if in_single_quote or in_double_quote:
|
|
82
|
+
continue
|
|
83
|
+
|
|
84
|
+
if ch == "[":
|
|
85
|
+
bracket_depth += 1
|
|
86
|
+
elif ch == "]":
|
|
87
|
+
bracket_depth -= 1
|
|
88
|
+
if bracket_depth == 0:
|
|
89
|
+
return content[start_idx + 1:idx]
|
|
90
|
+
|
|
91
|
+
return None
|
|
92
|
+
|
|
93
|
+
def _strip_ruby_comments(self, text: str) -> str:
|
|
94
|
+
"""
|
|
95
|
+
Strip '#' comments from ruby snippet, ignoring hashes inside quotes.
|
|
96
|
+
"""
|
|
97
|
+
output_chars = []
|
|
98
|
+
in_single_quote = False
|
|
99
|
+
in_double_quote = False
|
|
100
|
+
escape_next = False
|
|
101
|
+
idx = 0
|
|
102
|
+
|
|
103
|
+
while idx < len(text):
|
|
104
|
+
ch = text[idx]
|
|
105
|
+
|
|
106
|
+
if escape_next:
|
|
107
|
+
output_chars.append(ch)
|
|
108
|
+
escape_next = False
|
|
109
|
+
idx += 1
|
|
110
|
+
continue
|
|
111
|
+
|
|
112
|
+
if (in_single_quote or in_double_quote) and ch == "\\":
|
|
113
|
+
output_chars.append(ch)
|
|
114
|
+
escape_next = True
|
|
115
|
+
idx += 1
|
|
116
|
+
continue
|
|
117
|
+
|
|
118
|
+
if ch == "'" and not in_double_quote:
|
|
119
|
+
in_single_quote = not in_single_quote
|
|
120
|
+
output_chars.append(ch)
|
|
121
|
+
idx += 1
|
|
122
|
+
continue
|
|
123
|
+
|
|
124
|
+
if ch == '"' and not in_single_quote:
|
|
125
|
+
in_double_quote = not in_double_quote
|
|
126
|
+
output_chars.append(ch)
|
|
127
|
+
idx += 1
|
|
128
|
+
continue
|
|
129
|
+
|
|
130
|
+
if ch == "#" and not in_single_quote and not in_double_quote:
|
|
131
|
+
# Skip comment content until newline.
|
|
132
|
+
while idx < len(text) and text[idx] != "\n":
|
|
133
|
+
idx += 1
|
|
134
|
+
continue
|
|
135
|
+
|
|
136
|
+
output_chars.append(ch)
|
|
137
|
+
idx += 1
|
|
138
|
+
|
|
139
|
+
return "".join(output_chars)
|
|
140
|
+
|
|
141
|
+
def _iter_repo_roots_from_member_configs(self) -> List[Tuple[str, str]]:
|
|
142
|
+
"""
|
|
143
|
+
Return a list of tuples: (developer_config_filename, repo_root_path)
|
|
144
|
+
"""
|
|
145
|
+
member_modules_dir = self._get_member_modules_dir()
|
|
146
|
+
if not os.path.isdir(member_modules_dir):
|
|
147
|
+
return []
|
|
148
|
+
|
|
149
|
+
roots = []
|
|
150
|
+
for file_name in sorted(os.listdir(member_modules_dir)):
|
|
151
|
+
if not file_name.endswith(".rb"):
|
|
152
|
+
continue
|
|
153
|
+
file_path = os.path.join(member_modules_dir, file_name)
|
|
154
|
+
for repo_root in self._parse_repo_roots_from_config(file_path):
|
|
155
|
+
roots.append((file_name, repo_root))
|
|
156
|
+
return roots
|
|
157
|
+
|
|
158
|
+
def find_git_root(self, component_name):
|
|
159
|
+
# 1) 兼容旧逻辑:指定了repo_root时直接拼接
|
|
160
|
+
if self.repo_root:
|
|
161
|
+
return os.path.join(self.repo_root, component_name)
|
|
162
|
+
|
|
163
|
+
# 2) 自动遍历所有开发者配置,找到实际存在的组件仓库路径
|
|
164
|
+
for config_name, repo_root in self._iter_repo_roots_from_member_configs():
|
|
165
|
+
candidate_path = os.path.join(repo_root, component_name)
|
|
166
|
+
if os.path.isdir(candidate_path):
|
|
167
|
+
print(
|
|
168
|
+
f"[✓] Found component '{component_name}' by config '{config_name}' -> {candidate_path}"
|
|
169
|
+
)
|
|
170
|
+
return candidate_path
|
|
171
|
+
|
|
172
|
+
# 3) 未找到则返回None,让调用方决定兜底策略
|
|
173
|
+
print(f"[!] Cannot find local git root for component '{component_name}'")
|
|
174
|
+
return None
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: UTF-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
@Project :BBScriptToolBundle
|
|
5
|
+
@File :LockFileUpdater.py
|
|
6
|
+
@Author :Aron
|
|
7
|
+
@Date :2026/3/13 10:57
|
|
8
|
+
"""
|
|
9
|
+
import re
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class LockFileUpdater:
|
|
13
|
+
|
|
14
|
+
def __init__(self, lock_file_path):
|
|
15
|
+
self.lock_file_path = lock_file_path
|
|
16
|
+
|
|
17
|
+
def update_commit(self, component_name, new_commit):
|
|
18
|
+
with open(self.lock_file_path, "r") as file:
|
|
19
|
+
lines = file.readlines()
|
|
20
|
+
|
|
21
|
+
updated_lines = []
|
|
22
|
+
pattern = rf"^\s+{re.escape(component_name)}:\n(\s+:git: .+\n)?\s+:commit: .+\n"
|
|
23
|
+
regex = re.compile(pattern, re.MULTILINE)
|
|
24
|
+
|
|
25
|
+
found = False
|
|
26
|
+
i = 0
|
|
27
|
+
while i < len(lines):
|
|
28
|
+
if lines[i].strip() == f"{component_name}:":
|
|
29
|
+
found = True
|
|
30
|
+
updated_lines.append(lines[i])
|
|
31
|
+
i += 1
|
|
32
|
+
# 可选的 :git: 行
|
|
33
|
+
if lines[i].strip().startswith(":git:"):
|
|
34
|
+
updated_lines.append(lines[i])
|
|
35
|
+
i += 1
|
|
36
|
+
# Skip if :branch: line exists
|
|
37
|
+
if lines[i].strip().startswith(":branch:"):
|
|
38
|
+
updated_lines.append(lines[i])
|
|
39
|
+
i += 1
|
|
40
|
+
print(f"[!] Skipping update for {component_name} as it uses a branch.")
|
|
41
|
+
continue
|
|
42
|
+
# 替换 :commit: 行
|
|
43
|
+
updated_lines.append(f" :commit: {new_commit}\n")
|
|
44
|
+
i += 1
|
|
45
|
+
else:
|
|
46
|
+
updated_lines.append(lines[i])
|
|
47
|
+
i += 1
|
|
48
|
+
|
|
49
|
+
if not found:
|
|
50
|
+
print(f"[!] Component '{component_name}' not found in Podfile.lock")
|
|
51
|
+
return False
|
|
52
|
+
|
|
53
|
+
with open(self.lock_file_path, "w") as file:
|
|
54
|
+
file.writelines(updated_lines)
|
|
55
|
+
|
|
56
|
+
print(f"[✓] Updated {component_name} commit to {new_commit} in Podfile.lock")
|
|
57
|
+
return True
|
|
58
|
+
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: UTF-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
@Project :BBScriptToolBundle
|
|
5
|
+
@File :MainProjUpdater.py
|
|
6
|
+
@Author :Aron
|
|
7
|
+
@Date :2026/3/13 11:02
|
|
8
|
+
"""
|
|
9
|
+
import os
|
|
10
|
+
import subprocess
|
|
11
|
+
|
|
12
|
+
from CommitUpdater.CommitFetcher import CommitFetcher
|
|
13
|
+
from CommitUpdater.ComponentGitFinder import ComponentGitFinder
|
|
14
|
+
from CommitUpdater.LockFileUpdater import LockFileUpdater
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class MainProjUpdater:
|
|
18
|
+
|
|
19
|
+
def __init__(self, current_proj_dir):
|
|
20
|
+
self.current_proj_dir = current_proj_dir
|
|
21
|
+
self.PODFILE_LOCK_PATH = os.path.join(current_proj_dir, "Podfile.lock")
|
|
22
|
+
|
|
23
|
+
# 拉取主工程的最新代码
|
|
24
|
+
def _pull_main_proj(self):
|
|
25
|
+
os.chdir(self.current_proj_dir)
|
|
26
|
+
subprocess.run(["git", "pull"], check=True)
|
|
27
|
+
print(f"[✓] Pulled latest changes for main project at {self.current_proj_dir}")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _git_commit_and_push(self, component_names):
|
|
31
|
+
os.chdir(self.current_proj_dir)
|
|
32
|
+
subprocess.run(["git", "add", "Podfile.lock"], check=True)
|
|
33
|
+
|
|
34
|
+
if len(component_names) == 1:
|
|
35
|
+
commit_message = f"[update] {component_names[0]}"
|
|
36
|
+
else:
|
|
37
|
+
components_str = ", ".join(component_names)
|
|
38
|
+
commit_message = f"[update] Multiple components: {components_str}"
|
|
39
|
+
|
|
40
|
+
subprocess.run(["git", "commit", "-m", commit_message], check=True)
|
|
41
|
+
subprocess.run(["git", "push"], check=True)
|
|
42
|
+
print(f"[✓] Git commit and push complete for {', '.join(component_names)}")
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def update_components(self, components):
|
|
46
|
+
# Pull the latest changes for the main project
|
|
47
|
+
self._pull_main_proj()
|
|
48
|
+
|
|
49
|
+
# Track successfully updated components
|
|
50
|
+
updated_components = []
|
|
51
|
+
|
|
52
|
+
# Update each component
|
|
53
|
+
for component in components:
|
|
54
|
+
print(f"\n[*] Processing component: {component}")
|
|
55
|
+
|
|
56
|
+
# Find the git repository for the component
|
|
57
|
+
gitFinder = ComponentGitFinder(current_proj_dir=self.current_proj_dir) # Initialize to ensure any setup is done
|
|
58
|
+
repo_path = gitFinder.find_git_root(component) # Call to ensure any internal state is set if needed
|
|
59
|
+
|
|
60
|
+
# Get the latest commit hash for the component
|
|
61
|
+
commitFetcher = CommitFetcher(self.current_proj_dir)
|
|
62
|
+
commit_val = commitFetcher.get_latest_commit(component, repo_path)
|
|
63
|
+
|
|
64
|
+
if commit_val:
|
|
65
|
+
# Update the commit in Podfile.lock
|
|
66
|
+
lockFileUpdater = LockFileUpdater(self.PODFILE_LOCK_PATH)
|
|
67
|
+
if lockFileUpdater.update_commit(component, commit_val):
|
|
68
|
+
updated_components.append(component)
|
|
69
|
+
else:
|
|
70
|
+
print(f"[!] Failed to get latest commit for {component}, skipping")
|
|
71
|
+
|
|
72
|
+
# Push changes if any components were updated
|
|
73
|
+
if updated_components:
|
|
74
|
+
self._git_commit_and_push(updated_components)
|
|
75
|
+
return True
|
|
76
|
+
else:
|
|
77
|
+
print("[!] No components were updated successfully")
|
|
78
|
+
return False
|
|
79
|
+
|
CommitUpdater/main.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: UTF-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
@Project :BBScriptToolBundle
|
|
5
|
+
@File :CommitUpdater.py
|
|
6
|
+
@Author :Aron
|
|
7
|
+
@Date :2025/4/17 10:50
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import os
|
|
11
|
+
import re
|
|
12
|
+
import subprocess
|
|
13
|
+
import argparse
|
|
14
|
+
|
|
15
|
+
from CommitUpdater.MainProjUpdater import MainProjUpdater
|
|
16
|
+
|
|
17
|
+
# POD_REPO_ROOT = "/Users/aron/MyWorkSpaces/CodeRepos/"
|
|
18
|
+
current_proj_dir = os.getcwd()
|
|
19
|
+
# current_proj_dir = "/Users/aron/MyWorkSpaces/CodeRepos/bbframework_iOS_New_3D/proj.ios"
|
|
20
|
+
PODFILE_LOCK_PATH = os.path.join(current_proj_dir, "Podfile.lock")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def main():
|
|
24
|
+
parser = argparse.ArgumentParser(description="Update component commit(s) in Podfile.lock and push to Git")
|
|
25
|
+
parser.add_argument("components", nargs="+", help="Component name(s) (e.g., BBUnlock BBEngine)")
|
|
26
|
+
args = parser.parse_args()
|
|
27
|
+
|
|
28
|
+
MainProjUpdater(current_proj_dir).update_components(args.components)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
if __name__ == "__main__":
|
|
32
|
+
isTest = False
|
|
33
|
+
if isTest:
|
|
34
|
+
# For testing purposes, you can hardcode component names here
|
|
35
|
+
current_proj_dir = "/Volumes/Realtek/MyWorkSpaces/CodeRepos/Baby_Recommend2"
|
|
36
|
+
test_components = ["BBVocabMemoTool"]
|
|
37
|
+
MainProjUpdater(current_proj_dir).update_components(test_components)
|
|
38
|
+
else:
|
|
39
|
+
main()
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: commit-updater
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Update Podfile.lock component commits from local git repos and push
|
|
5
|
+
Author: Aron
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: cocoapods,podfile,git,lockfile
|
|
8
|
+
Classifier: Development Status :: 4 - Beta
|
|
9
|
+
Classifier: Environment :: Console
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Topic :: Software Development :: Version Control
|
|
18
|
+
Requires-Python: >=3.8
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
|
|
21
|
+
# CommitUpdater
|
|
22
|
+
|
|
23
|
+
用于在主工程中批量更新 `Podfile.lock` 里的组件 commit,并自动提交推送主工程仓库。
|
|
24
|
+
|
|
25
|
+
## 功能概述
|
|
26
|
+
|
|
27
|
+
- 拉取主工程最新代码(`git pull`)
|
|
28
|
+
- 根据组件名定位本地组件仓库路径
|
|
29
|
+
- 获取组件仓库最新 commit(`git fetch` + `git rev-parse HEAD`)
|
|
30
|
+
- 更新主工程 `Podfile.lock` 对应组件的 `:commit:`
|
|
31
|
+
- 自动执行 `git add Podfile.lock`、`git commit`、`git push`
|
|
32
|
+
|
|
33
|
+
## 目录说明
|
|
34
|
+
|
|
35
|
+
- `main.py`:入口脚本(命令行参数解析)
|
|
36
|
+
- `MainProjUpdater.py`:主流程编排(pull、更新、提交推送)
|
|
37
|
+
- `ComponentGitFinder.py`:组件本地仓库路径查找
|
|
38
|
+
- `CommitFetcher.py`:获取组件仓库最新 commit
|
|
39
|
+
- `LockFileUpdater.py`:更新 `Podfile.lock` 里的 commit
|
|
40
|
+
|
|
41
|
+
## 组件路径查找规则
|
|
42
|
+
|
|
43
|
+
`ComponentGitFinder` 会优先按以下方式定位组件目录:
|
|
44
|
+
|
|
45
|
+
1. 如果初始化时传入 `repo_root`,直接拼接 `repo_root/component_name`
|
|
46
|
+
2. 否则自动读取主工程下的开发者配置目录:
|
|
47
|
+
- `cocoapods/Member_modules/*.rb`
|
|
48
|
+
- 从各配置文件的 `:pathes => [...]` 解析本地仓库根目录
|
|
49
|
+
- 依次检查 `<repo_root>/<component_name>` 是否存在
|
|
50
|
+
- 找到即返回对应路径
|
|
51
|
+
|
|
52
|
+
已适配以下 `:pathes` 写法:
|
|
53
|
+
- 多行数组
|
|
54
|
+
- 行内或独立行注释(`# ...`)
|
|
55
|
+
- 单引号/双引号路径
|
|
56
|
+
|
|
57
|
+
## 安装与使用
|
|
58
|
+
|
|
59
|
+
### 方式一:pip 安装(推荐,独立包)
|
|
60
|
+
|
|
61
|
+
`pyproject.toml` 位于 `CommitUpdater` 目录,可将该目录作为独立包根目录安装,并得到全局命令 `commit-updater`:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
# 在 CommitUpdater 目录
|
|
65
|
+
cd CommitUpdater
|
|
66
|
+
pip install -e .
|
|
67
|
+
|
|
68
|
+
# 之后可在任意目录执行(需先 cd 到含 Podfile.lock 的主工程目录)
|
|
69
|
+
commit-updater BBUnlock BBEngine
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
发布到 PyPI 后,他人可直接:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
pip install commit-updater
|
|
76
|
+
commit-updater BBUnlock BBEngine
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### 方式二:不安装,在仓库根目录运行
|
|
80
|
+
|
|
81
|
+
在仓库根目录(`BBScriptToolBundle`)执行:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
python3 -m CommitUpdater.main BBUnlock BBEngine
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
或直接运行脚本:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
python3 CommitUpdater/main.py BBUnlock BBEngine
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## PyCharm 运行注意事项
|
|
94
|
+
|
|
95
|
+
若使用 PyCharm 直接运行脚本,且 `Working directory` 设置不正确,可能出现:
|
|
96
|
+
|
|
97
|
+
- `No module named 'CommitUpdater.MainProjUpdater'`
|
|
98
|
+
- `'CommitUpdater' is not a package`
|
|
99
|
+
|
|
100
|
+
推荐方案:
|
|
101
|
+
|
|
102
|
+
- 在 PyCharm 里使用 **Module name** 运行:`CommitUpdater.main`
|
|
103
|
+
- Working directory 设为项目根目录:`BBScriptToolBundle`
|
|
104
|
+
|
|
105
|
+
## 提交信息规则
|
|
106
|
+
|
|
107
|
+
- 单组件更新:`[update] <component>`
|
|
108
|
+
- 多组件更新:`[update] Multiple components: <comp1>, <comp2>, ...`
|
|
109
|
+
|
|
110
|
+
## 发布(维护者)
|
|
111
|
+
|
|
112
|
+
打包与上传 PyPI(需先安装 `build`、`twine`):
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
# 在 CommitUpdater 目录
|
|
116
|
+
cd CommitUpdater
|
|
117
|
+
python3 -m build
|
|
118
|
+
twine upload dist/*
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
若使用私有 PyPI,将 `twine upload` 目标改为对应 index。单独发布 CommitUpdater 时,直接复制整个 `CommitUpdater` 目录到新仓库根目录即可,在该目录执行上述命令即可。
|
|
122
|
+
|
|
123
|
+
## 注意事项
|
|
124
|
+
|
|
125
|
+
- `MainProjUpdater` 会自动执行提交和推送,请确保主工程分支、权限和远程状态正确
|
|
126
|
+
- `LockFileUpdater` 遇到 `:branch:` 配置会跳过该组件更新
|
|
127
|
+
- 运行前请确保主工程目录下存在 `Podfile.lock`
|
|
128
|
+
- 当前 `main.py` 中有 `isTest` 测试入口,正式使用命令行时请保持 `isTest = False`
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
CommitUpdater/CommitFetcher.py,sha256=oJZhFxcaVosSxSCX_lHcI9a5mWPNK4HsJ2kglIp59dE,2125
|
|
2
|
+
CommitUpdater/ComponentGitFinder.py,sha256=b-QxPHSMzgWeBmlqCd2qNZ3OslZaLISC-EQzVhL8lbw,5814
|
|
3
|
+
CommitUpdater/LockFileUpdater.py,sha256=cEtLp1toHYaQDcJVT-A7LGb5HHBg88WG2fjUW0h6Htg,1855
|
|
4
|
+
CommitUpdater/MainProjUpdater.py,sha256=wv5Kq8YebhG0PCUiTMer_xuf6nSnJdOVU67wxTFoSEY,2947
|
|
5
|
+
CommitUpdater/__init__.py,sha256=OOblVCPHIASPm_H-MeFYcvgd-VPzW4OVO2a32ItxYbU,159
|
|
6
|
+
CommitUpdater/main.py,sha256=TLhmMZwzvAuQ1BxauNuqA2VE29_MPWdQrwRlut45gW4,1214
|
|
7
|
+
commit_updater-0.1.0.dist-info/METADATA,sha256=bW8l9j17tUs_y2yIF6O1ZAf_hmasObkCHUc88PouJ9g,4121
|
|
8
|
+
commit_updater-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
9
|
+
commit_updater-0.1.0.dist-info/entry_points.txt,sha256=IViDxIBpRI7bnKsuKQVvzk0CIu7NnPokFN-AoG-dbzE,59
|
|
10
|
+
commit_updater-0.1.0.dist-info/top_level.txt,sha256=3OWw6sEFGEL5zZoY9ir6RFucAVDpY8iiZuyekZu8HIc,14
|
|
11
|
+
commit_updater-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
CommitUpdater
|