Files
vpn-dns-gateway/demo/ci/record-source-change.py
vsun1 c4ca770ee4
vpn-dns-gateway/pipeline/head This commit looks good
vpn-dns-gateway/pipeline/pr-main This commit looks good
Support issue-linked demo source changes
2026-11-27 20:42:33 -05:00

53 lines
2.5 KiB
Python

"""Record the current intentional tree diff; review it before staging or committing.
This creates metadata only. It never edits product source, stages files, verifies
issue existence, or grants approval. A content-changing rename is a delete/add.
"""
import argparse
import json
from pathlib import Path
import sys
sys.dont_write_bytecode = True
from source_provenance import BASELINE_SHA256, UPSTREAM_COMMIT, expected_files, identity, is_link, load_definition, verify_source
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--issue-url', required=True)
parser.add_argument('--change-id', required=True)
parser.add_argument('--description', required=True)
args = parser.parse_args()
demo = Path(__file__).resolve().parents[1]
target = demo / 'source-change.json'
try:
manifest, existing, _, _ = load_definition(demo)
if existing is not None:
raise ValueError('Preserve existing source-change.json; inspect it before replacing it')
source = demo / 'tikzrefinery'
if is_link(source):
raise ValueError('Source root must not be a link')
actual = {}
for path in sorted(source.rglob('*')):
if is_link(path):
raise ValueError(f'Source link rejected: {path}')
if path.is_file():
name = path.relative_to(source).as_posix()
# Preserve original modes. New source/docs default to ordinary files;
# review executable additions and their index modes explicitly.
mode = manifest['files'].get(name, {}).get('mode', '100644')
actual[name] = identity(path.read_bytes(), mode)
changes = []
for name in sorted(set(manifest['files']) | set(actual)):
before, after = manifest['files'].get(name), actual.get(name)
if before != after:
changes.append(dict(before=name if before is not None else None,
after=dict(path=name, **after) if after is not None else None))
record = dict(schema_version=1, upstream_commit=UPSTREAM_COMMIT,
baseline_manifest_sha256=BASELINE_SHA256, change_id=args.change_id,
issue_url=args.issue_url, description=args.description, changes=changes)
expected_files(manifest, record)
with target.open('x', encoding='utf-8', newline='\n') as stream:
stream.write(json.dumps(record, indent=2) + '\n')
print(json.dumps(verify_source(demo), indent=2))
except (ValueError, OSError) as error:
parser.exit(1, f'Change recording failed: {error}\n')