70 lines
2.3 KiB
Python
Executable File
70 lines
2.3 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Generate the delivery file list from Git instead of hand-maintained counts."""
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import json
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
|
|
def git(root: Path, *args: str) -> list[str]:
|
|
output = subprocess.check_output(
|
|
["git", *args], cwd=root, text=True, encoding="utf-8"
|
|
)
|
|
return [line for line in output.splitlines() if line]
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("--base", default="main")
|
|
parser.add_argument(
|
|
"--output",
|
|
default="reports/gitea-tag-publication-atomicity-delivery.json",
|
|
)
|
|
args = parser.parse_args()
|
|
root = Path(
|
|
subprocess.check_output(
|
|
["git", "rev-parse", "--show-toplevel"], text=True, encoding="utf-8"
|
|
).strip()
|
|
)
|
|
output = Path(args.output)
|
|
if output.is_absolute() or ".." in output.parts:
|
|
raise SystemExit("output must remain inside the repository")
|
|
output_path = root / output
|
|
output_path.parent.mkdir(parents=True, exist_ok=True)
|
|
base_oid = git(root, "rev-parse", "--verify", f"{args.base}^{{commit}}")[0]
|
|
source_commit = git(root, "rev-parse", "--verify", "HEAD^{commit}")[0]
|
|
source_branch = git(root, "symbolic-ref", "--short", "HEAD")[0]
|
|
commit_range = f"{base_oid}..{source_commit}"
|
|
commits = git(root, "log", "--reverse", "--format=%H", commit_range)
|
|
files = [
|
|
path
|
|
for path in git(root, "diff", "--name-only", commit_range)
|
|
if path != output.as_posix()
|
|
]
|
|
payload = {
|
|
"base": args.base,
|
|
"base_oid": base_oid,
|
|
"source_branch": source_branch,
|
|
"source_commit": source_commit,
|
|
"commit_count": len(commits),
|
|
"commits": commits,
|
|
"file_count": len(files),
|
|
"files": files,
|
|
"manifest_path": output.as_posix(),
|
|
"generated_from": {
|
|
"commit_range": commit_range,
|
|
"files_command": f"git diff --name-only {commit_range}",
|
|
"commits_command": f"git log --reverse --format=%H {commit_range}",
|
|
},
|
|
}
|
|
output_path.write_text(
|
|
json.dumps(payload, indent=2, sort_keys=True) + "\n", encoding="utf-8"
|
|
)
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|