#!/usr/bin/env python3 """Exercise mixed workspace generation/check and native Go multi-module builds remotely.""" import argparse import hashlib import json import os from pathlib import Path import re import tempfile import time from verifyErrorInheritanceRelease import run ROOT = Path(__file__).resolve().parents[1] MODULE = "git.yuntuo.hk/k2safe/go-omni" def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--version", required=True) parser.add_argument("--report", type=Path, default=ROOT / "reports/workspaceRemote.json") args = parser.parse_args() if not re.fullmatch(r"v\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?", args.version): parser.error("a fixed release version is required") env = {k: v for k, v in os.environ.items() if not k.startswith("GO_OMNI_")} env.update(GOWORK="off", GOFLAGS="", GOPRIVATE="git.yuntuo.hk", GONOSUMDB="git.yuntuo.hk") started = time.monotonic() with tempfile.TemporaryDirectory(prefix="goOmniWorkspaceRelease-") as directory: temp = Path(directory) (temp / "bin").mkdir() env.update(GOBIN=str(temp / "bin"), GOMODCACHE=str(temp / "modcache")) print(f"Installing remote CLI {args.version} in an empty cache", flush=True) run(["go", "install", MODULE + "/cmd/go-omni@" + args.version], temp, env) dependency = json.loads(run(["go", "mod", "download", "-json", MODULE + "@" + args.version], temp, env)) assert dependency["Version"] == args.version and dependency.get("Sum") downloaded = Path(dependency["Dir"]) env.update(GO_OMNI_SCAFFOLD_INTEGRATION="1", GO_OMNI_RELEASE_CLI=str(temp / "bin/go-omni"), GO_OMNI_RELEASE_VERSION=args.version) print("Testing mixed API/project consumers and go.work builds from the downloaded release", flush=True) output = run(["go", "test", "-race", "-json", "-count=1", "-timeout=240s", "./cmd/go-omni", "-run", "^TestMixedWorkspaceConsumer$"], downloaded, env) events = [json.loads(line) for line in output.splitlines() if line.startswith("{")] passed = [e["Test"] for e in events if e.get("Action") == "pass" and "Test" in e] assert passed == ["TestMixedWorkspaceConsumer"], output evidence = "".join(e.get("Output", "") for e in events) assert evidence.count("; no local replace") == 2, evidence assert dependency["Sum"] in evidence, evidence sources = ["cmd/go-omni/apigen/workspace.go", "cmd/go-omni/apigen/workspaceMixed_test.go", "cmd/go-omni/apigen/workspaceCatalog_test.go", "cmd/go-omni/workspace.go", "cmd/go-omni/workspace_test.go", "scripts/verifyWorkspaceRelease.py"] report = { "passed": True, "frameworkVersion": args.version, "frameworkSum": dependency["Sum"], "freshModuleCache": True, "noLocalReplace": True, "durationSeconds": round(time.monotonic() - started, 2), "checks": ["remoteCLIInstall", "remoteAPIModule", "remoteGenericModule", "explicitKinds", "manifestInferredKinds", "mixedFormatWithProjectSkip", "mixedGeneration", "mixedCheck", "nativeGoWorkBuild", "nativeGoWorkRaceTests", "moduleAndWorkspaceMetadataPreserved", "bothProjectFailuresAggregated", "nonzeroFailureExit", "failedCheckIsReadOnly", "crossProjectPreflight", "missingGeneratedOutputRestored"], "sourceHashes": {p: hashlib.sha256((ROOT / p).read_bytes()).hexdigest() for p in sources}, } args.report.write_text(json.dumps(report, ensure_ascii=False, indent=2) + "\n") print(f"PASS remote mixed workspace {args.version}: {len(report['checks'])} checks", flush=True) if __name__ == "__main__": main()