@supersdk/supercli 0.3.2 → 0.3.3-staging.45
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/build/artifactIntegrity.js +119 -0
- package/dist/build/artifactIntegrity.js.map +1 -0
- package/dist/cli.js +22 -11
- package/dist/cli.js.map +1 -1
- package/dist/commands/add.js +79 -31
- package/dist/commands/add.js.map +1 -1
- package/dist/commands/analytics.js +15 -9
- package/dist/commands/analytics.js.map +1 -1
- package/dist/commands/build.js +231 -0
- package/dist/commands/build.js.map +1 -0
- package/dist/commands/config.js +170 -0
- package/dist/commands/config.js.map +1 -0
- package/dist/commands/db.js +24 -19
- package/dist/commands/db.js.map +1 -1
- package/dist/commands/deploy.js +434 -751
- 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 +31 -20
- package/dist/commands/image.js.map +1 -1
- package/dist/commands/init.js +68 -37
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/logs.js +16 -7
- package/dist/commands/logs.js.map +1 -1
- package/dist/commands/publishSite.js +28 -943
- package/dist/commands/publishSite.js.map +1 -1
- package/dist/commands/register.js +51 -30
- package/dist/commands/register.js.map +1 -1
- package/dist/commands/settings.js +10 -6
- package/dist/commands/settings.js.map +1 -1
- package/dist/config/appConfig.js +40 -36
- package/dist/config/appConfig.js.map +1 -1
- package/dist/config/superConfig.js +429 -0
- package/dist/config/superConfig.js.map +1 -0
- package/dist/deploy/adapterTypes.js +3 -0
- package/dist/deploy/adapterTypes.js.map +1 -0
- package/dist/deploy/manifest.js +381 -0
- package/dist/deploy/manifest.js.map +1 -0
- package/dist/deploy/preflight.js +202 -0
- package/dist/deploy/preflight.js.map +1 -0
- package/dist/deploy/resultWriter.js +178 -0
- package/dist/deploy/resultWriter.js.map +1 -0
- package/dist/deploy/runAdapter.js +299 -0
- package/dist/deploy/runAdapter.js.map +1 -0
- package/dist/deploy/siteAdapter.js +182 -0
- package/dist/deploy/siteAdapter.js.map +1 -0
- package/dist/docker/dockerCli.js +63 -1
- package/dist/docker/dockerCli.js.map +1 -1
- package/dist/output/envelope.js +5 -1
- package/dist/output/envelope.js.map +1 -1
- package/dist/output/resultPrinter.js +3 -0
- 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/siteZip.js +4 -5
- package/dist/publish/siteZip.js.map +1 -1
- package/dist/template/README.md +64 -227
- 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 +6 -5
- package/dist/template/android/supersdk-default.config.json +3 -2
- 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 +26 -10
- package/dist/template/scripts/build_ios.sh +41 -9
- package/dist/template/scripts/build_service.sh +89 -0
- package/dist/template/scripts/build_site.sh +40 -26
- package/dist/template/scripts/lib/workspace.sh +4 -4
- package/dist/template/scripts/serve_web.py +2 -4
- package/dist/template/scripts/super_build_orchestrator.py +278 -355
- package/dist/template/scripts/supersdk_template.py +414 -181
- package/dist/template/scripts/web_package.py +9 -8
- package/dist/template/service/Dockerfile +2 -0
- package/dist/template/{supersdk.json → super.json} +20 -1
- package/dist/template/super_build.sh +39 -113
- package/dist/template/template_manifest.json +5 -4
- package/dist/workspace/config.js +81 -119
- package/dist/workspace/config.js.map +1 -1
- package/dist/workspace/identity.js +15 -14
- package/dist/workspace/identity.js.map +1 -1
- package/dist/workspace/inspect.js +1 -0
- package/dist/workspace/inspect.js.map +1 -1
- package/dist/workspace/projectContext.js +93 -0
- package/dist/workspace/projectContext.js.map +1 -0
- package/dist/workspace/projectIdentity.js +53 -96
- package/dist/workspace/projectIdentity.js.map +1 -1
- package/dist/workspace/template.js +5 -8
- package/dist/workspace/template.js.map +1 -1
- package/package.json +2 -2
- package/dist/publish/siteConfig.js +0 -649
- package/dist/publish/siteConfig.js.map +0 -1
|
@@ -1,420 +1,343 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
|
+
"""Fixed-adapter workspace builder and portable manifest authority."""
|
|
3
|
+
|
|
2
4
|
import argparse
|
|
5
|
+
import hashlib
|
|
3
6
|
import json
|
|
4
7
|
import math
|
|
5
8
|
import os
|
|
6
9
|
import signal
|
|
10
|
+
import stat
|
|
7
11
|
import subprocess
|
|
8
12
|
import sys
|
|
9
13
|
import threading
|
|
10
|
-
|
|
14
|
+
import uuid
|
|
15
|
+
from datetime import datetime, timezone
|
|
11
16
|
from pathlib import Path
|
|
12
17
|
|
|
13
18
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
14
19
|
import supersdk_template
|
|
15
20
|
|
|
16
21
|
|
|
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
|
-
|
|
23
|
+
MANIFEST_FILENAME = "super-build-manifest.json"
|
|
24
|
+
MANIFEST_SCHEMA_VERSION = 1
|
|
24
25
|
DEFAULT_TIMEOUT_SECONDS = 1800.0
|
|
25
26
|
REASON_LIMIT = 500
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def sha256_file(path):
|
|
30
|
+
digest = hashlib.sha256()
|
|
31
|
+
size = 0
|
|
32
|
+
with Path(path).open("rb") as handle:
|
|
33
|
+
while True:
|
|
34
|
+
chunk = handle.read(1024 * 1024)
|
|
35
|
+
if not chunk:
|
|
36
|
+
break
|
|
37
|
+
size += len(chunk)
|
|
38
|
+
digest.update(chunk)
|
|
39
|
+
return digest.hexdigest(), size
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def directory_integrity(path):
|
|
43
|
+
"""Hash ordinary files exactly like SuperCLI deploy preflight.
|
|
44
|
+
|
|
45
|
+
Each sorted entry contributes: rel + NUL + (mode & 0o777) + NUL + file sha256 + LF.
|
|
46
|
+
"""
|
|
47
|
+
root = Path(path)
|
|
48
|
+
digest = hashlib.sha256()
|
|
49
|
+
total_size = 0
|
|
50
|
+
count = 0
|
|
51
|
+
for candidate in sorted(root.rglob("*"), key=lambda item: item.relative_to(root).as_posix()):
|
|
52
|
+
if candidate.is_symlink():
|
|
53
|
+
raise ValueError(f"symlink is not allowed in artifact directory: {candidate}")
|
|
54
|
+
if candidate.is_dir():
|
|
55
|
+
continue
|
|
56
|
+
if not candidate.is_file():
|
|
57
|
+
raise ValueError(f"special file is not allowed in artifact directory: {candidate}")
|
|
58
|
+
mode = stat.S_IMODE(candidate.stat().st_mode) & 0o777
|
|
59
|
+
file_sha, size = sha256_file(candidate)
|
|
60
|
+
rel = candidate.relative_to(root).as_posix()
|
|
61
|
+
digest.update(rel.encode("utf-8") + b"\0" + format(mode, "o").encode("ascii") + b"\0" + file_sha.encode("ascii") + b"\n")
|
|
62
|
+
total_size += size
|
|
63
|
+
count += 1
|
|
64
|
+
return digest.hexdigest(), total_size, count
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def builder_bundle_sha256(root):
|
|
68
|
+
root = Path(root)
|
|
69
|
+
entries = [root / "super_build.sh"]
|
|
70
|
+
entries.extend(
|
|
71
|
+
path for path in sorted((root / "scripts").rglob("*"))
|
|
72
|
+
if "__pycache__" not in path.parts and path.suffix != ".pyc"
|
|
73
|
+
)
|
|
74
|
+
digest = hashlib.sha256()
|
|
75
|
+
for path in entries:
|
|
76
|
+
if path.is_symlink():
|
|
77
|
+
raise ValueError(f"builder bundle contains symlink: {path}")
|
|
78
|
+
if not path.is_file():
|
|
79
|
+
continue
|
|
80
|
+
rel = path.relative_to(root).as_posix()
|
|
81
|
+
file_sha, _ = sha256_file(path)
|
|
82
|
+
mode = stat.S_IMODE(path.stat().st_mode) & 0o777
|
|
83
|
+
digest.update(rel.encode("utf-8") + b"\0" + format(mode, "o").encode("ascii") + b"\0" + file_sha.encode("ascii") + b"\n")
|
|
84
|
+
return digest.hexdigest()
|
|
89
85
|
|
|
90
86
|
|
|
91
87
|
def helper_timeout_seconds():
|
|
92
88
|
raw = os.environ.get("SUPERSDK_BUILD_HELPER_TIMEOUT_SECONDS")
|
|
93
|
-
if raw
|
|
89
|
+
if raw in (None, ""):
|
|
94
90
|
return DEFAULT_TIMEOUT_SECONDS
|
|
95
91
|
try:
|
|
96
92
|
value = float(raw)
|
|
93
|
+
if math.isfinite(value) and value > 0:
|
|
94
|
+
return value
|
|
97
95
|
except ValueError:
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
if value > 0 and math.isfinite(value):
|
|
101
|
-
return value
|
|
102
|
-
warn_invalid_timeout(raw)
|
|
96
|
+
pass
|
|
97
|
+
print(f"[orchestrator] warning: invalid helper timeout {raw!r}; using {DEFAULT_TIMEOUT_SECONDS:g}s", file=sys.stderr)
|
|
103
98
|
return DEFAULT_TIMEOUT_SECONDS
|
|
104
99
|
|
|
105
100
|
|
|
106
|
-
def
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
file=sys.stderr,
|
|
111
|
-
)
|
|
112
|
-
|
|
101
|
+
def selected_projects(config, project_id):
|
|
102
|
+
normalized = supersdk_template.load_and_validate(config, project=project_id)
|
|
103
|
+
supersdk_template.require_selection(normalized, "all", project_id)
|
|
104
|
+
return normalized, normalized["projects"]
|
|
113
105
|
|
|
114
|
-
def decode_line(raw):
|
|
115
|
-
return raw.decode("utf-8", errors="replace")
|
|
116
106
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
return
|
|
107
|
+
def helper_command(root, config, project, output_dir, evidence):
|
|
108
|
+
helper = Path(root) / "scripts" / f"build_{project['type']}.sh"
|
|
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
|
+
]
|
|
122
115
|
|
|
123
116
|
|
|
124
|
-
def
|
|
117
|
+
def run_helper(command, project_id, timeout):
|
|
125
118
|
try:
|
|
126
|
-
|
|
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
|
-
)
|
|
119
|
+
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, start_new_session=True)
|
|
173
120
|
except OSError as exc:
|
|
174
|
-
return 127,
|
|
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
|
|
121
|
+
return 127, "", f"launch error: {exc}"
|
|
192
122
|
try:
|
|
193
|
-
|
|
123
|
+
stdout_raw, stderr_raw = process.communicate(timeout=timeout)
|
|
194
124
|
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)
|
|
234
125
|
try:
|
|
126
|
+
os.killpg(process.pid, signal.SIGTERM)
|
|
127
|
+
except OSError:
|
|
235
128
|
process.kill()
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
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
|
-
|
|
129
|
+
stdout_raw, stderr_raw = process.communicate()
|
|
130
|
+
return 124, stdout_raw.decode("utf-8", "replace"), f"timeout after {timeout:g}s"
|
|
131
|
+
stdout = stdout_raw.decode("utf-8", "replace")
|
|
132
|
+
stderr = stderr_raw.decode("utf-8", "replace")
|
|
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):
|
|
286
141
|
if exit_code != 0:
|
|
287
|
-
excerpt =
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
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):
|
|
234
|
+
try:
|
|
235
|
+
commit = subprocess.check_output(["git", "-C", str(root), "rev-parse", "HEAD"], text=True, stderr=subprocess.DEVNULL).strip()
|
|
236
|
+
dirty = bool(subprocess.check_output(["git", "-C", str(root), "status", "--porcelain"], text=True).strip())
|
|
237
|
+
return {"gitCommit": commit, "dirty": dirty}
|
|
238
|
+
except (OSError, subprocess.CalledProcessError):
|
|
239
|
+
return {"gitCommit": None, "dirty": None}
|
|
299
240
|
|
|
300
241
|
|
|
301
|
-
def
|
|
242
|
+
def build_manifest(root, config_path, output_staging, project_id=None, cli_version=None):
|
|
243
|
+
raw = supersdk_template.load_config(config_path)
|
|
244
|
+
normalized, projects = selected_projects(config_path, project_id)
|
|
245
|
+
bundle_before = builder_bundle_sha256(root)
|
|
246
|
+
results = []
|
|
247
|
+
timeout = helper_timeout_seconds()
|
|
248
|
+
for project in projects:
|
|
249
|
+
project_output = Path(output_staging) / "projects" / project["projectId"]
|
|
250
|
+
project_output.mkdir(parents=True, exist_ok=False)
|
|
251
|
+
evidence_path = project_output / "evidence.json"
|
|
252
|
+
try:
|
|
253
|
+
command = helper_command(root, config_path, project, project_output, evidence_path)
|
|
254
|
+
exit_code, stdout, stderr = run_helper(command, project["projectId"], timeout)
|
|
255
|
+
status, reason = classify_helper(exit_code, stdout, stderr)
|
|
256
|
+
ensure_evidence(evidence_path, project, status, reason)
|
|
257
|
+
artifacts = collect_artifacts(project, project_output, output_staging) if status == "success" else []
|
|
258
|
+
if status == "success" and not artifacts:
|
|
259
|
+
status, reason = "failed", "helper reported success but produced no required artifact"
|
|
260
|
+
ensure_evidence(evidence_path, project, status, reason)
|
|
261
|
+
except Exception as exc:
|
|
262
|
+
status, reason, artifacts = "failed", cap_reason(f"internal orchestrator error: {exc}"), []
|
|
263
|
+
ensure_evidence(evidence_path, project, status, reason)
|
|
264
|
+
result = {
|
|
265
|
+
"projectId": project["projectId"], "type": project["type"], "status": status,
|
|
266
|
+
"evidence": relative_file_entry(evidence_path, output_staging), "artifacts": artifacts,
|
|
267
|
+
}
|
|
268
|
+
if status != "success":
|
|
269
|
+
result["reason"] = reason or status
|
|
270
|
+
results.append(result)
|
|
271
|
+
bundle_after = builder_bundle_sha256(root)
|
|
272
|
+
if bundle_after != bundle_before:
|
|
273
|
+
for result in results:
|
|
274
|
+
if result["status"] == "success":
|
|
275
|
+
result["status"] = "failed"
|
|
276
|
+
result["reason"] = "builder bundle changed during build"
|
|
302
277
|
return {
|
|
303
|
-
"
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
"
|
|
307
|
-
"
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
278
|
+
"schemaVersion": MANIFEST_SCHEMA_VERSION,
|
|
279
|
+
"kind": "super-build-manifest",
|
|
280
|
+
"createdAt": datetime.now(timezone.utc).isoformat().replace("+00:00", "Z"),
|
|
281
|
+
"builder": {"engineVersion": supersdk_template.ENGINE_VERSION, "cliVersion": cli_version, "bundleSha256": bundle_before},
|
|
282
|
+
"config": {
|
|
283
|
+
"schemaVersion": supersdk_template.CONFIG_SCHEMA_VERSION,
|
|
284
|
+
"sha256": supersdk_template.canonical_config_sha256(raw),
|
|
285
|
+
"spid": normalized["spid"],
|
|
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,
|
|
311
290
|
}
|
|
312
291
|
|
|
313
292
|
|
|
314
|
-
def
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
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
|
|
293
|
+
def summary_from_manifest(manifest):
|
|
294
|
+
failed = any(item["status"] == "failed" for item in manifest["projects"])
|
|
295
|
+
skipped_only = bool(manifest["projects"]) and all(item["status"] == "skipped" for item in manifest["projects"])
|
|
296
|
+
overall = "failed" if failed else ("skipped" if skipped_only else "success")
|
|
323
297
|
return {
|
|
324
|
-
"
|
|
325
|
-
"
|
|
326
|
-
"
|
|
327
|
-
"
|
|
298
|
+
"schemaVersion": 1,
|
|
299
|
+
"overallStatus": overall,
|
|
300
|
+
"overallExitCode": 1 if failed else 0,
|
|
301
|
+
"manifest": MANIFEST_FILENAME,
|
|
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"]],
|
|
328
304
|
}
|
|
329
305
|
|
|
330
306
|
|
|
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
|
-
|
|
392
307
|
def main(argv=None):
|
|
393
|
-
parser = argparse.ArgumentParser(description="
|
|
308
|
+
parser = argparse.ArgumentParser(description="Build SuperSDK projects with fixed helpers and emit a portable manifest")
|
|
394
309
|
parser.add_argument("--root", required=True)
|
|
395
|
-
parser.add_argument("--platform", choices=["all", *PROJECT_TYPES], default="all")
|
|
396
|
-
parser.add_argument("--project", default=None)
|
|
397
310
|
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")
|
|
398
314
|
args = parser.parse_args(argv)
|
|
399
|
-
|
|
400
315
|
root = Path(args.root).resolve()
|
|
401
316
|
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}")
|
|
402
323
|
try:
|
|
403
|
-
|
|
324
|
+
staging.mkdir()
|
|
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"]
|
|
404
331
|
except supersdk_template.ConfigError as exc:
|
|
405
|
-
# 配置错误发生在编排开始**之前**:按契约,这种情况不发摘要。
|
|
406
332
|
print(str(exc), file=sys.stderr)
|
|
407
333
|
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)
|
|
414
334
|
except Exception as exc:
|
|
415
|
-
print(f"internal orchestrator error
|
|
335
|
+
print(f"internal orchestrator error: {exc}", file=sys.stderr)
|
|
416
336
|
return 1
|
|
417
|
-
|
|
337
|
+
finally:
|
|
338
|
+
if staging.exists():
|
|
339
|
+
import shutil
|
|
340
|
+
shutil.rmtree(staging, ignore_errors=True)
|
|
418
341
|
|
|
419
342
|
|
|
420
343
|
if __name__ == "__main__":
|