61 lines
3.2 KiB
Python
Executable File
61 lines
3.2 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Build an allowlisted tester archive: never include runtime databases or secrets."""
|
|
import argparse
|
|
import hashlib
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import subprocess
|
|
import tarfile
|
|
import tempfile
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
|
def source_files():
|
|
files = [ROOT / name for name in ("go.mod", "go.sum", "README.md", "install.sh", "uninstall.sh")]
|
|
for directory, patterns in {"cmd": ["*.go"], "internal": ["*.go", "*.md"], "examples": ["*.go", "*.md"],
|
|
"docs": ["*.md"], "scripts": ["*.py", "*.sh"]}.items():
|
|
for pattern in patterns:
|
|
files.extend((ROOT / directory).rglob(pattern))
|
|
return sorted({path for path in files if path.is_file() and not path.is_symlink()})
|
|
|
|
|
|
def package(output, version, target):
|
|
if not version or any(c not in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_" for c in version):
|
|
raise ValueError("Invalid release version")
|
|
output = Path(output).resolve(); output.mkdir(parents=True, exist_ok=True)
|
|
name = f"pipelines-{version}-{target}"
|
|
archive = output / (name + ".tar.gz")
|
|
if archive.exists():
|
|
raise ValueError("Archive exists; use a new version/output directory")
|
|
with tempfile.TemporaryDirectory(prefix="pipelines-package-", dir=output) as temporary:
|
|
binaries = Path(temporary)
|
|
if target != "source":
|
|
system, arch = target.split("-")
|
|
if system not in ("darwin", "linux") or arch not in ("arm64", "amd64"):
|
|
raise ValueError("Supported: source, darwin-arm64/amd64, linux-arm64/amd64")
|
|
env = dict(os.environ, GOOS=system, GOARCH=arch, CGO_ENABLED="0")
|
|
for command, binary in (("pipelines-server", "pipelines-server"), ("pipelines-tui", "pipelines-tui"), ("pipelines", "pipelines"), ("pipelines-claude-host", "pipelines-claude-host"), ("pipelines-codex-host", "pipelines-codex-host")):
|
|
subprocess.run(["go", "build", "-trimpath", "-o", str(binaries / binary), "./cmd/" + command],
|
|
cwd=ROOT, env=env, check=True)
|
|
(binaries / "platform.json").write_text(json.dumps({"os": "Darwin" if system == "darwin" else "Linux", "arch": "arm64" if arch == "arm64" and system == "darwin" else "aarch64" if arch == "arm64" else "x86_64"}))
|
|
with tarfile.open(archive, "w:gz") as tar:
|
|
for path in source_files():
|
|
tar.add(path, arcname=str(Path(name) / path.relative_to(ROOT)), recursive=False)
|
|
if target != "source":
|
|
for path in sorted(binaries.iterdir()):
|
|
tar.add(path, arcname=str(Path(name) / "release-bin" / path.name), recursive=False)
|
|
digest = hashlib.sha256(archive.read_bytes()).hexdigest()
|
|
archive.with_suffix(archive.suffix + ".sha256").write_text(digest + " " + archive.name + "\n")
|
|
return archive
|
|
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("--platform", default="source")
|
|
parser.add_argument("--version", default="0.1.0-beta.1")
|
|
parser.add_argument("--output", type=Path, default=ROOT / "dist")
|
|
args = parser.parse_args()
|
|
print(package(args.output, args.version, args.platform))
|