-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpublish-engineering-program-status.py
More file actions
91 lines (82 loc) · 2.76 KB
/
Copy pathpublish-engineering-program-status.py
File metadata and controls
91 lines (82 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
85
86
87
88
89
90
91
#!/usr/bin/env python3
"""CLI entry point for deterministic engineering program-status publication."""
from __future__ import annotations
import argparse
import json
import logging
from collections.abc import Sequence
from pathlib import Path
from program_status.publisher import (
ProgramStatusPublishError,
ProgramStatusPublishRequest,
publish_program_status,
watch_program_status,
)
def build_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
prog="publish-engineering-program-status",
description="Publish one validated committed EPP status bundle.",
)
parser.add_argument("--repository", required=True)
parser.add_argument("--source", required=True)
parser.add_argument("--data-root", required=True)
parser.add_argument(
"--watch-committed",
action="store_true",
help="Watch committed HEAD and publish after each exact commit change.",
)
parser.add_argument(
"--poll-seconds",
type=float,
default=2.0,
help="Committed-watch poll interval (default: 2 seconds).",
)
return parser
def main(argv: Sequence[str] | None = None) -> int:
args = build_parser().parse_args(argv)
logging.basicConfig(level=logging.INFO, format="%(levelname)s %(message)s")
try:
request = ProgramStatusPublishRequest(
repository=Path(args.repository),
source_commit=args.source,
data_root=Path(args.data_root),
)
if args.watch_committed:
result = watch_program_status(request, poll_seconds=args.poll_seconds)
if result is None: # pragma: no cover - unbounded CLI exits by interrupt
return 0
else:
result = publish_program_status(request)
except KeyboardInterrupt:
print(json.dumps({"status": "stopped", "mode": "committed_watch"}))
return 0
except ProgramStatusPublishError as exc:
print(
json.dumps(
{
"status": "rejected",
"code": exc.code,
"message": str(exc),
"recovery_class": exc.recovery_class,
},
sort_keys=True,
)
)
return 2
print(
json.dumps(
{
"status": "published",
"source_commit": result.source_commit,
"source_tree": result.source_tree,
"program_tree": result.program_tree,
"bundle_id": result.bundle_id,
"installed_artifact": result.installed_artifact,
"changed": result.changed,
},
sort_keys=True,
)
)
return 0
if __name__ == "__main__":
raise SystemExit(main())