feat: 完善远程构建恢复、工程同步与变体选择

增加持久化构建记录、历史 APK 恢复、断点下载、Gradle 缓存复用、系统代理与按工程选择服务端 JDK。

支持已有工程目录、Git 状态检查、原生忽略规则和文本换行等价比较,修复干净检出与历史同步快照不一致时的误拦截。

优化插件设备可选构建、侧栏滚动、左右日志布局、时间显示和构建变体快速选择,并补充部署与协议文档。

验证:17 项 Go 测试、22 项插件测试及 HTTP/HTTPS 两条端到端测试通过;Linux/macOS 服务端交叉编译通过。
This commit is contained in:
tongtong committed 2026-11-25 02:10:52 +08:00
1 parent 2203afde3c
commit 2cb70beb69
44 files changed
+3310 -236

No files matched your search

+41 -27
View File
@@ -11,13 +11,16 @@ import time
import urllib.request
import urllib.parse
import uuid
from source_files import git_snapshot, collect, text_hash
EXCLUDE = {'.git', '.gradle', '.idea', '.remotecompile', '.kotlin', 'build', 'node_modules', '__pycache__'}
def main():
parser = argparse.ArgumentParser(description='Sync, remote build, download and optionally install an APK')
parser.add_argument('source', type=Path)
parser.add_argument('--url', default='http://127.0.0.1:8765')
parser.add_argument('--remote-folder', required=True, help='Existing absolute project folder on the server')
parser.add_argument('--java-home', default='', help='JDK home selected from server /jdks; blank inherits service default')
parser.add_argument('--exact-line-endings', action='store_true', help='Upload CRLF/LF-only changes too')
parser.add_argument('--task', default=':app:assembleDebug')
parser.add_argument('--adb', default='adb')
parser.add_argument('--server-cert', help='Trusted server public PEM certificate for LAN HTTPS')
@@ -45,42 +48,53 @@ def main():
result = response.read()
return result if '/artifacts/' in path else json.loads(result)
request('GET', '/health')
health = request('GET', '/health')
if not health.get('workspaceSelection'):
raise RuntimeError('Upgrade service to 0.3.0 for workspace selection')
if not health.get('textComparison') or not health.get('jdkSelection'):
raise RuntimeError('Upgrade service to 0.4.0 for EOL comparison and JDK selection')
local_git = git_snapshot(source)
state_file = output / 'client.json'
state = json.loads(state_file.read_text()) if state_file.exists() else {}
if state.get('url') != endpoint:
state = {'url': endpoint, 'project': request('POST', '/projects')['id']}
if state.get('url') != endpoint or state.get('remoteFolder') != args.remote_folder:
state = {'url': endpoint, 'remoteFolder': args.remote_folder}
inspection = request('POST', '/projects/check', {'workspacePath': args.remote_folder, 'projectId': state.get('project', ''), 'git': local_git})
print('Git check: '+inspection['message'], flush=True)
if not inspection['canSync']:
raise RuntimeError(inspection['message'])
paths = collect(source, local_git)
if not state.get('project'):
state['project'] = request('POST', '/projects', {'workspacePath': args.remote_folder, 'git': local_git})['id']
state_file.write_text(json.dumps(state), encoding='utf-8')
project = state['project']
remote = request('GET', f'/projects/{project}/manifest')['files']
manifest = {}
changed = 0
for directory, dirs, names in os.walk(source, followlinks=False):
for name in list(dirs):
if name in EXCLUDE:
dirs.remove(name)
elif (Path(directory) / name).is_symlink():
raise RuntimeError('Symbolic links are unsupported')
for name in names:
if name == 'local.properties' or name.startswith('.env') or name.endswith(('.jks', '.keystore')) or name in ('key.properties', 'keystore.properties'):
continue
path = Path(directory) / name
if path.is_symlink():
raise RuntimeError(f'Symbolic link: {path}')
if path.stat().st_size > 64 * 1024 * 1024:
raise RuntimeError(f'File exceeds 64 MiB: {path}')
content = path.read_bytes()
sha = hashlib.sha256(content).hexdigest()
relative = path.relative_to(source).as_posix()
entry = {'hash': sha}
if remote.get(relative, {}).get('hash') != sha:
eol_only = 0
for path in paths:
if path.stat().st_size > 64 * 1024 * 1024:
raise RuntimeError(f'File exceeds 64 MiB: {path}')
content = path.read_bytes()
sha = hashlib.sha256(content).hexdigest()
relative = path.relative_to(source).as_posix()
entry = {'hash': sha}
previous = remote.get(relative, {})
if previous.get('hash') != sha:
normalized = text_hash(relative, content) if not args.exact_line_endings else None
if normalized is not None and normalized == previous.get('textHash'):
entry = {'hash': previous['hash']}
eol_only += 1
else:
entry['data'] = base64.b64encode(content).decode()
changed += 1
manifest[relative] = entry
manifest[relative] = entry
latest_git = git_snapshot(source)
if (latest_git or {}).get('head') != (local_git or {}).get('head') or (latest_git or {}).get('branch') != (local_git or {}).get('branch'):
raise RuntimeError('Git state changed during scan; retry')
revision = str(uuid.uuid4())
print(f'Syncing {changed} changed files ({len(manifest)} total)', flush=True)
request('POST', f'/projects/{project}/sync', {'revision': revision, 'files': manifest})
build = request('POST', f'/projects/{project}/builds', {'revision': revision, 'task': args.task})
print(f'Syncing {changed} changed files ({len(manifest)} total), skipped {eol_only} EOL-only files', flush=True)
request('POST', f'/projects/{project}/sync', {'revision': revision, 'files': manifest, 'git': local_git})
build = request('POST', f'/projects/{project}/builds', {'revision': revision, 'task': args.task, 'javaHome': args.java_home})
build_id = build['id']
offset = 0
try: