main
ply4 git calls27 ms43 KiB3 cachedprotocol v2
165 lines6.6 KiBRaw
1#!/usr/bin/env python3
2"""Place docs/img/cd-pipeline.mmd on a grid and write docs/img/cd-pipeline.svg.
4mermaid-cli's layered layout puts each failure node on the next row and drifts
5the spine, so connectors sweep across the picture. This keeps the graph in the
6mermaid file (labels, classes, colours, and which node fails to which) and
7draws one row per stage: the happy path on the left, the failure on the right.
8"""
10import pathlib
11import re
12import sys
14ROOT = pathlib.Path(__file__).resolve().parent
15MMD = ROOT / "cd-pipeline.mmd"
16SVG = ROOT / "cd-pipeline.svg"
18NODE = re.compile(r'(\w+)\["([^"]+)"\]:::(\w+)')
19CLASS = re.compile(r"classDef\s+(\w+)\s+fill:(#[0-9a-fA-F]{6}),stroke:(#[0-9a-fA-F]{6})")
20EDGE = r'(\w+)(?:\["[^"]*"\])?(?:::\w+)?\s+{arrow}\s+(\w+)'
21HAPPY = re.compile(EDGE.format(arrow="==>"))
22SIDE = re.compile(EDGE.format(arrow="-->"))
24LEFT_X, LEFT_W, BOX_H = 40, 340, 72
25RIGHT_X, RIGHT_W = 476, 344
26ROW0, ROW_STEP = 84, 112
27WIDTH = 860
30def esc(text: str) -> str:
31 return (
32 text.replace("&", "&")
33 .replace("<", "&lt;")
34 .replace(">", "&gt;")
35 .replace('"', "&quot;")
36 )
39def split_label(label: str) -> tuple[str, str]:
40 kind, _, detail = label.partition(" · ")
41 return kind.strip(), detail.strip()
44def main() -> int:
45 text = MMD.read_text()
46 nodes = {m.group(1): (m.group(2), m.group(3)) for m in NODE.finditer(text)}
47 colors = {m.group(1): (m.group(2), m.group(3)) for m in CLASS.finditer(text)}
48 code = "\n".join(line for line in text.splitlines() if not line.strip().startswith("%%"))
49 bare = re.sub(r'(\w+)\["[^"]*"\]:::\w+', r"\1", code)
50 happy = {src: dst for src, dst in HAPPY.findall(bare)}
51 side = {src: dst for src, dst in SIDE.findall(bare)}
52 targets = set(happy.values())
53 start = [node for node in happy if node not in targets]
54 if len(start) != 1:
55 sys.exit(f"expected one start node, found {start}")
56 column = []
57 node = start[0]
58 while node:
59 column.append(node)
60 node = happy.get(node)
61 if not column or column[-1] in happy:
62 sys.exit("happy path did not end")
64 rows = []
65 for node in column:
66 label, kind = nodes[node]
67 fail = side.get(node)
68 fail_box = None
69 if fail:
70 fail_label, fail_kind = nodes[fail]
71 fail_box = (fail_label, fail_kind)
72 rows.append((label, kind, fail_box))
74 legend = []
75 seen = set()
76 for label, kind, _fail in rows:
77 if kind in seen or kind in {"halt", "done"}:
78 continue
79 seen.add(kind)
80 legend.append((split_label(label)[0], kind))
81 if "rollback" in colors and "rollback" not in seen:
82 legend.append(("Rollback", "rollback"))
84 height = ROW0 + len(rows) * ROW_STEP + 150
85 parts = [
86 '<?xml version="1.0" encoding="UTF-8"?>',
87 f'<svg xmlns="http://www.w3.org/2000/svg" width="{WIDTH}" height="{height}" viewBox="0 0 {WIDTH} {height}" role="img" aria-labelledby="title desc">',
88 ' <title id="title">ply-web operator deploy</title>',
89 ' <desc id="desc">Happy path down the left column. Each failure is a short arrow to the right on that same row. Rendered from cd-pipeline.mmd.</desc>',
90 f' <rect width="{WIDTH}" height="{height}" fill="#ffffff"/>',
91 " <style>",
92 " text { font-family: ui-sans-serif, system-ui, sans-serif; fill: #0f172a; }",
93 " .kind { font-size: 16px; font-weight: 700; }",
94 " .detail { font-size: 14px; font-weight: 500; }",
95 " .legend { font-size: 13px; font-weight: 600; }",
96 " </style>",
97 " <defs>",
98 ' <marker id="arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="8" markerHeight="8" orient="auto-start-reverse">',
99 ' <path d="M 0 1.2 L 9 5 L 0 8.8 z" fill="#334155"/>',
100 " </marker>",
101 " </defs>",
102 ' <text x="40" y="36" class="kind" font-size="18">ply-web operator deploy</text>',
103 ' <text x="40" y="58" class="detail" fill="#475569">Left column moves forward. A failure leaves to the right and stops.</text>',
104 ]
106 def box(x: int, y: int, w: int, kind: str, label: str) -> None:
107 fill, stroke = colors[kind]
108 title, detail = split_label(label)
109 cx = x + w / 2
110 parts.append(
111 f' <rect x="{x}" y="{y}" width="{w}" height="{BOX_H}" rx="10" fill="{fill}" stroke="{stroke}" stroke-width="2"/>'
112 )
113 parts.append(f' <text x="{cx}" y="{y + 28}" text-anchor="middle" class="kind">{esc(title)}</text>')
114 if detail:
115 parts.append(
116 f' <text x="{cx}" y="{y + 50}" text-anchor="middle" class="detail">{esc(detail)}</text>'
117 )
119 for index, (label, kind, fail) in enumerate(rows):
120 y = ROW0 + index * ROW_STEP
121 box(LEFT_X, y, LEFT_W, kind, label)
122 if fail:
123 fail_label, fail_kind = fail
124 box(RIGHT_X, y, RIGHT_W, fail_kind, fail_label)
125 mid = y + 36
126 parts.append(
127 f' <line x1="{LEFT_X + LEFT_W}" y1="{mid}" x2="{RIGHT_X - 8}" y2="{mid}" stroke="#334155" stroke-width="1.75" marker-end="url(#arrow)"/>'
128 )
129 if index + 1 < len(rows):
130 cx = LEFT_X + LEFT_W / 2
131 parts.append(
132 f' <line x1="{cx}" y1="{y + BOX_H}" x2="{cx}" y2="{y + ROW_STEP - 8}" stroke="#334155" stroke-width="2.25" marker-end="url(#arrow)"/>'
133 )
135 legend_y = ROW0 + len(rows) * ROW_STEP + 24
136 parts.append(f' <text x="40" y="{legend_y}" class="detail" fill="#475569">Stage kind</text>')
137 x = 40
138 chip_y = legend_y + 14
139 for title, kind in legend:
140 fill, stroke = colors[kind]
141 w = max(118, 16 + len(title) * 8)
142 parts.append(
143 f' <rect x="{x}" y="{chip_y}" width="{w}" height="32" rx="6" fill="{fill}" stroke="{stroke}" stroke-width="2"/>'
144 )
145 parts.append(
146 f' <text x="{x + w / 2}" y="{chip_y + 21}" text-anchor="middle" class="legend">{esc(title)}</text>'
147 )
148 x += w + 12
149 caption_y = chip_y + 64
150 parts.append(
151 f' <text x="40" y="{caption_y}" class="detail" fill="#475569">Gray boxes are a stop with traffic left as it is. Red boxes move the old version back to 100% and exit.</text>'
152 )
153 # The last text sits on the caption baseline. Keep a margin under it.
154 height = caption_y + 28
155 parts[1] = (
156 f'<svg xmlns="http://www.w3.org/2000/svg" width="{WIDTH}" height="{height}" viewBox="0 0 {WIDTH} {height}" role="img" aria-labelledby="title desc">'
157 )
158 parts.append("</svg>")
159 SVG.write_text("\n".join(parts) + "\n")
160 print(f"wrote {SVG} ({len(rows)} rows)")
161 return 0
164if __name__ == "__main__":
165 raise SystemExit(main())
Diagnostics4 git calls · 27 ms
CallStatusSizeTime027 ms
discover200152 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=152
git.server.agent=gitty/1.0
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch object-format
git.server.fetch=shallow filter sideband-all
git.protocol.version=2
git.pkt.frames=8
git.pkt.data=6
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=152
git.pkt.payload.max=34
ls-refs200145 B · hit3 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=145
git.response.cache=HIT
git.response.duration_ms=3
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=145
git.pkt.payload.max=76
git.ls_refs.count=2
git.ls_refs.head=refs/heads/main
fetchblob:none · deepen 1020040 KiB · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=41349
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=blob:none
git.fetch.filter.requested=tree:0
git.fetch.filter.fallback=blob:none
git.fetch.filter.learned=false
git.fetch.wants=526b305930b8ef382f2d7a1f9c0238730a585921
git.fetch.haves.count=0
git.fetch.deepen=10
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=6
git.pkt.data=4
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=41349
git.pkt.payload.max=41254
git.sideband.band1.bytes=41253
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=61
git.pack.bytes=41253
git.pack.ofs_delta=0
git.pack.ref_delta=0
git.pack.chain.max=0
git.pack.trailer=ab60efef4b7243678c75de64a4386986ee885c1c
git.pack.full=61
Open pack map
fetch2002.6 KiB · hit21 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=21
git.response.bytes=2653
git.response.cache=HIT
git.response.duration_ms=21
git.fetch.wants=b8cbfe310d753ed73150a5461895d549ab6ec953
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=2653
git.pkt.payload.max=2632
git.sideband.band1.bytes=2631
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0

Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.

Remote
https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/ply-web.git
Ref
refs/heads/main
Commit
526b305930b8ef382f2d7a1f9c0238730a585921
cf-ray
a5e339f8a836f162
Request
7aaa51a0…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format