Files
JWeBot/tools/package-plugin.py

71 lines
1.9 KiB
Python
Executable File

#!/usr/bin/env python3
"""Build a deterministic, digest-addressed JWeBot extension artifact."""
from __future__ import annotations
import argparse
import json
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
sys.path[:0] = [
str(ROOT / "packages" / "jwebot-sdk" / "src"),
str(ROOT / "packages" / "jwebot-kernel" / "src"),
]
from jwebot_kernel import ( # noqa: E402
ManifestError,
ReleaseError,
SourcePolicyError,
build_release,
sign_release_record,
)
def main() -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("extension", type=Path)
parser.add_argument("--output", type=Path, required=True)
parser.add_argument("--signing-key", type=Path)
parser.add_argument("--publisher")
args = parser.parse_args()
if (args.signing_key is None) != (args.publisher is None):
parser.error("--signing-key and --publisher must be provided together")
try:
artifact, record_path, record = build_release(
args.extension,
args.output,
)
signature_path = None
if args.signing_key is not None:
signature_path, _ = sign_release_record(
record_path,
args.signing_key,
args.publisher,
)
except (ManifestError, SourcePolicyError, ReleaseError) as error:
parser.error(str(error))
print(
json.dumps(
{
**record.to_mapping(),
"artifact_path": str(artifact),
"release_path": str(record_path),
"signature_path": (
str(signature_path)
if signature_path is not None
else None
),
},
ensure_ascii=False,
sort_keys=True,
)
)
return 0
if __name__ == "__main__":
raise SystemExit(main())