feat: 增加独立构建工作区、服务端ADB与私有文件清单
支持Git提交导入及未提交源码叠加,APK原名下载和完成通知。新增服务端设备安装与按工程维护的私有文件清单,修复Wrapper预检查、布局及IDE读锁和保存状态问题。更新协议、测试和部署记录;服务端0.7.0,插件0.7.1。
This commit is contained in:
1 parent
87652364bc
commit
6f9cc7e7ea
44 files changed
+2742
-87
No files matched your search
+46
-11
@@ -4,10 +4,13 @@ import base64
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import ssl
|
||||
import time
|
||||
import tempfile
|
||||
from datetime import datetime
|
||||
import urllib.request
|
||||
import urllib.parse
|
||||
import uuid
|
||||
@@ -41,12 +44,16 @@ def main():
|
||||
output.mkdir(exist_ok=True)
|
||||
|
||||
def request(method, path, body=None):
|
||||
data = json.dumps(body).encode() if body is not None else None
|
||||
req = urllib.request.Request(endpoint + '/api/v1' + path, data=data, method=method,
|
||||
headers={'Authorization': 'Bearer ' + token, 'Content-Type': 'application/json'})
|
||||
upload = body.open('rb') if isinstance(body, Path) else None
|
||||
data = upload if upload else (json.dumps(body).encode() if body is not None else None)
|
||||
headers = {'Authorization': 'Bearer ' + token, 'Content-Type': 'application/octet-stream' if upload else 'application/json'}
|
||||
if upload: headers['Content-Length'] = str(body.stat().st_size)
|
||||
req = urllib.request.Request(endpoint + '/api/v1' + path, data=data, method=method, headers=headers)
|
||||
context = ssl.create_default_context(cafile=args.server_cert) if args.server_cert else None
|
||||
with urllib.request.urlopen(req, timeout=300, context=context) as response:
|
||||
result = response.read()
|
||||
try:
|
||||
with urllib.request.urlopen(req, timeout=600, context=context) as response: result = response.read()
|
||||
finally:
|
||||
if upload: upload.close()
|
||||
return result if '/artifacts/' in path else json.loads(result)
|
||||
|
||||
health = request('GET', '/health')
|
||||
@@ -59,16 +66,34 @@ def main():
|
||||
state = json.loads(state_file.read_text()) if state_file.exists() else {}
|
||||
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})
|
||||
dedicated = bool(local_git)
|
||||
if dedicated and not health.get('dedicatedGit'): raise RuntimeError('Upgrade service to 0.5.0 for dedicated Git workspaces')
|
||||
binding = {'workspacePath': args.remote_folder, 'projectId': state.get('project', ''), 'git': local_git, 'dedicated': dedicated}
|
||||
inspection = request('POST', '/projects/check', binding)
|
||||
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']
|
||||
if not state.get('project') or dedicated:
|
||||
state['project'] = request('POST', '/projects', binding)['id']
|
||||
state_file.write_text(json.dumps(state), encoding='utf-8')
|
||||
project = state['project']
|
||||
remote = request('GET', f'/projects/{project}/manifest')['files']
|
||||
remote_state = request('GET', f'/projects/{project}/manifest')
|
||||
previous = (remote_state.get('git') or {}).get('head')
|
||||
if dedicated and previous != local_git['head']:
|
||||
def send_bundle(base):
|
||||
with tempfile.TemporaryDirectory(prefix='remotecompile-bundle-') as directory:
|
||||
bundle = Path(directory) / 'source.bundle'
|
||||
command = ['git', '-C', str(source), 'bundle', 'create', '--version=3', str(bundle), 'HEAD', '--filter=blob:none']
|
||||
if base and subprocess.run(['git', '-C', str(source), 'merge-base', '--is-ancestor', base, local_git['head']], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).returncode == 0: command.append('^' + base)
|
||||
subprocess.run(command, check=True, timeout=300, stdout=subprocess.DEVNULL)
|
||||
if git_snapshot(source)['head'] != local_git['head']: raise RuntimeError('HEAD changed while creating bundle; retry')
|
||||
request('POST', f'/projects/{project}/git?head=' + local_git['head'], bundle)
|
||||
try: send_bundle(previous)
|
||||
except urllib.error.HTTPError as error:
|
||||
if previous and error.code == 400: send_bundle(None)
|
||||
else: raise
|
||||
remote = remote_state['files']
|
||||
manifest = {}
|
||||
changed = 0
|
||||
eol_only = 0
|
||||
@@ -121,8 +146,18 @@ def main():
|
||||
content = request('GET', f'/builds/{build_id}/artifacts/' + urllib.parse.quote(artifact['name']))
|
||||
if hashlib.sha256(content).hexdigest() != artifact['hash']:
|
||||
raise RuntimeError('APK checksum mismatch')
|
||||
destination = output / (build_id + '-' + artifact['hash'] + '.apk')
|
||||
destination.write_bytes(content)
|
||||
filename = artifact.get('fileName') or (artifact.get('sourcePath') or artifact['name']).replace('\\', '/').split('/')[-1]
|
||||
if not artifact.get('fileName') and not artifact.get('sourcePath'):
|
||||
filename = re.sub(r'^\d+-', '', filename)
|
||||
if re.match(r'(?i)^(CON|PRN|AUX|NUL|COM[0-9]|LPT[0-9])(?:\.|$)', filename) or not filename.lower().endswith('.apk') or any(c in filename for c in '/\\:*?"<>|') or any(ord(c)<32 for c in filename): raise RuntimeError('Invalid APK filename')
|
||||
stamp = datetime.now().strftime('%Y%m%d_%H%M%S'); attempt = 0
|
||||
while True:
|
||||
name = filename if attempt == 0 else filename[:-4] + '_' + stamp + ('' if attempt == 1 else '_' + str(attempt)) + '.apk'
|
||||
destination = output / name
|
||||
try:
|
||||
with destination.open('xb') as f: f.write(content)
|
||||
break
|
||||
except FileExistsError: attempt += 1
|
||||
print(f'\nAPK: {destination}')
|
||||
if args.device:
|
||||
subprocess.run([args.adb, '-s', args.device, 'install', '-r', str(destination)], check=True, timeout=120)
|
||||
|
||||
+17
-6
@@ -54,7 +54,7 @@ class SmokeTest(unittest.TestCase):
|
||||
subprocess.run(['git', '-C', str(source), '-c', 'core.autocrlf=false', 'add', '.'], check=True, capture_output=True)
|
||||
subprocess.run(['git', '-C', str(source), '-c', 'user.name=Test', '-c', 'user.email=test@example.invalid', 'commit', '-qm', 'base'], check=True, capture_output=True)
|
||||
subprocess.run(['git', 'clone', '--no-hardlinks', str(source), str(workspace)], check=True, capture_output=True)
|
||||
command = [str(binary), '-workspace-root', str(workspaces), '-listen', f'127.0.0.1:{port}', '-data', str(root / 'data')]
|
||||
command = [str(binary), '-workspace-root', str(workspaces), '-listen', f'127.0.0.1:{port}', '-data', str(root / '服务 数据')]
|
||||
context = None
|
||||
if secure:
|
||||
import ssl
|
||||
@@ -87,7 +87,10 @@ class SmokeTest(unittest.TestCase):
|
||||
self.assertEqual(first.returncode, 0, first.stderr)
|
||||
self.assertEqual(next((source / '.remotecompile').glob('*.apk')).read_bytes(), b'first\r\n')
|
||||
self.assertEqual((workspace / 'input.txt').read_bytes(), b'first\r\n')
|
||||
self.assertRegex(first.stdout, r'skipped [1-9][0-9]* EOL-only files')
|
||||
self.assertIn('专用编译工作区', first.stdout)
|
||||
(source / 'input.txt').write_bytes(b'new committed content\n')
|
||||
subprocess.run(['git','-C',str(source),'add','input.txt'],check=True,capture_output=True)
|
||||
subprocess.run(['git','-C',str(source),'-c','user.name=Test','-c','user.email=test@example.invalid','commit','-qm','next local commit'],check=True,capture_output=True)
|
||||
(source / 'input.txt').write_bytes(b'second\n')
|
||||
(source / 'deleted.txt').unlink()
|
||||
second = subprocess.run(command, env=env, capture_output=True, text=True, timeout=120)
|
||||
@@ -95,11 +98,19 @@ class SmokeTest(unittest.TestCase):
|
||||
self.assertIn('Syncing 1 changed files', second.stdout)
|
||||
artifacts = [p.read_bytes() for p in (source / '.remotecompile').glob('*.apk')]
|
||||
self.assertCountEqual(artifacts, [b'first\r\n', b'second\n'])
|
||||
names = sorted(p.name for p in (source / '.remotecompile').glob('*.apk'))
|
||||
self.assertIn('app-debug.apk', names)
|
||||
self.assertTrue(any(__import__('re').match(r'app-debug_\d{8}_\d{6}(?:_\d+)?\.apk$', name) for name in names))
|
||||
state = json.loads((source / '.remotecompile' / 'client.json').read_text())
|
||||
self.assertFalse((workspace / 'deleted.txt').exists())
|
||||
self.assertFalse((workspace / 'ignored/private.txt').exists())
|
||||
self.assertFalse((workspace / 'app/.cxx/Debug/.ninja_deps').exists())
|
||||
self.assertTrue((workspace / '.git').exists())
|
||||
req = urllib.request.Request(endpoint + '/api/v1/projects/' + state['project'] + '/manifest', headers={'Authorization': 'Bearer ' + env['REMOTE_BUILD_TOKEN']})
|
||||
with urllib.request.urlopen(req, context=context, timeout=20) as response:
|
||||
private = Path(json.load(response)['workspacePath'])
|
||||
self.assertNotEqual(private, workspace)
|
||||
self.assertFalse((private / 'deleted.txt').exists())
|
||||
self.assertTrue((workspace / 'deleted.txt').exists())
|
||||
self.assertFalse((private / 'ignored/private.txt').exists())
|
||||
self.assertFalse((private / 'app/.cxx/Debug/.ninja_deps').exists())
|
||||
self.assertTrue((private / '.git').exists())
|
||||
if chosen_jdk:
|
||||
req = urllib.request.Request(endpoint + '/api/v1/projects/' + state['project'] + '/builds', headers={'Authorization': 'Bearer ' + env['REMOTE_BUILD_TOKEN']})
|
||||
with urllib.request.urlopen(req, context=context, timeout=20) as response:
|
||||
|
||||
Reference in new issue
Block a user