@supersdk/supercli 0.3.2-staging.44 → 0.3.2
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.
- package/dist/cli.js +11 -22
- package/dist/cli.js.map +1 -1
- package/dist/commands/add.js +31 -79
- package/dist/commands/add.js.map +1 -1
- package/dist/commands/analytics.js +9 -15
- package/dist/commands/analytics.js.map +1 -1
- package/dist/commands/db.js +19 -24
- package/dist/commands/db.js.map +1 -1
- package/dist/commands/deploy.js +751 -434
- package/dist/commands/deploy.js.map +1 -1
- package/dist/commands/env.js +8 -8
- package/dist/commands/env.js.map +1 -1
- package/dist/commands/image.js +20 -31
- package/dist/commands/image.js.map +1 -1
- package/dist/commands/init.js +37 -68
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/logs.js +7 -16
- package/dist/commands/logs.js.map +1 -1
- package/dist/commands/publishSite.js +943 -28
- package/dist/commands/publishSite.js.map +1 -1
- package/dist/commands/register.js +30 -51
- package/dist/commands/register.js.map +1 -1
- package/dist/commands/settings.js +6 -10
- package/dist/commands/settings.js.map +1 -1
- package/dist/config/appConfig.js +36 -40
- package/dist/config/appConfig.js.map +1 -1
- package/dist/docker/dockerCli.js +1 -63
- package/dist/docker/dockerCli.js.map +1 -1
- package/dist/output/envelope.js +1 -5
- package/dist/output/envelope.js.map +1 -1
- package/dist/output/resultPrinter.js +0 -3
- package/dist/output/resultPrinter.js.map +1 -1
- package/dist/publish/responseClassifier.js +4 -4
- package/dist/publish/responseClassifier.js.map +1 -1
- package/dist/publish/runClient.js +11 -11
- package/dist/publish/runClient.js.map +1 -1
- package/dist/publish/siteConfig.js +649 -0
- package/dist/publish/siteConfig.js.map +1 -0
- package/dist/publish/siteZip.js +5 -4
- package/dist/publish/siteZip.js.map +1 -1
- package/dist/template/README.md +227 -64
- package/dist/template/android/app/src/main/java/com/supersdk/simple/EnvironmentStore.java +1 -1
- package/dist/template/android/app/src/main/java/com/supersdk/simple/SimpleApplication.java +2 -2
- package/dist/template/android/gradle/supersdk-config-reader.gradle +5 -6
- package/dist/template/android/supersdk-default.config.json +2 -3
- package/dist/template/ios/Sources/App/AppDelegate.swift +1 -1
- package/dist/template/ios/Sources/App/SimpleSDKBootstrap.swift +1 -1
- package/dist/template/scripts/build_android.sh +10 -26
- package/dist/template/scripts/build_ios.sh +9 -41
- package/dist/template/scripts/build_site.sh +26 -40
- package/dist/template/scripts/lib/workspace.sh +4 -4
- package/dist/template/scripts/serve_web.py +4 -2
- package/dist/template/scripts/super_build_orchestrator.py +355 -278
- package/dist/template/scripts/supersdk_template.py +181 -414
- package/dist/template/scripts/web_package.py +8 -9
- package/dist/template/super_build.sh +113 -39
- package/dist/template/{super.json → supersdk.json} +1 -20
- package/dist/template/template_manifest.json +4 -5
- package/dist/workspace/config.js +119 -81
- package/dist/workspace/config.js.map +1 -1
- package/dist/workspace/identity.js +14 -15
- package/dist/workspace/identity.js.map +1 -1
- package/dist/workspace/inspect.js +0 -1
- package/dist/workspace/inspect.js.map +1 -1
- package/dist/workspace/projectIdentity.js +96 -53
- package/dist/workspace/projectIdentity.js.map +1 -1
- package/dist/workspace/template.js +8 -5
- package/dist/workspace/template.js.map +1 -1
- package/package.json +2 -2
- package/dist/build/artifactIntegrity.js +0 -119
- package/dist/build/artifactIntegrity.js.map +0 -1
- package/dist/commands/build.js +0 -231
- package/dist/commands/build.js.map +0 -1
- package/dist/commands/config.js +0 -170
- package/dist/commands/config.js.map +0 -1
- package/dist/config/superConfig.js +0 -429
- package/dist/config/superConfig.js.map +0 -1
- package/dist/deploy/adapterTypes.js +0 -3
- package/dist/deploy/adapterTypes.js.map +0 -1
- package/dist/deploy/manifest.js +0 -381
- package/dist/deploy/manifest.js.map +0 -1
- package/dist/deploy/preflight.js +0 -202
- package/dist/deploy/preflight.js.map +0 -1
- package/dist/deploy/resultWriter.js +0 -178
- package/dist/deploy/resultWriter.js.map +0 -1
- package/dist/deploy/runAdapter.js +0 -299
- package/dist/deploy/runAdapter.js.map +0 -1
- package/dist/deploy/siteAdapter.js +0 -182
- package/dist/deploy/siteAdapter.js.map +0 -1
- package/dist/template/scripts/build_service.sh +0 -89
- package/dist/template/service/Dockerfile +0 -2
- package/dist/workspace/projectContext.js +0 -93
- package/dist/workspace/projectContext.js.map +0 -1
|
@@ -1,343 +1,420 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
|
-
"""Fixed-adapter workspace builder and portable manifest authority."""
|
|
3
|
-
|
|
4
2
|
import argparse
|
|
5
|
-
import hashlib
|
|
6
3
|
import json
|
|
7
4
|
import math
|
|
8
5
|
import os
|
|
9
6
|
import signal
|
|
10
|
-
import stat
|
|
11
7
|
import subprocess
|
|
12
8
|
import sys
|
|
13
9
|
import threading
|
|
14
|
-
import
|
|
15
|
-
from datetime import datetime, timezone
|
|
10
|
+
from dataclasses import dataclass
|
|
16
11
|
from pathlib import Path
|
|
17
12
|
|
|
18
13
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
19
14
|
import supersdk_template
|
|
20
15
|
|
|
21
16
|
|
|
17
|
+
PROJECT_TYPES = supersdk_template.PROJECT_TYPES
|
|
18
|
+
# 🔴 站点没有 skip 模式:它是 success 或 failed。这条常量必须跟着类型改名走 ——
|
|
19
|
+
# 留着旧的 "web" 会让每个 site 构建都被 SKIP 扫描,任何以 SKIP_ 开头的日志行都会
|
|
20
|
+
# 把它判成 skipped,而退出码仍然是 0(静默的状态漂移,比直接失败危险得多)。
|
|
21
|
+
NO_SKIP_MODE_TYPES = ("site",)
|
|
22
22
|
SUMMARY_PREFIX = "SUPERSDK_BUILD_SUMMARY_JSON="
|
|
23
|
-
|
|
24
|
-
MANIFEST_SCHEMA_VERSION = 1
|
|
23
|
+
SUMMARY_SCHEMA_VERSION = 2
|
|
25
24
|
DEFAULT_TIMEOUT_SECONDS = 1800.0
|
|
26
25
|
REASON_LIMIT = 500
|
|
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
|
-
def
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
26
|
+
TRUNCATION_MARKER = "...(truncated)"
|
|
27
|
+
OUTPUT_HEAD_LINES = 100
|
|
28
|
+
OUTPUT_TAIL_LINES = 100
|
|
29
|
+
OUTPUT_LOCK = threading.Lock()
|
|
30
|
+
FORWARDED_LINE_SEPARATOR_TRANSLATION = {
|
|
31
|
+
ord("\r"): "\\r",
|
|
32
|
+
ord("\f"): "\\f",
|
|
33
|
+
ord("\v"): "\\v",
|
|
34
|
+
0x1C: "\\x1c",
|
|
35
|
+
0x1D: "\\x1d",
|
|
36
|
+
0x1E: "\\x1e",
|
|
37
|
+
0x85: "\\x85",
|
|
38
|
+
0x2028: "\\u2028",
|
|
39
|
+
0x2029: "\\u2029",
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
@dataclass
|
|
44
|
+
class HelperOutput:
|
|
45
|
+
stdout_lines: list[str]
|
|
46
|
+
stderr_lines: list[str]
|
|
47
|
+
stdout_skip_line: str | None = None
|
|
48
|
+
stderr_skip_line: str | None = None
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class BoundedLineBuffer:
|
|
52
|
+
def __init__(self):
|
|
53
|
+
self.head_lines = []
|
|
54
|
+
self.tail_lines = []
|
|
55
|
+
self.extra_line_count = 0
|
|
56
|
+
|
|
57
|
+
def append(self, line):
|
|
58
|
+
if len(self.head_lines) < OUTPUT_HEAD_LINES:
|
|
59
|
+
self.head_lines.append(line)
|
|
60
|
+
return
|
|
61
|
+
self.extra_line_count += 1
|
|
62
|
+
self.tail_lines.append(line)
|
|
63
|
+
if len(self.tail_lines) > OUTPUT_TAIL_LINES:
|
|
64
|
+
self.tail_lines.pop(0)
|
|
65
|
+
|
|
66
|
+
def lines(self):
|
|
67
|
+
if self.extra_line_count == 0:
|
|
68
|
+
return list(self.head_lines)
|
|
69
|
+
hidden_count = self.extra_line_count - len(self.tail_lines)
|
|
70
|
+
if hidden_count <= 0:
|
|
71
|
+
return [*self.head_lines, *self.tail_lines]
|
|
72
|
+
return [*self.head_lines, f"...({hidden_count} lines omitted)...\n", *self.tail_lines]
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def selected_projects(config, platform, project):
|
|
76
|
+
"""把「构建哪些项目」这件事交还给引擎,编排器不自己解析 supersdk.json。"""
|
|
77
|
+
normalized = supersdk_template.load_and_validate(config, platform, project)
|
|
78
|
+
supersdk_template.require_selection(normalized, platform, project)
|
|
79
|
+
return [{"type": item["type"], "dir": item["dir"]} for item in normalized["projects"]]
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def helper_command(root, project, config):
|
|
83
|
+
script = Path(root) / "scripts" / f"build_{project['type']}.sh"
|
|
84
|
+
command = [str(script), "--build", "--project", project["dir"]]
|
|
85
|
+
# 只有 android 需要根配置:它的 snapshot canary 在 managed config 缺席时会回退去读根配置。
|
|
86
|
+
if project["type"] == "android":
|
|
87
|
+
command.extend(["--config", str(config)])
|
|
88
|
+
return command
|
|
85
89
|
|
|
86
90
|
|
|
87
91
|
def helper_timeout_seconds():
|
|
88
92
|
raw = os.environ.get("SUPERSDK_BUILD_HELPER_TIMEOUT_SECONDS")
|
|
89
|
-
if raw
|
|
93
|
+
if raw is None or raw == "":
|
|
90
94
|
return DEFAULT_TIMEOUT_SECONDS
|
|
91
95
|
try:
|
|
92
96
|
value = float(raw)
|
|
93
|
-
if math.isfinite(value) and value > 0:
|
|
94
|
-
return value
|
|
95
97
|
except ValueError:
|
|
96
|
-
|
|
97
|
-
|
|
98
|
+
warn_invalid_timeout(raw)
|
|
99
|
+
return DEFAULT_TIMEOUT_SECONDS
|
|
100
|
+
if value > 0 and math.isfinite(value):
|
|
101
|
+
return value
|
|
102
|
+
warn_invalid_timeout(raw)
|
|
98
103
|
return DEFAULT_TIMEOUT_SECONDS
|
|
99
104
|
|
|
100
105
|
|
|
101
|
-
def
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
106
|
+
def warn_invalid_timeout(raw):
|
|
107
|
+
with OUTPUT_LOCK:
|
|
108
|
+
print(
|
|
109
|
+
f"[orchestrator] warning: ignoring invalid SUPERSDK_BUILD_HELPER_TIMEOUT_SECONDS={raw!r}; using {DEFAULT_TIMEOUT_SECONDS:g}s",
|
|
110
|
+
file=sys.stderr,
|
|
111
|
+
)
|
|
105
112
|
|
|
106
113
|
|
|
107
|
-
def
|
|
108
|
-
|
|
109
|
-
if not helper.is_file():
|
|
110
|
-
raise FileNotFoundError(f"fixed helper missing: {helper}")
|
|
111
|
-
return [
|
|
112
|
-
str(helper), "--build", "--config", str(config), "--project-id", project["projectId"],
|
|
113
|
-
"--output-dir", str(output_dir), "--evidence", str(evidence),
|
|
114
|
-
]
|
|
114
|
+
def decode_line(raw):
|
|
115
|
+
return raw.decode("utf-8", errors="replace")
|
|
115
116
|
|
|
116
117
|
|
|
117
|
-
def
|
|
118
|
+
def sanitize_forwarded_line(line):
|
|
119
|
+
suffix = "\n" if line.endswith("\n") else ""
|
|
120
|
+
body = line[:-1] if suffix else line
|
|
121
|
+
return body.translate(FORWARDED_LINE_SEPARATOR_TRANSLATION) + suffix
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def forward_reader(pipe, platform, stream_name, sink, capture, skip_line_ref, capture_lock):
|
|
118
125
|
try:
|
|
119
|
-
|
|
126
|
+
while True:
|
|
127
|
+
raw = pipe.readline()
|
|
128
|
+
if raw == b"":
|
|
129
|
+
break
|
|
130
|
+
decoded = decode_line(raw)
|
|
131
|
+
normalized = decoded.rstrip("\r\n")
|
|
132
|
+
with capture_lock:
|
|
133
|
+
capture.append(decoded)
|
|
134
|
+
if skip_line_ref[stream_name] is None and is_skip_line(normalized):
|
|
135
|
+
skip_line_ref[stream_name] = normalized
|
|
136
|
+
with OUTPUT_LOCK:
|
|
137
|
+
forwarded = sanitize_forwarded_line(decoded)
|
|
138
|
+
sink.write(f"[{platform} {stream_name}] {forwarded}")
|
|
139
|
+
if not forwarded.endswith("\n"):
|
|
140
|
+
sink.write("\n")
|
|
141
|
+
sink.flush()
|
|
142
|
+
except (OSError, ValueError):
|
|
143
|
+
pass
|
|
144
|
+
finally:
|
|
145
|
+
try:
|
|
146
|
+
pipe.close()
|
|
147
|
+
except Exception:
|
|
148
|
+
pass
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def snapshot_output(stdout_capture, stderr_capture, skip_line_ref, capture_lock):
|
|
152
|
+
with capture_lock:
|
|
153
|
+
return HelperOutput(
|
|
154
|
+
stdout_capture.lines(),
|
|
155
|
+
stderr_capture.lines(),
|
|
156
|
+
skip_line_ref["stdout"],
|
|
157
|
+
skip_line_ref["stderr"],
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def run_helper(command, platform, timeout_seconds):
|
|
162
|
+
stdout_capture = BoundedLineBuffer()
|
|
163
|
+
stderr_capture = BoundedLineBuffer()
|
|
164
|
+
skip_line_ref = {"stdout": None, "stderr": None}
|
|
165
|
+
capture_lock = threading.Lock()
|
|
166
|
+
try:
|
|
167
|
+
process = subprocess.Popen(
|
|
168
|
+
command,
|
|
169
|
+
stdout=subprocess.PIPE,
|
|
170
|
+
stderr=subprocess.PIPE,
|
|
171
|
+
start_new_session=True,
|
|
172
|
+
)
|
|
120
173
|
except OSError as exc:
|
|
121
|
-
return 127,
|
|
174
|
+
return 127, HelperOutput(stdout_capture.lines(), stderr_capture.lines()), f"launch error: {exc}"
|
|
175
|
+
|
|
176
|
+
threads = [
|
|
177
|
+
threading.Thread(
|
|
178
|
+
target=forward_reader,
|
|
179
|
+
args=(process.stdout, platform, "stdout", sys.stdout, stdout_capture, skip_line_ref, capture_lock),
|
|
180
|
+
daemon=True,
|
|
181
|
+
),
|
|
182
|
+
threading.Thread(
|
|
183
|
+
target=forward_reader,
|
|
184
|
+
args=(process.stderr, platform, "stderr", sys.stderr, stderr_capture, skip_line_ref, capture_lock),
|
|
185
|
+
daemon=True,
|
|
186
|
+
),
|
|
187
|
+
]
|
|
188
|
+
for thread in threads:
|
|
189
|
+
thread.start()
|
|
190
|
+
|
|
191
|
+
timed_out = False
|
|
122
192
|
try:
|
|
123
|
-
|
|
193
|
+
exit_code = process.wait(timeout=timeout_seconds)
|
|
124
194
|
except subprocess.TimeoutExpired:
|
|
195
|
+
timed_out = True
|
|
196
|
+
terminate_process_group(process, platform)
|
|
197
|
+
exit_code = 124
|
|
198
|
+
|
|
199
|
+
for thread in threads:
|
|
200
|
+
thread.join(timeout=5)
|
|
201
|
+
pipe_open = any(thread.is_alive() for thread in threads)
|
|
202
|
+
|
|
203
|
+
output = snapshot_output(stdout_capture, stderr_capture, skip_line_ref, capture_lock)
|
|
204
|
+
if timed_out:
|
|
205
|
+
return exit_code, output, f"timeout after {timeout_seconds:g}s"
|
|
206
|
+
if pipe_open:
|
|
207
|
+
with OUTPUT_LOCK:
|
|
208
|
+
print(f"[{platform}] warning: helper output pipe remained open after process exit", file=sys.stderr)
|
|
209
|
+
return exit_code, output, None
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
def terminate_process_group(process, platform):
|
|
213
|
+
try:
|
|
214
|
+
os.killpg(process.pid, signal.SIGTERM)
|
|
215
|
+
except Exception:
|
|
216
|
+
with OUTPUT_LOCK:
|
|
217
|
+
print(f"[{platform}] warning: could not terminate process group {process.pid}", file=sys.stderr)
|
|
218
|
+
try:
|
|
219
|
+
process.terminate()
|
|
220
|
+
except Exception:
|
|
221
|
+
with OUTPUT_LOCK:
|
|
222
|
+
print(f"[{platform}] warning: could not terminate process {process.pid}", file=sys.stderr)
|
|
223
|
+
pass
|
|
224
|
+
try:
|
|
225
|
+
process.wait(timeout=2)
|
|
226
|
+
return
|
|
227
|
+
except Exception:
|
|
228
|
+
pass
|
|
229
|
+
try:
|
|
230
|
+
os.killpg(process.pid, signal.SIGKILL)
|
|
231
|
+
except Exception:
|
|
232
|
+
with OUTPUT_LOCK:
|
|
233
|
+
print(f"[{platform}] warning: could not kill process group {process.pid}", file=sys.stderr)
|
|
125
234
|
try:
|
|
126
|
-
os.killpg(process.pid, signal.SIGTERM)
|
|
127
|
-
except OSError:
|
|
128
235
|
process.kill()
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
for line in stdout.splitlines():
|
|
134
|
-
print(f"[{project_id} stdout] {line}")
|
|
135
|
-
for line in stderr.splitlines():
|
|
136
|
-
print(f"[{project_id} stderr] {line}", file=sys.stderr)
|
|
137
|
-
return process.returncode, stdout, stderr
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
def classify_helper(exit_code, stdout, stderr):
|
|
141
|
-
if exit_code != 0:
|
|
142
|
-
excerpt = " ".join((stderr or stdout).split())
|
|
143
|
-
return "failed", cap_reason(f"exit_code={exit_code}" + (f"; {excerpt}" if excerpt else ""))
|
|
144
|
-
for line in (stdout + "\n" + stderr).splitlines():
|
|
145
|
-
if line.startswith("SKIP_") or line.startswith("BUILD SKIPPED"):
|
|
146
|
-
return "skipped", cap_reason(line)
|
|
147
|
-
return "success", None
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
def cap_reason(value):
|
|
151
|
-
return value if len(value) <= REASON_LIMIT else value[: REASON_LIMIT - 14] + "...(truncated)"
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
def write_json_atomic(path, payload):
|
|
155
|
-
path = Path(path)
|
|
156
|
-
path.parent.mkdir(parents=True, exist_ok=True)
|
|
157
|
-
temp = path.with_name(f".{path.name}.tmp.{os.getpid()}.{uuid.uuid4().hex}")
|
|
158
|
-
with temp.open("x", encoding="utf-8") as handle:
|
|
159
|
-
json.dump(payload, handle, indent=2, ensure_ascii=False)
|
|
160
|
-
handle.write("\n")
|
|
161
|
-
handle.flush()
|
|
162
|
-
os.fsync(handle.fileno())
|
|
163
|
-
os.replace(temp, path)
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
def ensure_evidence(path, project, status, reason):
|
|
167
|
-
path = Path(path)
|
|
168
|
-
if not path.is_file():
|
|
169
|
-
write_json_atomic(path, {
|
|
170
|
-
"schemaVersion": 1,
|
|
171
|
-
"projectId": project["projectId"],
|
|
172
|
-
"type": project["type"],
|
|
173
|
-
"status": status,
|
|
174
|
-
"reason": reason,
|
|
175
|
-
})
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
def relative_file_entry(path, build_root):
|
|
179
|
-
digest, size = sha256_file(path)
|
|
180
|
-
return {"path": Path(path).relative_to(build_root).as_posix(), "sha256": digest, "sizeBytes": size}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
def artifact_entry(path, build_root, artifact_id, kind=None, media_type=None):
|
|
184
|
-
path = Path(path)
|
|
185
|
-
if path.is_symlink():
|
|
186
|
-
raise ValueError(f"artifact may not be a symlink: {path}")
|
|
187
|
-
if path.is_dir():
|
|
188
|
-
digest, size, count = directory_integrity(path)
|
|
189
|
-
result = {
|
|
190
|
-
"id": artifact_id, "kind": "directory", "path": path.relative_to(build_root).as_posix(),
|
|
191
|
-
"sha256": digest, "sizeBytes": size, "fileCount": count,
|
|
192
|
-
}
|
|
193
|
-
else:
|
|
194
|
-
digest, size = sha256_file(path)
|
|
195
|
-
result = {
|
|
196
|
-
"id": artifact_id, "kind": kind or "file", "path": path.relative_to(build_root).as_posix(),
|
|
197
|
-
"sha256": digest, "sizeBytes": size,
|
|
198
|
-
}
|
|
199
|
-
if media_type:
|
|
200
|
-
result["mediaType"] = media_type
|
|
201
|
-
return result
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
def collect_artifacts(project, project_output, build_root):
|
|
205
|
-
project_output = Path(project_output)
|
|
206
|
-
candidates = [item for item in sorted(project_output.iterdir()) if item.name != "evidence.json"] if project_output.exists() else []
|
|
207
|
-
artifacts = []
|
|
208
|
-
if project["type"] == "android":
|
|
209
|
-
candidates = [item for item in candidates if item.is_file() and item.suffix.lower() in (".apk", ".aab")]
|
|
210
|
-
elif project["type"] == "ios":
|
|
211
|
-
candidates = [item for item in candidates if item.is_file() or item.is_dir()]
|
|
212
|
-
elif project["type"] == "site":
|
|
213
|
-
candidates = [item for item in candidates if item.name == "dist" or (item.is_file() and item.suffix == ".zip")]
|
|
214
|
-
else:
|
|
215
|
-
candidates = [item for item in candidates if item.is_file() and item.suffix in (".tar", ".docker")]
|
|
216
|
-
for index, candidate in enumerate(candidates, start=1):
|
|
217
|
-
kind = "docker-image-archive" if project["type"] == "service" else None
|
|
218
|
-
media = "application/vnd.docker.image.rootfs.diff.tar" if kind else None
|
|
219
|
-
if project["type"] == "site":
|
|
220
|
-
artifact_id = "site-dist" if candidate.is_dir() else "site-offline-zip"
|
|
221
|
-
elif project["type"] == "service":
|
|
222
|
-
artifact_id = "service-image"
|
|
223
|
-
elif project["type"] == "android":
|
|
224
|
-
artifact_id = "android-aab" if candidate.suffix.lower() == ".aab" else "android-apk"
|
|
225
|
-
if any(item["id"] == artifact_id for item in artifacts):
|
|
226
|
-
artifact_id = f"{artifact_id}-{index}"
|
|
227
|
-
else:
|
|
228
|
-
artifact_id = "ios-archive" if index == 1 else f"ios-archive-{index}"
|
|
229
|
-
artifacts.append(artifact_entry(candidate, build_root, artifact_id, kind, media))
|
|
230
|
-
return artifacts
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
def git_source(root):
|
|
236
|
+
except Exception:
|
|
237
|
+
with OUTPUT_LOCK:
|
|
238
|
+
print(f"[{platform}] warning: could not kill process {process.pid}", file=sys.stderr)
|
|
239
|
+
pass
|
|
234
240
|
try:
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
except (OSError, subprocess.CalledProcessError):
|
|
239
|
-
return {"gitCommit": None, "dirty": None}
|
|
241
|
+
process.wait(timeout=2)
|
|
242
|
+
except Exception:
|
|
243
|
+
pass
|
|
240
244
|
|
|
241
245
|
|
|
242
|
-
def
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
if
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
246
|
+
def is_skip_line(line):
|
|
247
|
+
return line.startswith("SKIP_") or line.startswith("BUILD SKIPPED")
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
def first_skip_line(output):
|
|
251
|
+
if output.stdout_skip_line is not None:
|
|
252
|
+
return output.stdout_skip_line
|
|
253
|
+
if output.stderr_skip_line is not None:
|
|
254
|
+
return output.stderr_skip_line
|
|
255
|
+
for lines in (output.stdout_lines, output.stderr_lines):
|
|
256
|
+
for line in lines:
|
|
257
|
+
normalized = line.rstrip("\r\n")
|
|
258
|
+
if is_skip_line(normalized):
|
|
259
|
+
return normalized
|
|
260
|
+
return None
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
def output_excerpt(output):
|
|
264
|
+
for lines in (output.stderr_lines, output.stdout_lines):
|
|
265
|
+
text = "".join(line for line in lines if not is_omission_marker(line)).strip()
|
|
266
|
+
if text:
|
|
267
|
+
return " ".join(text.split())
|
|
268
|
+
return ""
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
def is_omission_marker(line):
|
|
272
|
+
return line.startswith("...(") and line.endswith(" lines omitted)...\n")
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
def cap_reason(reason):
|
|
276
|
+
if len(reason) <= REASON_LIMIT:
|
|
277
|
+
return reason
|
|
278
|
+
return reason[: REASON_LIMIT - len(TRUNCATION_MARKER)] + TRUNCATION_MARKER
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
def classify_result(project, command, exit_code, output, launch_or_timeout_reason=None):
|
|
282
|
+
command_payload = [str(item) for item in command]
|
|
283
|
+
if launch_or_timeout_reason is not None:
|
|
284
|
+
return platform_result(project, "failed", exit_code, cap_reason(launch_or_timeout_reason), command_payload)
|
|
285
|
+
|
|
286
|
+
if exit_code != 0:
|
|
287
|
+
excerpt = output_excerpt(output)
|
|
288
|
+
reason = f"exit_code={exit_code}"
|
|
289
|
+
if excerpt:
|
|
290
|
+
reason = f"{reason}; {excerpt}"
|
|
291
|
+
return platform_result(project, "failed", exit_code, cap_reason(reason), command_payload)
|
|
292
|
+
|
|
293
|
+
if project["type"] not in NO_SKIP_MODE_TYPES:
|
|
294
|
+
marker = first_skip_line(output)
|
|
295
|
+
if marker is not None:
|
|
296
|
+
return platform_result(project, "skipped", exit_code, cap_reason(marker), command_payload)
|
|
297
|
+
|
|
298
|
+
return platform_result(project, "success", exit_code, "", command_payload)
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
def platform_result(project, status, exit_code, reason, command):
|
|
277
302
|
return {
|
|
278
|
-
"
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
"
|
|
282
|
-
"
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
},
|
|
287
|
-
"source": git_source(root),
|
|
288
|
-
"selection": {"mode": "single" if project_id else "all", "projectIds": [item["projectId"] for item in projects]},
|
|
289
|
-
"projects": results,
|
|
303
|
+
"platform": project["type"],
|
|
304
|
+
# 一个工作空间可以有多个同类型项目(比如两个 site)。没有 dir,两条摘要记录
|
|
305
|
+
# 长得一模一样,谁失败了根本读不出来。
|
|
306
|
+
"dir": project["dir"],
|
|
307
|
+
"status": status,
|
|
308
|
+
"exit_code": int(exit_code),
|
|
309
|
+
"reason": reason,
|
|
310
|
+
"command": command,
|
|
290
311
|
}
|
|
291
312
|
|
|
292
313
|
|
|
293
|
-
def
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
314
|
+
def aggregate_summary(results):
|
|
315
|
+
statuses = [item["status"] for item in results]
|
|
316
|
+
if any(status == "failed" for status in statuses):
|
|
317
|
+
overall_status = "failed"
|
|
318
|
+
elif statuses and all(status == "skipped" for status in statuses):
|
|
319
|
+
overall_status = "skipped"
|
|
320
|
+
else:
|
|
321
|
+
overall_status = "success"
|
|
322
|
+
exit_code = 1 if overall_status == "failed" else 0
|
|
297
323
|
return {
|
|
298
|
-
"
|
|
299
|
-
"
|
|
300
|
-
"
|
|
301
|
-
"
|
|
302
|
-
"selection": manifest["selection"],
|
|
303
|
-
"projects": [{"projectId": item["projectId"], "type": item["type"], "status": item["status"], **({"reason": item["reason"]} if "reason" in item else {})} for item in manifest["projects"]],
|
|
324
|
+
"schema_version": SUMMARY_SCHEMA_VERSION,
|
|
325
|
+
"overall_status": overall_status,
|
|
326
|
+
"overall_exit_code": exit_code,
|
|
327
|
+
"platforms": results,
|
|
304
328
|
}
|
|
305
329
|
|
|
306
330
|
|
|
331
|
+
def emit_summary(summary):
|
|
332
|
+
payload = SUMMARY_PREFIX + json.dumps(summary, separators=(",", ":")) + "\n"
|
|
333
|
+
with OUTPUT_LOCK:
|
|
334
|
+
sys.stdout.write(payload)
|
|
335
|
+
sys.stdout.flush()
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
def command_payload(command):
|
|
339
|
+
return [str(part) for part in command] if command else ["<command-unavailable>"]
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
def run_all(root, projects, config):
|
|
343
|
+
timeout = helper_timeout_seconds()
|
|
344
|
+
results = []
|
|
345
|
+
for index, item in enumerate(projects):
|
|
346
|
+
command = []
|
|
347
|
+
try:
|
|
348
|
+
command = helper_command(root, item, config)
|
|
349
|
+
exit_code, output, launch_or_timeout_reason = run_helper(command, item["type"], timeout)
|
|
350
|
+
results.append(classify_result(item, command, exit_code, output, launch_or_timeout_reason))
|
|
351
|
+
except Exception as exc:
|
|
352
|
+
results.append(
|
|
353
|
+
platform_result(
|
|
354
|
+
item,
|
|
355
|
+
"failed",
|
|
356
|
+
1,
|
|
357
|
+
cap_reason(f"internal orchestrator error: {exc}"),
|
|
358
|
+
command_payload(command),
|
|
359
|
+
)
|
|
360
|
+
)
|
|
361
|
+
for remaining in projects[index + 1 :]:
|
|
362
|
+
remaining_command = []
|
|
363
|
+
try:
|
|
364
|
+
remaining_command = helper_command(root, remaining, config)
|
|
365
|
+
except Exception:
|
|
366
|
+
pass
|
|
367
|
+
results.append(
|
|
368
|
+
platform_result(
|
|
369
|
+
remaining,
|
|
370
|
+
"failed",
|
|
371
|
+
1,
|
|
372
|
+
cap_reason(f"not run after internal orchestrator error in {item['dir']}: {exc}"),
|
|
373
|
+
command_payload(remaining_command),
|
|
374
|
+
)
|
|
375
|
+
)
|
|
376
|
+
break
|
|
377
|
+
return aggregate_summary(results)
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
def fallback_internal_summary(projects, root, config, exc):
|
|
381
|
+
results = []
|
|
382
|
+
for index, item in enumerate(projects):
|
|
383
|
+
try:
|
|
384
|
+
command = helper_command(root, item, config)
|
|
385
|
+
except Exception:
|
|
386
|
+
command = []
|
|
387
|
+
reason = f"internal orchestrator error: {exc}" if index == 0 else f"not run after internal orchestrator error: {exc}"
|
|
388
|
+
results.append(platform_result(item, "failed", 1, cap_reason(reason), command_payload(command)))
|
|
389
|
+
return aggregate_summary(results)
|
|
390
|
+
|
|
391
|
+
|
|
307
392
|
def main(argv=None):
|
|
308
|
-
parser = argparse.ArgumentParser(description="
|
|
393
|
+
parser = argparse.ArgumentParser(description="Run SuperSDK workspace project builds and emit one root summary")
|
|
309
394
|
parser.add_argument("--root", required=True)
|
|
395
|
+
parser.add_argument("--platform", choices=["all", *PROJECT_TYPES], default="all")
|
|
396
|
+
parser.add_argument("--project", default=None)
|
|
310
397
|
parser.add_argument("--config", required=True)
|
|
311
|
-
parser.add_argument("--output-dir", required=True)
|
|
312
|
-
parser.add_argument("--project")
|
|
313
|
-
parser.add_argument("--cli-version")
|
|
314
398
|
args = parser.parse_args(argv)
|
|
399
|
+
|
|
315
400
|
root = Path(args.root).resolve()
|
|
316
401
|
config = Path(args.config).resolve()
|
|
317
|
-
output = Path(args.output_dir).resolve()
|
|
318
|
-
if output.exists():
|
|
319
|
-
print(f"BUILD_OUTPUT_EXISTS: {output}", file=sys.stderr)
|
|
320
|
-
return 1
|
|
321
|
-
output.parent.mkdir(parents=True, exist_ok=True)
|
|
322
|
-
staging = output.with_name(f".{output.name}.staging.{os.getpid()}.{uuid.uuid4().hex}")
|
|
323
402
|
try:
|
|
324
|
-
|
|
325
|
-
manifest = build_manifest(root, config, staging, args.project, args.cli_version)
|
|
326
|
-
write_json_atomic(staging / MANIFEST_FILENAME, manifest)
|
|
327
|
-
os.replace(staging, output)
|
|
328
|
-
summary = summary_from_manifest(manifest)
|
|
329
|
-
print(SUMMARY_PREFIX + json.dumps(summary, separators=(",", ":")))
|
|
330
|
-
return summary["overallExitCode"]
|
|
403
|
+
projects = selected_projects(config, args.platform, args.project)
|
|
331
404
|
except supersdk_template.ConfigError as exc:
|
|
405
|
+
# 配置错误发生在编排开始**之前**:按契约,这种情况不发摘要。
|
|
332
406
|
print(str(exc), file=sys.stderr)
|
|
333
407
|
return 1
|
|
408
|
+
try:
|
|
409
|
+
summary = run_all(root, projects, config)
|
|
410
|
+
except Exception as exc:
|
|
411
|
+
summary = fallback_internal_summary(projects, root, config, exc)
|
|
412
|
+
try:
|
|
413
|
+
emit_summary(summary)
|
|
334
414
|
except Exception as exc:
|
|
335
|
-
print(f"internal orchestrator error: {exc}", file=sys.stderr)
|
|
415
|
+
print(f"internal orchestrator error while emitting summary: {exc}", file=sys.stderr)
|
|
336
416
|
return 1
|
|
337
|
-
|
|
338
|
-
if staging.exists():
|
|
339
|
-
import shutil
|
|
340
|
-
shutil.rmtree(staging, ignore_errors=True)
|
|
417
|
+
return summary["overall_exit_code"]
|
|
341
418
|
|
|
342
419
|
|
|
343
420
|
if __name__ == "__main__":
|