Use existing DC CMS publication workflow
This commit is contained in:
@@ -1,68 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Package the four-file scroll repair for the registered dc-cms-site-nodedc runner."""
|
||||
import argparse
|
||||
import gzip
|
||||
import hashlib
|
||||
import io
|
||||
import json
|
||||
from pathlib import Path
|
||||
import re
|
||||
import subprocess
|
||||
import tarfile
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
ENTRIES = (
|
||||
"assets/custom/css/app.css",
|
||||
"assets/custom/css/out.css",
|
||||
"index.html",
|
||||
"templates/pages/home/shell.html",
|
||||
)
|
||||
|
||||
|
||||
def bundle(root, commit, patch_id):
|
||||
if not re.fullmatch(r"[0-9a-f]{40}", commit):
|
||||
raise ValueError("full_source_commit_required")
|
||||
if not re.fullmatch(r"nodedc-scroll-layout-[0-9]{8}-[0-9]{3}", patch_id):
|
||||
raise ValueError("invalid_patch_id")
|
||||
files = {
|
||||
"manifest.env": (f"id={patch_id}\ncomponent=dc-cms-site-nodedc\ntype=app-overlay\n").encode(),
|
||||
"files.txt": ("\n".join(ENTRIES) + "\n").encode(),
|
||||
}
|
||||
for entry in ENTRIES:
|
||||
mode = subprocess.check_output(["git", "ls-tree", commit, "--", entry], cwd=root, text=True)
|
||||
if not mode.startswith("100644 blob "):
|
||||
raise ValueError(f"regular_committed_file_required:{entry}")
|
||||
files["payload/" + entry] = subprocess.check_output(["git", "show", f"{commit}:{entry}"], cwd=root)
|
||||
output = io.BytesIO()
|
||||
with gzip.GzipFile(fileobj=output, mode="wb", filename="", mtime=0) as compressed:
|
||||
with tarfile.open(fileobj=compressed, mode="w", format=tarfile.USTAR_FORMAT) as archive:
|
||||
for name, content in sorted(files.items()):
|
||||
info = tarfile.TarInfo(name)
|
||||
info.size, info.mode, info.mtime = len(content), 0o644, 0
|
||||
archive.addfile(info, io.BytesIO(content))
|
||||
return output.getvalue()
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--source-commit", required=True)
|
||||
parser.add_argument("--patch-id", required=True)
|
||||
parser.add_argument("--output-dir", required=True, type=Path)
|
||||
args = parser.parse_args()
|
||||
actual = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=ROOT, text=True).strip()
|
||||
if actual != args.source_commit:
|
||||
raise SystemExit("source_commit_mismatch")
|
||||
if subprocess.check_output(["git", "status", "--porcelain"], cwd=ROOT, text=True).strip():
|
||||
raise SystemExit("clean_committed_source_required")
|
||||
data = bundle(ROOT, actual, args.patch_id)
|
||||
args.output_dir.mkdir(parents=True, exist_ok=True)
|
||||
target = args.output_dir / (args.patch_id + ".tgz")
|
||||
with target.open("xb") as stream:
|
||||
stream.write(data)
|
||||
print(json.dumps({"artifact": str(target.resolve()), "patchId": args.patch_id,
|
||||
"component": "dc-cms-site-nodedc", "sourceCommit": actual,
|
||||
"sha256": hashlib.sha256(data).hexdigest(), "files": ENTRIES}))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,75 +0,0 @@
|
||||
import io
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tarfile
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
from build_scroll_layout_artifact import ENTRIES, bundle
|
||||
|
||||
|
||||
class ArtifactContract(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.temp = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(self.temp.cleanup)
|
||||
self.root = Path(self.temp.name)
|
||||
self.git("init", "-q")
|
||||
self.git("config", "user.email", "artifact-test@localhost")
|
||||
self.git("config", "user.name", "Artifact Test")
|
||||
for entry in ENTRIES:
|
||||
path = self.root / entry
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_text("fixture:" + entry)
|
||||
(self.root / ".env").write_text("SECRET=must-not-be-packaged")
|
||||
self.git("add", ".")
|
||||
self.git("commit", "-qm", "fixture")
|
||||
self.commit = self.git("rev-parse", "HEAD").strip()
|
||||
|
||||
def git(self, *args):
|
||||
return subprocess.check_output(["git", *args], cwd=self.root, text=True)
|
||||
|
||||
def build(self, **kwargs):
|
||||
return bundle(self.root, kwargs.get("commit", self.commit),
|
||||
kwargs.get("patch_id", "nodedc-scroll-layout-20261014-001"))
|
||||
|
||||
def test_deterministic_exact_scope_and_committed_bytes(self):
|
||||
first = self.build()
|
||||
(self.root / ENTRIES[0]).write_text("uncommitted data")
|
||||
self.assertEqual(first, self.build())
|
||||
with tarfile.open(fileobj=io.BytesIO(first), mode="r:gz") as archive:
|
||||
expected = {"manifest.env", "files.txt", *("payload/" + p for p in ENTRIES)}
|
||||
self.assertEqual(set(archive.getnames()), expected)
|
||||
for member in archive.getmembers():
|
||||
self.assertTrue(member.isfile())
|
||||
self.assertEqual(member.mode, 0o644)
|
||||
manifest = archive.extractfile("manifest.env").read().decode()
|
||||
self.assertEqual(manifest, "id=nodedc-scroll-layout-20261014-001\ncomponent=dc-cms-site-nodedc\ntype=app-overlay\n")
|
||||
self.assertEqual(archive.extractfile("files.txt").read().decode().splitlines(), list(ENTRIES))
|
||||
self.assertEqual(archive.extractfile("payload/" + ENTRIES[0]).read(), ("fixture:" + ENTRIES[0]).encode())
|
||||
|
||||
def test_missing_file_is_rejected(self):
|
||||
self.git("rm", "-q", ENTRIES[0])
|
||||
self.git("commit", "-qm", "missing file")
|
||||
with self.assertRaises(ValueError):
|
||||
self.build(commit=self.git("rev-parse", "HEAD").strip())
|
||||
|
||||
def test_symlink_is_rejected(self):
|
||||
path = self.root / ENTRIES[0]
|
||||
path.unlink()
|
||||
path.symlink_to("out.css")
|
||||
self.git("add", ENTRIES[0])
|
||||
self.git("commit", "-qm", "symlink")
|
||||
with self.assertRaises(ValueError):
|
||||
self.build(commit=self.git("rev-parse", "HEAD").strip())
|
||||
|
||||
def test_manifest_injection_is_rejected(self):
|
||||
with self.assertRaises(ValueError):
|
||||
self.build(patch_id="nodedc-scroll-layout-20261014-001\ncomponent=dc-cms")
|
||||
|
||||
def test_mutable_revision_is_rejected(self):
|
||||
with self.assertRaises(ValueError):
|
||||
self.build(commit="HEAD")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user