Add core detection and scheduler adapters
This commit is contained in:
1 parent
f06ad804a5
commit
06a4e67e80
28 files changed
+1440
-2
No files matched your search
@@ -0,0 +1,48 @@
|
||||
"""Build a genuine Spigot test server using official BuildTools."""
|
||||
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import shutil
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
TOOL_URL = "https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar"
|
||||
|
||||
|
||||
def sha256(path):
|
||||
with path.open("rb") as stream:
|
||||
return hashlib.file_digest(stream, "sha256").hexdigest()
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--java", type=lambda value: Path(value).resolve(), required=True)
|
||||
parser.add_argument("--version", choices=("1.21.1", "1.21.4", "1.21.8", "1.21.11"), required=True)
|
||||
args = parser.parse_args()
|
||||
directory = ROOT / ".test-servers" / "spigot" / args.version
|
||||
build = directory / "buildtools"
|
||||
build.mkdir(parents=True, exist_ok=True)
|
||||
jar = build / "BuildTools.jar"
|
||||
if not jar.is_file():
|
||||
partial = build / "BuildTools.download"
|
||||
subprocess.run(["curl", "-fsSL", "--retry", "2", "--connect-timeout", "10",
|
||||
"--max-time", "120", TOOL_URL, "-o", str(partial)], check=True)
|
||||
partial.replace(jar)
|
||||
log = build / "build.log"
|
||||
with log.open("wb") as output:
|
||||
subprocess.run([str(args.java), "-Dfile.encoding=UTF-8", "-Xmx3G", "-jar", str(jar),
|
||||
"--rev", args.version, "--compile", "SPIGOT", "--nogui"],
|
||||
cwd=build, stdout=output, stderr=subprocess.STDOUT, check=True)
|
||||
final = directory / "server.jar"
|
||||
shutil.copy2(build / f"spigot-{args.version}.jar", final)
|
||||
data = {"core": "spigot", "version": args.version, "buildtools_url": TOOL_URL,
|
||||
"buildtools_sha256": sha256(jar), "server_sha256": sha256(final),
|
||||
"build_log": str(log)}
|
||||
(directory / "source.json").write_text(json.dumps(data, indent=2), encoding="utf-8")
|
||||
print(final)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,33 @@
|
||||
const { createClient } = require(process.argv[2]);
|
||||
const client = createClient({
|
||||
host: "127.0.0.1",
|
||||
port: Number(process.argv[3]),
|
||||
version: process.argv[4],
|
||||
username: "ICGProbe",
|
||||
auth: "offline",
|
||||
hideErrors: true,
|
||||
});
|
||||
|
||||
let loggedIn = false;
|
||||
const timeout = setTimeout(() => {
|
||||
console.error("Timed out connecting to the test server");
|
||||
process.exit(1);
|
||||
}, 20_000);
|
||||
|
||||
client.on("login", () => {
|
||||
loggedIn = true;
|
||||
console.log("Minecraft protocol login completed");
|
||||
clearTimeout(timeout);
|
||||
setTimeout(() => client.end("Probe finished"), 4_000);
|
||||
});
|
||||
client.on("error", error => {
|
||||
console.error(error.message);
|
||||
process.exitCode = 1;
|
||||
});
|
||||
client.on("end", reason => {
|
||||
clearTimeout(timeout);
|
||||
if (!loggedIn) {
|
||||
console.error("Disconnected before login:", reason);
|
||||
process.exitCode = 1;
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,117 @@
|
||||
"""Download pinned-by-evidence upstream builds for isolated compatibility runs."""
|
||||
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from pathlib import Path
|
||||
from urllib.parse import urlsplit
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
AGENT = os.environ.get("ICG_DOWNLOAD_USER_AGENT", "ItxiaohuiContentGuard-tests/0.1 (https://www.minecraft.net/)")
|
||||
VERSIONS = ("1.21.1", "1.21.4", "1.21.8", "1.21.11")
|
||||
CURL = "curl.exe" if os.name == "nt" else "curl"
|
||||
|
||||
|
||||
def fetch(url, destination=None, accept=None):
|
||||
command = [CURL, "-fsSL", "--retry", "2",
|
||||
"--connect-timeout", "8", "--max-time", "150", "-A", AGENT, url]
|
||||
if accept:
|
||||
command.extend(["-H", f"Accept: {accept}"])
|
||||
if destination:
|
||||
subprocess.run(command + ["-o", str(destination)], check=True, capture_output=True)
|
||||
else:
|
||||
return json.loads(subprocess.check_output(command, stderr=subprocess.PIPE))
|
||||
|
||||
|
||||
def leaves_release_asset(url, version):
|
||||
headers = subprocess.check_output(
|
||||
[CURL, "-fsS", "--connect-timeout", "8", "--max-time", "15", "-A", AGENT,
|
||||
"-D", "-", "-o", os.devnull, url], stderr=subprocess.PIPE, text=True)
|
||||
redirect = next(line.split(":", 1)[1].strip() for line in headers.splitlines()
|
||||
if line.lower().startswith("location:"))
|
||||
release = urlsplit(redirect)
|
||||
parts = release.path.split("/")
|
||||
if release.hostname != "github.com" or "/".join(parts[1:5]).lower() != "leavesmc/leaves/releases/download":
|
||||
raise ValueError("Leaves download did not redirect to its upstream GitHub releases")
|
||||
info = fetch(f"https://api.github.com/repos/LeavesMC/Leaves/releases/tags/{parts[5]}")
|
||||
return next(item for item in info["assets"] if item["name"] == f"leaves-{version}.jar")
|
||||
|
||||
|
||||
def build_info(core, version, allow_prerelease):
|
||||
if core in ("paper", "folia"):
|
||||
api = f"https://fill.papermc.io/v3/projects/{core}/versions/{version}/builds"
|
||||
builds = fetch(api)
|
||||
stable = [entry for entry in builds if entry["channel"] == "STABLE"]
|
||||
eligible = stable or (builds if allow_prerelease else [])
|
||||
if not eligible:
|
||||
raise ValueError("No stable build in upstream channel")
|
||||
build = max(eligible, key=lambda entry: entry["id"])
|
||||
asset = build["downloads"]["server:default"]
|
||||
return build["id"], build["channel"], asset["url"], asset["checksums"]["sha256"]
|
||||
if core == "purpur":
|
||||
api = f"https://api.purpurmc.org/v2/purpur/{version}"
|
||||
build = fetch(api)["builds"]["latest"]
|
||||
details = fetch(f"{api}/{build}")
|
||||
return build, details.get("result", "unknown"), f"{api}/{build}/download", None
|
||||
api = f"https://api.leavesmc.org/v2/projects/leaves/versions/{version}/builds"
|
||||
builds = fetch(api)["builds"]
|
||||
stable = [entry for entry in builds if entry["channel"] == "default"]
|
||||
eligible = stable or (builds if allow_prerelease else [])
|
||||
if not eligible:
|
||||
raise ValueError("No default-channel build in upstream channel")
|
||||
build = max(eligible, key=lambda entry: entry["build"])
|
||||
asset = build["downloads"]["application"]
|
||||
return (build["build"], build["channel"], f'{api}/{build["build"]}/downloads/{asset["name"]}', asset["sha256"])
|
||||
|
||||
|
||||
def acquire(core, version, should_download, allow_prerelease):
|
||||
destination = ROOT / ".test-servers" / core / version
|
||||
try:
|
||||
build, channel, url, checksum = build_info(core, version, allow_prerelease)
|
||||
status = {"core": core, "version": version, "build": build, "channel": channel,
|
||||
"url": url, "upstream_sha256": checksum}
|
||||
if should_download:
|
||||
destination.mkdir(parents=True, exist_ok=True)
|
||||
partial = destination / "server.download"
|
||||
try:
|
||||
fetch(url, partial)
|
||||
except subprocess.CalledProcessError:
|
||||
if core != "leaves":
|
||||
raise
|
||||
asset = leaves_release_asset(url, version)
|
||||
fetch(asset["url"] + "?download=1", partial, "application/octet-stream")
|
||||
status["url"] = asset["browser_download_url"]
|
||||
with partial.open("rb") as stream:
|
||||
actual = hashlib.file_digest(stream, "sha256").hexdigest()
|
||||
if checksum and actual != checksum:
|
||||
raise ValueError(f"SHA-256 mismatch: {actual}")
|
||||
partial.replace(destination / "server.jar")
|
||||
status["sha256"] = actual
|
||||
(destination / "source.json").write_text(json.dumps(status, indent=2), encoding="utf-8")
|
||||
return status
|
||||
except subprocess.CalledProcessError as error:
|
||||
message = error.stderr if isinstance(error.stderr, str) else error.stderr.decode()
|
||||
return {"core": core, "version": version, "error": message.strip()}
|
||||
except (OSError, KeyError, IndexError, ValueError, StopIteration) as error:
|
||||
return {"core": core, "version": version, "error": str(error)}
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--core", nargs="+", default=["paper", "purpur", "folia", "leaves"],
|
||||
choices=["paper", "purpur", "folia", "leaves"])
|
||||
parser.add_argument("--version", nargs="+", default=VERSIONS, choices=VERSIONS)
|
||||
parser.add_argument("--download", action="store_true")
|
||||
parser.add_argument("--allow-prerelease", action="store_true")
|
||||
args = parser.parse_args()
|
||||
with ThreadPoolExecutor(max_workers=8) as pool:
|
||||
results = [pool.submit(acquire, core, version, args.download, args.allow_prerelease)
|
||||
for core in args.core for version in args.version]
|
||||
print(json.dumps([result.result() for result in results], ensure_ascii=False, indent=2))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user