Coverage for packages/workshop/src/livery/workshop/_release_driver.py: 86%
Measured by coverage.py 7.16.2 on CPython 3.14 while the suites of tests, packages/workshop/tests/test_workshop_without_docs.py, packages/workshop/tests/test_workshop_vocabulary.py, packages/workshop/tests/test_workshop_sync.py, packages/workshop/tests/test_workshop_shells.py, packages/workshop/tests/test_workshop_release_point.py, packages/workshop/tests/test_workshop_release_fresh.py, packages/workshop/tests/test_workshop_release_driver.py, packages/workshop/tests/test_workshop_publish.py, packages/workshop/tests/test_workshop_prose.py, packages/workshop/tests/test_workshop_points.py, packages/workshop/tests/test_workshop_new_project.py, packages/workshop/tests/test_workshop_layering.py, packages/workshop/tests/test_workshop_groups.py, packages/workshop/tests/test_workshop_governance.py, packages/workshop/tests/test_workshop_e2e.py, packages/workshop/tests/test_workshop_dispatch.py, packages/workshop/tests/test_workshop_dev_release.py, packages/extensions/python/tests/test_release_driver.py, packages/extensions/nanobind/tests/test_extensions_nanobind.py, packages/extensions/docs/tests/test_task_links.py, packages/extensions/conan/tests/test_cross_kind.py ran.
727 statements
643 run
84 missing
0 excluded
36 partial
?
Keys r m x p show or hide the lines of a kindj k the next or previous highlighted chunk0 the top of the page1 the first highlighted chunk[ ] the previous or next fileu the index? show or hide this help
1 """``workflow.release``: the release train's driver on the engine.
3 One release shape for a set of N >= 1 packages: derive each member's
4 version from its commits and its entry through the release notes'
5 provider, bump floors within the set only, stamp, commit per member in
6 dependency order, and hand the branch to the shared engine. The branch
7 decides the act: main-family (``main`` and the engine's ``workflow/``
8 namespace) runs the real train, any other branch is the dev act, a wheel
9 straight from the branch. ``--local`` is everything that stays on this
10 machine: derive, build, validate, report, then roll the stamps back like
11 a failed prepare, leaving ``dist/`` and the report.
14 from __future__ import annotations 12 ctx
16 import contextlib 12 ctx
18 from collections . abc import Callable , Sequence 12 ctx
19 from dataclasses import dataclass 12 ctx
20 from functools import partial 12 ctx
21 from pathlib import Path 12 ctx
22 from typing import Annotated 12 ctx
24 import livery . footman as footman 12 ctx
25 from livery import git 12 ctx
26 from livery . footman import doc , fail 12 ctx
27 from livery . forge import ForgeError , Repository , Run 12 ctx
28 from livery . workshop import _lifecycle 12 ctx
29 from livery . workshop . _graph import order_topologically 12 ctx
30 from livery . workshop . _packages import Package , discover_packages , receipt_member 12 ctx
31 from livery . workshop . _release import prepare_release 12 ctx
32 from livery . workshop . _verdict import ( 12 ctx
39 from livery . workshop . _versions import derive_version , release_pathspecs 12 ctx
40 from livery . workshop . _workflow_engine import Submission , run_workflow 12 ctx
41 from livery . workshop . _workflow_state import WorkflowKind 12 ctx
42 from livery . workshop . _workflow_tasks import workflow 12 ctx
45 def _moved_paths ( root : Path , span : str , pathspecs : tuple [ str , . . . ] ) - > tuple [ str , . . . ] : 12 ctx
46 """Commit subjects in *span* touching *pathspecs*, honoring ``:(exclude)``."""
47 if not any ( spec . startswith ( " :(exclude) " ) for spec in pathspecs ) : 47 ↛ 49line 47 didn't jump to line 49 because the condition on line 47 was always true 4 ctx
48 return git . log_paths ( root , span , pathspecs ) 4 ctx
49 out = git . run ( root , " log " , " --format= %s " , span , " -- " , * pathspecs )
50 return tuple ( line for line in out . splitlines ( ) if line )
53 #: The base gate's patience and cadence.
54 BASE_TIMEOUT = 30 * 60 12 ctx
56 #: A tip with zero reported contexts this long gets one nudge: run
57 #: creation itself failed, and patience cannot fix that.
58 SILENT_NUDGE_AFTER = 3 * 60 12 ctx
61 @dataclass ( frozen = True ) 12 ctx
62 class MemberPlan : 12 ctx
63 """One member's derived release: the package and its next version."""
65 package : Package 12 ctx
69 #: The longest the members' joined directories may run in a release's
70 #: name. The name is a branch, and a checkout keeps a branch as a file
71 #: under ``.git/refs/remotes/origin/``: past Windows' path limit there,
72 #: a CI checkout fails before anything runs.
76 def release_name ( members : tuple [ str , . . . ] ) - > str : 12 ctx
77 """The workflow name a set earns: its directories, sorted and ``+``-joined.
79 A set whose joined directories run past `NAME_LIMIT` is named by
80 its size and a digest of them instead, so the branch stays short
81 and the same set always earns the same name.
83 joined = " + " . join ( sorted ( members ) ) 13 ctx
84 if len ( joined ) < = NAME_LIMIT : 13 ctx
85 return f " release/ { joined } " 13 ctx
88 digest = hashlib . sha256 ( joined . encode ( " utf-8 " ) ) . hexdigest ( ) [ : 12 ] 1 ctx
89 return f " release/ { len ( members ) } -packages- { digest } " 1 ctx
92 def resolve_set ( root : Path , paths : tuple [ str , . . . ] ) - > tuple [ Package , . . . ] : 12 ctx
93 """The named packages, in dependency order; every name must exist."""
94 packages = { p . path : p for p in discover_packages ( root ) } 27 ctx
95 chosen : list [ Package ] = [ ] 27 ctx
96 for path in paths : 27 ctx
97 package = packages . get ( path ) or packages . get ( f " packages/ { path } " ) 27 ctx
98 if package is None : 27 ctx
99 known = " , " . join ( sorted ( packages ) ) 1 ctx
100 fail ( f " { path } is not a workspace package; members: { known } " ) 1 ctx
101 chosen . append ( package ) 27 ctx
102 return order_topologically ( tuple ( chosen ) ) 27 ctx
105 def derive_plans ( root : Path , members : tuple [ Package , . . . ] ) - > tuple [ MemberPlan , . . . ] : 12 ctx
106 """Each member's next version, every member refused when unchanged.
108 Runs before the branch is cut, from read-only state: a refusal
109 here has nothing to undo. A member whose bump equals its newest
110 released tag has nothing unreleased, and minting a number the
111 index already has is refused with the options. The tag is the
112 judge, never the stamped version: a stamp can land without its
113 release cutting, and judging by it would strand that release
114 (the same rule livery.workshop._release.prepare_release keeps).
116 from livery . workshop . _release import _last_released 16 ctx
118 plans : list [ MemberPlan ] = [ ] 16 ctx
119 unchanged : list [ str ] = [ ] 16 ctx
120 for package in members : 16 ctx
121 released = _last_released ( root , package ) 16 ctx
122 derived = derive_version ( root , package , released = released ) 16 ctx
123 if not derived or derived == released : 16 ctx
124 unchanged . append ( package . member ) 2 ctx
126 plans . append ( MemberPlan ( package = package , version = derived ) ) 16 ctx
128 names = " , " . join ( unchanged ) 2 ctx
130 f " nothing unreleased touches: { names } . Options: drop them from "
131 " the set (release the rest now); or, if a hollow re-release is "
132 " truly meant, stamp a version explicitly with "
133 f " ` { footman . prog ( ) } release.prepare <path> <version>`. "
135 return tuple ( plans ) 15 ctx
138 def _write_manifest ( 12 ctx
139 root : Path , plans : tuple [ MemberPlan , . . . ] , * , mined_at : str
141 """Write the release set's record for the squash's discovery.
143 The publish wave and the title check read it at the ref, so a
144 recovery re-prepare whose stamps already sit on the base still
145 names every member; see [livery.workshop._publish.MANIFEST][].
146 The record carries *mined_at*, which differs for every prepare,
147 so every release squash touches the file: the dispatch finds the
148 squash as the last commit touching it, and a prepare that takes
149 over an abandoned squash at the same versions still has a commit.
153 from livery . workshop . _publish import MANIFEST 9 ctx
157 " mined-at " : mined_at ,
160 " dir " : plan . package . member ,
161 " name " : plan . package . name ,
162 " version " : plan . version ,
167 ( root / MANIFEST ) . write_text ( json . dumps ( payload , indent = 1 ) + " \n " , encoding = " utf-8 " ) 9 ctx
170 def member_pairs_at ( root : Path , ref : str ) - > list [ tuple [ str , str ] ] | None : 12 ctx
171 """(distribution, version) for each member in the member list at *ref*.
173 Each name is read from the member's contract as committed at
174 *ref*, so the answer describes that commit alone. None when *ref*
175 carries no readable list.
179 from livery . workshop . _publish import MANIFEST , read_manifest 4 ctx
181 recorded = read_manifest ( git . file_at ( root , ref , MANIFEST ) ) 4 ctx
182 if recorded is None : 4 ctx
184 pairs : list [ tuple [ str , str ] ] = [ ] 4 ctx
185 for directory , version in recorded : 4 ctx
187 contract = tomllib . loads ( 4 ctx
188 git . file_at ( root , ref , f " packages/ { directory } /workshop.toml " )
190 name = str ( contract . get ( " name " ) or directory ) 4 ctx
191 except tomllib . TOMLDecodeError :
193 pairs . append ( ( name , version ) ) 4 ctx
197 def bump_set_floors ( root : Path , plans : tuple [ MemberPlan , . . . ] ) - > list [ str ] : 12 ctx
198 """Raise floors between co-released members through the stamp phase; the files.
200 Within the set only (contract: a solo release never moves a
201 floor): each member's stamp phase runs at the version it declares
202 now, with every other member's version as its floors, so the
203 version stays for `prepare_release` to stamp. Each step raises the
204 floors in its own manifests, and the base those of the member's
205 ``[[depends]]`` edges, as `livery.workshop._lifecycle.stamp` says.
206 The files are the ones the phase reported, relative to *root*.
208 if len ( plans ) < 2 : 29 ctx
210 changed : list [ str ] = [ ] 12 ctx
211 for plan in plans : 12 ctx
212 package = plan . package 12 ctx
214 other . package . path : other . version
216 if other . package . path != package . path
218 current = _lifecycle . current_version ( package ) 12 ctx
219 stamped = _lifecycle . stamp ( package , root , current , floors = floors ) 12 ctx
221 ( package . directory / name ) . relative_to ( root ) . as_posix ( ) for name in stamped
226 def rollback_prepare ( 12 ctx
227 root : Path , members : tuple [ Package , . . . ] , reported : Sequence [ str ] = ( )
229 """Restore exactly the files prepare writes; never raises.
231 The error being unwound is the one worth seeing, so this raises
232 nothing of its own: each member's changelog, contract and version
233 files return to HEAD, and so do the files the stamp phase
234 *reported* raising floors in (relative to *root*), the set's
235 manifest and the workspace lock the stamp refreshed. One of these
236 files on disk that HEAD lacks is one prepare created, as a first
237 release's changelog and manifest are, and it is removed, so the
238 switch back to the base does not carry it along. Each restore reads
239 HEAD, never the index: a commit that failed (a signing agent that
240 refused) has already staged every change, and a restore from the
241 index would keep them. Each path the rollback could not put back is
242 printed with the reason, and the other paths are put back all the
245 for path , reason in _put_back ( root , _prepare_paths ( root , members , reported ) ) : 13 ctx
246 print ( f " the rollback could not restore { path } : { reason } " ) 2 ctx
249 def _prepare_paths ( 12 ctx
250 root : Path , members : tuple [ Package , . . . ] , reported : Sequence [ str ] = ( )
252 """The paths prepare may write for *members*, each once, from *root*.
254 The files the stamp phase *reported* raising floors in, then each
255 member's changelog, its contract and the files its set's stamp
256 writes a version into, then the workspace lock and the set's
257 manifest, with forward slashes. The rollback puts back exactly
258 these, and the local act refuses while one of them has changes of
259 its own, so the two read the same list.
261 from livery . workshop . _contract import CONTRACT 16 ctx
262 from livery . workshop . _publish import MANIFEST 16 ctx
264 paths = [ Path ( name ) . as_posix ( ) for name in reported ] 16 ctx
265 for package in members : 16 ctx
266 base = package . directory . relative_to ( root ) 16 ctx
267 paths . extend ( ( base / name ) . as_posix ( ) for name in ( " CHANGELOG.md " , CONTRACT ) ) 16 ctx
268 # Every file the set's stamp writes a version into. A set that
269 # cannot name them restores the rest regardless.
270 with contextlib . suppress ( Exception ) : 16 ctx
272 home . relative_to ( root ) . as_posix ( )
273 for home in _lifecycle . version_files ( package )
275 paths . extend ( ( " uv.lock " , MANIFEST ) ) 16 ctx
276 return tuple ( dict . fromkeys ( paths ) ) 16 ctx
279 def _require_unchanged ( root : Path , members : tuple [ Package , . . . ] ) - > None : 12 ctx
280 """Refuse while a path prepare may write has changes of its own, naming each.
282 The rollback returns each of those paths to HEAD and deletes one
283 HEAD lacks, so an uncommitted edit there, or a file a person made
284 there by hand, would be lost. A change anywhere else in the tree
288 Failed: naming each such path, modified, staged, deleted or
289 untracked, and saying to commit or stash it first.
296 " --untracked-files=all " ,
298 * _prepare_paths ( root , members ) ,
300 fields = out . split ( " \0 " ) 8 ctx
301 changed : list [ str ] = [ ] 8 ctx
303 while index < len ( fields ) : 8 ctx
304 record = fields [ index ] 8 ctx
306 if len ( record ) < 4 : 8 ctx
308 changed . append ( record [ 3 : ] ) 3 ctx
309 if record [ 0 ] in " RC " : 309 ↛ 311line 309 didn't jump to line 311 because the condition on line 309 was never true 3 ctx
310 # A rename or a copy names the path it came from next.
313 listed = " " . join ( f " \n { path } " for path in sorted ( set ( changed ) ) ) 3 ctx
315 " the local act writes these files and then restores them from "
316 f " HEAD, so the changes they have now would be lost: { listed } \n "
317 " Commit or stash them first, then run it again. "
321 def _put_back ( root : Path , paths : tuple [ str , . . . ] ) - > list [ tuple [ str , str ] ] : 12 ctx
322 """Return each of *paths* to HEAD; each path that failed, with the reason.
324 A path HEAD has is checked out from HEAD. A path HEAD lacks that
325 is on disk is taken out of the index and deleted. A path in
326 neither is left alone. The paths HEAD has are checked out in one
327 call, and only when git refuses that call is each checked out
328 alone: git refuses the whole call for one bad path, so the one
329 path git refuses never stops the rest.
331 tracked : list [ str ] = [ ] 13 ctx
332 failed : list [ tuple [ str , str ] ] = [ ] 13 ctx
333 for path in paths : 13 ctx
335 if git . tracks ( root , f " HEAD: { path } " ) : 13 ctx
336 tracked . append ( path ) 13 ctx
337 elif ( root / path ) . is_file ( ) : 13 ctx
338 git . unstage ( root , path ) 3 ctx
339 ( root / path ) . unlink ( ) 2 ctx
340 except ( git . GitError , OSError ) as error : 1 ctx
341 failed . append ( ( path , str ( error ) ) ) 1 ctx
342 if tracked and git . restore ( root , * tracked ) : 13 ctx
343 for path in tracked : 1 ctx
344 refused = git . restore ( root , path ) 1 ctx
346 failed . append ( ( path , refused ) ) 1 ctx
350 def verify_set ( root : Path , plans : tuple [ MemberPlan , . . . ] ) - > None : 12 ctx
351 """Run the publish job's own checks over the stamped set, before any leg.
353 The wave refuses a member whose version homes disagree with its tag,
354 whose release notes are unsound, or whose floor names an unreleased
355 version, and it refuses only after the release has merged. The same
356 checks on the stamped tree refuse before a release pull request
357 exists. The set's own tags count as released, as the wave counts them.
360 Failed: as the publish job's check refuses, naming the member and
363 from livery . workshop . _release import verify_release 14 ctx
365 coreleased = frozenset ( f " { plan . package . path } /v { plan . version } " for plan in plans ) 14 ctx
366 for plan in plans : 14 ctx
367 verify_release ( 14 ctx
368 root , f " { plan . package . path } /v { plan . version } " , coreleased = coreleased
372 def _wheel_dists ( plans : tuple [ MemberPlan , . . . ] ) - > tuple [ Path , . . . ] : 12 ctx
373 """The find-links dirs: each member's ``dist/`` that exists, in set order.
375 Read after the set's builds. A build that writes nothing there, a
376 conan member's, leaves no directory to name, and a find-links path
377 that does not exist fails the sibling legs outright.
379 dists = ( plan . package . directory / " dist " for plan in plans ) 14 ctx
380 return tuple ( dist for dist in dists if dist . is_dir ( ) ) 14 ctx
383 #: The key of `[release]` listing the resolutions a release tests at.
386 #: The resolutions a release may test a member at, in the order the legs
387 #: run: the floor first, since a floor lying about compatibility fails
388 #: before anything else is spent, then the newest, then the lock's.
389 RESOLUTIONS = ( " floor " , " latest " , " head " ) 12 ctx
391 #: The resolutions a release tests at when no contract lists any.
392 DEFAULT_RESOLUTIONS = ( " floor " , " latest " ) 12 ctx
395 def proved_resolutions ( root : Path , package : Package ) - > tuple [ tuple [ str , . . . ] , str ] : 12 ctx
396 """The resolutions *package*'s release tests at, and the file that listed them.
398 The package's own `[release] prove` wins; the workspace's is the
399 default; without either the release tests at
400 [livery.workshop._release_driver.DEFAULT_RESOLUTIONS][], and the
401 file is empty. The contract's judge refuses a word other than the
402 three and a word listed twice, so the list holds each at most
403 once, in the order the legs run.
405 from livery . workshop . _contract import load_contract 5 ctx
407 for contract in ( package . directory / " workshop.toml " , root / " workshop.toml " ) : 5 ctx
408 if not contract . is_file ( ) : 408 ↛ 409line 408 didn't jump to line 409 because the condition on line 408 was never true 5 ctx
410 release = load_contract ( contract ) . get ( " release " ) or { } 5 ctx
411 if PROVE in release : 5 ctx
412 listed = { str ( word ) for word in release [ PROVE ] } 1 ctx
413 where = contract . relative_to ( root ) . as_posix ( ) 1 ctx
414 return tuple ( word for word in RESOLUTIONS if word in listed ) , where 1 ctx
415 return DEFAULT_RESOLUTIONS , " " 5 ctx
418 def validate_member ( 12 ctx
419 root : Path , plan : MemberPlan , release_dirs : tuple [ Path , . . . ]
421 """Run the member's test phase isolated once per resolution it proves; report each.
423 One leg per resolution
424 ([livery.workshop._release_driver.proved_resolutions][]), in the
425 order of [livery.workshop._release_driver.RESOLUTIONS][], so the
426 floor leg runs before the latest leg; a list from a contract is
427 named with its file. The report names what each leg resolved per
428 co-member and sibling: every workspace member but the one under
429 test. The caller builds every set member's wheel first: the legs'
430 find-links name each sibling's ``dist/``, so a later member's
431 wheel must exist before an earlier member's floor leg resolves.
433 A member whose extensions add no isolated test, as a conan
434 package's do, has no venv to isolate: its own gate already built
435 and ran ctest, so the legs skip saying why.
437 if not _lifecycle . has_isolated_test ( plan . package ) : 6 ctx
439 f " { plan . package . name } : isolated legs skip (its extensions add no "
440 " isolated test, since it publishes no wheel; its own gate builds "
444 legs , where = proved_resolutions ( root , plan . package ) 5 ctx
446 listed = " , " . join ( legs ) or " nothing, so no leg runs " 1 ctx
447 print ( f " { plan . package . name } : [release] { PROVE } in { where } lists { listed } " ) 1 ctx
448 members = { _normalised ( package . name ) for package in discover_packages ( root ) } 5 ctx
449 own = _normalised ( plan . package . name ) 5 ctx
450 for leg in legs : 5 ctx
451 resolved = _lifecycle . isolated_test ( 5 ctx
452 plan . package , root , resolution = leg , release_dirs = release_dirs
456 for name , version in sorted ( resolved . items ( ) )
457 if _normalised ( name ) in members and _normalised ( name ) != own
459 listed = " , " . join ( f " { n } { v } " for n , v in siblings . items ( ) ) or " no siblings " 5 ctx
460 print ( f " { plan . package . name } { leg } leg: { listed } " ) 5 ctx
463 def _normalised ( name : str ) - > str : 12 ctx
464 """A distribution's name as an index compares it: lower case, hyphens."""
465 return name . lower ( ) . replace ( " _ " , " - " ) . replace ( " . " , " - " ) 5 ctx
468 def _base_tree_verified ( root : Path , base : str ) - > bool : 12 ctx
469 """Whether the proved record already vouches for *base*'s tip on every check leg."""
470 from livery . workshop import _proved 14 ctx
473 git . fetch ( root ) 14 ctx
474 proved , why = _proved . base_proved ( root , base ) 14 ctx
475 except Exception as error :
477 f " { base } : its tip cannot be read for the proved record: { error } ; "
478 " waiting for the tip ' s own run "
481 if why : 481 ↛ 482line 481 didn't jump to line 482 because the condition on line 481 was never true 14 ctx
482 print ( f " { base } : { why } ; waiting for the tip ' s own run " )
485 print ( f " { base } verified: proved green on every leg; the release starts now " ) 1 ctx
490 def require_verified_base ( 12 ctx
496 timeout : float = BASE_TIMEOUT ,
497 poll : float = BASE_POLL ,
499 """Wait for the base's own push CI to be green; stop on red or skip.
501 Branch protection only ever judged PR heads, and a release
502 publishes the base's tree, so the base's push run is the only
503 vouching there is. Green, not merely not-red; red is a verdict
504 waiting cannot improve; a skip-ci tip will never get a run; an
505 unreachable forge fails open, the engine's UNKNOWN story says it
508 Zero reported contexts after minutes means run creation itself
509 failed, and every forge can do it: Gitea's actions queue could
510 wedge before 1.27.3, GitHub silently drops a push's workflow-run
511 creation under load, and GitLab can never mint the pipeline (a
512 job-queue backlog, or workflow rules evaluating to nothing). The
514 reports all three identically, so detection is uniform; the safe
515 remedy is not (whether a tool may push to the base varies per
516 forge and protection), so the silent tip gets a printed teaching
517 naming the fresh-push-event remedy, never an automatic push. The
518 timeout tells the two conditions apart: a run that reported and
519 hung sends the reader to the runners, a tip that never got a run
523 print ( " base verification skipped (--force-unverified-base) " ) 1 ctx
525 if _base_tree_verified ( root , base ) : 14 ctx
527 announced = False 14 ctx
528 silent_since : float | None = None 14 ctx
530 ever_reported = False 14 ctx
532 def read ( ) - > bool | Pending : 14 ctx
533 nonlocal announced , silent_since , nudged , ever_reported
535 git . fetch ( root ) 14 ctx
536 sha = git . remote_head ( root , base ) 14 ctx
537 status = repo . checks . status ( sha ) if sha else None 14 ctx
538 except ForgeError : 1 ctx
540 except Exception as error : 1 ctx
541 # The base gate fails open: a tree nobody can vouch for
542 # releases, and the reason is said rather than swallowed.
543 print ( f " { base } ' s CI could not be read ( { error } ); releasing unverified " ) 1 ctx
545 if status is None or status . state == " success " : 13 ctx
547 if status . state == " failure " : 4 ctx
549 f " { base } ' s own CI is red, and a release publishes that tree. "
550 f " Fix { base } first (` { footman . prog ( ) } ci.logs` on it names "
552 " release with --force-unverified-base if you accept an "
555 if " [skip ci] " in git . commit_message ( root , sha ) : 555 ↛ 556line 555 didn't jump to line 556 because the condition on line 555 was never true 2 ctx
557 f " { base } ' s tip carries a skip-ci marker, so CI will never "
558 " report on it. Push a commit CI can run, or "
559 " --force-unverified-base to accept it unverified. "
561 now = time . monotonic ( ) 2 ctx
562 if status . contexts : 2 ctx
563 ever_reported = True 1 ctx
564 silent_since = None 1 ctx
565 elif silent_since is None : 1 ctx
566 silent_since = now 1 ctx
567 elif not nudged and now - silent_since > = SILENT_NUDGE_AFTER : 567 ↛ 568line 567 didn't jump to line 568 because the condition on line 567 was never true 1 ctx
570 f " { base } ' s tip has had no CI run for "
571 f " { SILENT_NUDGE_AFTER / / 60 } min; a fresh push event may be "
572 " needed (an empty commit mints one). "
574 if not announced : 2 ctx
575 announced = True 2 ctx
577 f " waiting for { base } ' s own CI before releasing (up to "
578 f " { BASE_TIMEOUT / / 60 } min) "
580 return Pending ( ) 2 ctx
586 subject = f " { base } ' s own CI " ,
591 except ForgeUnreachable as exc : 4 ctx
593 print ( f " releasing unverified: { base } ' s CI could not be read " )
594 except FollowTimedOut : 4 ctx
595 # Not started and hanging are different problems with
596 # different remedies, so the timeout names the one that
598 if ever_reported : 2 ctx
600 f " { base } reported a run but never went green within "
601 f " { timeout / 60 : .0f } minutes. Check the runners "
602 f " (` { footman . prog ( ) } status --watch` on a branch follows "
604 " --force-unverified-base. "
607 f " { base } ' s tip never got a CI run in { timeout / 60 : .0f } "
608 " minutes: run creation itself failed, and waiting cannot "
609 " fix that. A fresh push event mints a run (an empty "
610 " commit, or its PR merged), or --force-unverified-base. "
614 class ReleaseDriver : 12 ctx
615 """The release kind's driver for the shared engine."""
617 kind = WorkflowKind . RELEASE 12 ctx
623 members : tuple [ Package , . . . ] ,
626 force_unverified_base : bool = False ,
627 wave_timeout : float = 1800.0 ,
629 self . _root = root 12 ctx
630 self . _repo = repo 12 ctx
631 self . _members = members 12 ctx
632 self . members = tuple ( p . member for p in members ) 12 ctx
633 self . name = release_name ( self . members ) 12 ctx
634 self . armed = armed 12 ctx
635 self . _force = force_unverified_base 12 ctx
636 self . _wave_timeout = wave_timeout 12 ctx
637 # An armed release follows its pull request for as long as it
638 # would wait for the wave; the engine's own tests pass zero.
639 self . watch = wave_timeout 12 ctx
640 # Set by `discard`: the next prepare starts from the base, and
641 # the given-up branch's manifest says which members' legs
643 self . _fresh = False 12 ctx
644 self . _previous : tuple [ str , tuple [ tuple [ str , str ] , . . . ] ] | None = None 12 ctx
647 def branch ( self ) - > str : 12 ctx
648 return f " workflow/ { self . name } " 11 ctx
651 def base ( self ) - > str : 12 ctx
654 def discard ( self ) - > None : 12 ctx
655 """Give up the prepared branch: the base moved in the set's paths.
657 The next prepare derives the set again from the base and
658 force-pushes the branch, so the open pull request carries the
659 new stamps, entries and ``Mined-At``. The given-up branch's
660 manifest is kept: a member whose directory the base did not
661 move since that prepare, at the same versions for the whole
662 set, keeps its legs' verdict instead of running them again.
666 from livery . workshop . _publish import MANIFEST , read_manifest 2 ctx
668 root = self . _root 2 ctx
670 text = git . file_at ( root , f " origin/ { self . branch } " , MANIFEST ) 2 ctx
671 pairs = read_manifest ( text ) if text else None 2 ctx
673 if pairs : 673 ↛ 676line 673 didn't jump to line 676 because the condition on line 673 was always true 2 ctx
674 with contextlib . suppress ( ValueError , TypeError , AttributeError ) : 2 ctx
675 mined = str ( json . loads ( text ) . get ( " mined-at " ) or " " ) 2 ctx
676 self . _previous = ( mined , pairs ) if pairs and mined else None 2 ctx
677 if git . current_branch ( root ) == self . branch : 677 ↛ 679line 677 didn't jump to line 679 because the condition on line 677 was always true 2 ctx
678 git . switch ( root , self . base ) 2 ctx
679 if git . local_branch_exists ( root , self . branch ) : 679 ↛ 681line 679 didn't jump to line 681 because the condition on line 679 was always true 2 ctx
680 git . delete_branch ( root , self . branch ) 2 ctx
681 self . _fresh = True 2 ctx
683 def legs_kept ( self , plans : tuple [ MemberPlan , . . . ] , mined_at : str ) - > set [ str ] : 12 ctx
684 """The members whose legs from the discarded prepare still hold.
686 Only when the whole set keeps its versions (a co-member's new
687 version moves the floors every other member is tested at), and
688 then each member the base did not touch between the two mining
691 if self . _previous is None : 12 ctx
693 previous_mined , previous_pairs = self . _previous 2 ctx
694 now = tuple ( ( plan . package . member , plan . version ) for plan in plans ) 2 ctx
695 if tuple ( sorted ( previous_pairs ) ) != tuple ( sorted ( now ) ) : 2 ctx
697 kept : set [ str ] = set ( ) 2 ctx
698 for plan in plans : 2 ctx
700 moved = _moved_paths ( 2 ctx
702 f " { previous_mined } .. { mined_at } " ,
703 release_pathspecs ( plan . package ) ,
706 continue # an unreadable span proves nothing: run the legs
708 kept . add ( plan . package . member ) 1 ctx
711 def prepare ( self ) - > Submission | None : 12 ctx
712 """Derive, stamp, and commit the set; recover an existing branch.
714 A branch already alive locally or on the remote is recovery:
715 nothing is rebuilt, the engine re-submits what the branch
716 holds, and titles come from the ref, never the working tree.
718 root = self . _root 9 ctx
719 if not self . _fresh and ( 9 ctx
720 git . local_branch_exists ( root , self . branch )
721 or self . _repo . branch_exists ( self . branch )
723 if git . current_branch ( root ) != self . branch : 723 ↛ 724line 723 didn't jump to line 724 because the condition on line 723 was never true 3 ctx
724 if not git . local_branch_exists ( root , self . branch ) :
727 root , " checkout " , " -b " , self . branch , f " origin/ { self . branch } "
730 git . switch ( root , self . branch )
731 print ( f " recovering the prepared { self . name } from its branch " ) 3 ctx
732 self . _require_fresh_base ( ) 3 ctx
733 return self . _submission_from_ref ( ) 2 ctx
735 require_verified_base ( self . _repo , root , self . base , force = self . _force ) 9 ctx
736 plans = derive_plans ( self . _root , self . _members ) 9 ctx
737 mined_at = git . head_sha ( root ) 9 ctx
738 kept = self . legs_kept ( plans , mined_at ) 9 ctx
739 git . create_branch ( root , self . branch ) 9 ctx
740 prepared = False 9 ctx
741 floor_changes : list [ str ] = [ ] 9 ctx
743 floor_changes = bump_set_floors ( self . _root , plans ) 9 ctx
744 if floor_changes : 9 ctx
745 print ( f " floors raised within the set: { ' , ' . join ( floor_changes ) } " ) 5 ctx
746 _write_manifest ( self . _root , plans , mined_at = mined_at ) 9 ctx
747 for plan in plans : 9 ctx
748 prepare_release ( self . _root , plan . package . path , plan . version ) 9 ctx
749 _lifecycle . build_release ( plan . package , self . _root ) 9 ctx
750 if git . is_clean ( root ) : 750 ↛ 755line 750 didn't jump to line 755 because the condition on line 750 was never true 9 ctx
751 # Already stamped: a release squash-merged but never
752 # published leaves main carrying exactly these
753 # entries and versions, and re-preparing is the
754 # recovery. A clean tree is that state, not a fault.
756 f " { plan . package . name } v { plan . version } : "
757 " already stamped on the base; nothing to commit "
761 root , f " chore(release): { plan . package . name } v { plan . version } "
763 if not git . is_clean ( root ) : 763 ↛ 768line 763 didn't jump to line 768 because the condition on line 763 was never true 9 ctx
764 # Only the manifest changed: every member was already
765 # stamped on the base (a merged release whose publish
766 # failed), and the manifest alone is what lets the
767 # squash's discovery still name the whole set.
768 git . commit_all ( root , " chore(release): the set manifest " )
769 verify_set ( self . _root , plans ) 9 ctx
770 # Every member's wheel exists before any leg runs; a
771 # failed leg still tears the whole branch down, commits
772 # included, so nothing unvalidated survives.
773 release_dirs = _wheel_dists ( plans ) 9 ctx
774 for plan in plans : 9 ctx
775 if plan . package . member in kept : 775 ↛ 776line 775 didn't jump to line 776 because the condition on line 775 was never true 9 ctx
777 f " { plan . package . name } v { plan . version } : legs kept from the "
778 " discarded prepare; the base did not move its directory "
781 validate_member ( self . _root , plan , release_dirs ) 9 ctx
784 if not prepared : 9 ctx
785 rollback_prepare ( self . _root , self . _members , floor_changes ) 1 ctx
786 git . switch ( root , self . base ) 1 ctx
787 git . delete_branch ( root , self . branch ) 1 ctx
788 title = release_title ( [ ( plan . package . name , plan . version ) for plan in plans ] ) 8 ctx
790 " ## Release summary \n "
791 + " \n " . join ( f " - ** { plan . package . name } ** v { plan . version } " for plan in plans )
792 + f " \n \n Mined-At: { mined_at } "
794 return Submission ( title = title , body = body ) 8 ctx
796 def _require_fresh_base ( self ) - > None : 12 ctx
797 """Refuse a prepared branch whose base moved under it.
799 hse merges the default branch into a stale release branch and
800 re-verifies; livery's entries carry a mining point instead,
801 and commits merged in beneath it would ship under-documented,
802 so the stale branch is refused outright: abandon and re-run,
803 and the fresh prepare mines everything. Deviation from hse
804 ruled 2026-09-04 with issue #161.
806 root = self . _root 3 ctx
808 base_sha = git . run ( root , " rev-parse " , f " origin/ { self . base } " ) . strip ( ) 3 ctx
809 if git . is_ancestor ( root , base_sha , " HEAD " ) : 3 ctx
812 f " { self . base } has moved past this prepared release: commits "
813 " it gained are not mined into the branch ' s entries, and "
814 " releasing them under-documented is worse than re-preparing. "
815 f " \n Run ` { footman . prog ( ) } abandon` on the branch, then "
816 f " ` { footman . prog ( ) } workflow.release` again. "
819 def _submission_from_ref ( self ) - > Submission : 12 ctx
820 """The title and body the branch's member list states.
822 Recovery reads the branch's committed member list, never the
823 working tree and never commit subjects: a checkout standing
824 elsewhere holds a different tree, and a rider commit is not
825 part of what was prepared, so the rebuilt title stays
826 consistent with the content the squash will carry.
828 root = self . _root 2 ctx
829 mined_at = git . run ( root , " merge-base " , " HEAD " , f " origin/ { self . base } " ) . strip ( ) 2 ctx
830 pairs = member_pairs_at ( root , " HEAD " ) or [ ] 2 ctx
832 " ## Release summary \n "
833 + " \n " . join ( f " - ** { name } ** v { version } " for name , version in pairs )
834 + f " \n \n Mined-At: { mined_at } "
836 return Submission ( title = release_title ( pairs ) , body = body ) 2 ctx
838 def on_merged ( self ) - > None : 12 ctx
839 """The merge point dispatches the wave; follow it to its verdict.
841 The wave's run is awaited by its id, then followed the way
842 ``ci.status --point=release --wait`` follows it, so the act
843 ends with the wave's own verdict and exit; the receipt tags
844 say when each member is done. A wave timeout of zero reports
845 the merge and names the dispatch verb as the confirmation
846 instead of waiting: the engine's own tests run against a
847 forge with no merge point.
849 if self . _wave_timeout < = 0 : 3 ctx
851 " merged; the merge point dispatches the wave, confirm it with "
852 f " ` { footman . prog ( ) } workflow.release.dispatch` "
855 transient = Transient ( interval = _WAVE_POLL ) 1 ctx
856 before = { run . id for run in _wave_runs_answered ( self . _repo , transient ) } 1 ctx
857 run_id = await_wave ( 1 ctx
860 timeout = self . _wave_timeout ,
863 if run_id is None : 863 ↛ 864line 863 didn't jump to line 864 because the condition on line 863 was never true 1 ctx
865 " merged, but no release wave appeared within "
866 f " { self . _wave_timeout : .0f } s: the merge point ' s dispatch job "
867 " runs after main ' s own verdict, so a red main or a slow "
868 " queue is the usual cause. The recovery is "
869 f " ` { footman . prog ( ) } workflow.release.dispatch` from any "
870 " checkout, which answers green once the wave is up. "
873 f " merged; the merge point dispatched the wave, run { run_id } ; the "
874 " receipt tags say when each member is done "
877 ( r for r in _wave_runs_answered ( self . _repo , transient ) if r . id == run_id ) ,
880 if run is None : 880 ↛ 881line 880 didn't jump to line 881 because the condition on line 880 was never true 1 ctx
882 from livery . workshop . _ci_tasks import follow_run 1 ctx
884 code = follow_run ( self . _repo , " release " , run , timeout = self . _wave_timeout ) 1 ctx
885 self . _trace_the_chain ( ) 1 ctx
887 raise SystemExit ( code ) 1 ctx
889 def _trace_the_chain ( self ) - > None : 12 ctx
890 """Fold everything this release caused into the command's own trace.
892 A release is two commits and one hop. The branch commit carries
893 the pull request's run, and the commit its merge made carries
894 the base's own run and the wave dispatched at it. One walk from
895 the branch holds the whole story, and a red wave's is the one
896 most worth having, so this runs before the exit code does.
898 The branch is already gone from a checkout that recovered a
899 release it did not prepare, and then the release squash on the
900 base is where the walk starts instead.
902 from livery . workshop . _traces import drop_chain 1 ctx
904 root = self . _root 1 ctx
905 at = git . sha_of ( root , self . branch ) 1 ctx
906 if not at : 906 ↛ 908line 906 didn't jump to line 908 because the condition on line 906 was always true 1 ctx
907 at , _subject = newest_release_squash ( root , self . base ) 1 ctx
908 if line := drop_chain ( self . _repo , root , commit = at ) : 1 ctx
909 print ( f " { line } " ) 1 ctx
912 #: The longest release title. GitHub's auto-merge refuses a squash
913 #: headline it judges too long, and its refusal names 80 characters.
914 TITLE_LIMIT = 80 12 ctx
917 def release_title ( pairs : Sequence [ tuple [ str , str ] ] ) - > str : 12 ctx
918 """The release pull request's title: each member with its version, or a count.
920 The title is the squash commit's headline, and arming hands it to
921 GitHub's auto-merge, which refuses a long one. A set whose title
922 would pass `TITLE_LIMIT` characters is counted instead; the pull
923 request's body and the commit's body list every member.
925 listed = " , " . join ( f " { name } v { version } " for name , version in pairs ) 10 ctx
926 title = f " chore(release): released { listed } " 10 ctx
927 if len ( title ) < = TITLE_LIMIT : 10 ctx
929 counted = " 1 package " if len ( pairs ) == 1 else f " { len ( pairs ) } packages " 1 ctx
930 return f " chore(release): released { counted } " 1 ctx
933 def runs_the_train ( branch : str ) - > bool : 12 ctx
934 """Whether `workflow.release` on *branch* is the release train, not the dev act.
936 ``main`` and the engine's reserved ``workflow/`` branches release;
937 any other branch builds a dev wheel straight from its commit.
939 return branch == " main " or branch . startswith ( " workflow/ " ) 9 ctx
942 def fresh_receipts ( root : Path ) - > None : 12 ctx
943 """Fetch origin's tags, so a derivation reads every receipt a wave cut.
945 A release wave tags its receipts on the remote, and this checkout
946 holds them only after a fetch: a derivation from stale tags names
947 versions the index already has. A checkout with no origin has only
948 its own tags to read; one that cannot reach origin derives from its
951 if not git . has_remote ( root , " origin " ) : 951 ↛ 952line 951 didn't jump to line 952 because the condition on line 951 was never true 5 ctx
954 git . fetch_tags ( root ) 5 ctx
955 except git . GitError as error : 1 ctx
957 " origin could not be fetched, so the versions come from this "
958 f " checkout ' s own tags: { error } "
962 def local_release ( root : Path , members : tuple [ Package , . . . ] ) - > None : 12 ctx
963 """Everything that stays on this machine, then the stamps roll back.
965 Derive, stamp (so the built wheels carry the would-be versions),
966 build, run the isolated legs, print the would-be release, restore
967 the tree; ``dist/`` and the report remain. Publishing consent is
968 never asked because nothing leaves the machine. The derivation
969 reads origin's receipts, fetched first, so it names the versions
970 the armed act would ([livery.workshop._release_driver.fresh_receipts][]).
971 Before any of it, the act refuses while a file it would write has
972 changes of its own, since the restore would discard them; a change
973 anywhere else in the tree is left alone.
975 _require_unchanged ( root , members ) 8 ctx
976 fresh_receipts ( root ) 5 ctx
977 plans = derive_plans ( root , members ) 5 ctx
978 print ( " act: local; nothing leaves this machine " ) 5 ctx
979 floor_changes : list [ str ] = [ ] 5 ctx
981 floor_changes = bump_set_floors ( root , plans ) 5 ctx
982 for plan in plans : 5 ctx
983 prepare_release ( root , plan . package . path , plan . version ) 5 ctx
984 _lifecycle . build_release ( plan . package , root ) 5 ctx
985 verify_set ( root , plans ) 5 ctx
986 release_dirs = _wheel_dists ( plans ) 4 ctx
987 for plan in plans : 4 ctx
988 validate_member ( root , plan , release_dirs ) 4 ctx
989 listed = " , " . join ( f " { plan . package . name } v { plan . version } " for plan in plans ) 3 ctx
990 print ( f " would release: { listed } " ) 3 ctx
991 print ( " wheels in each member ' s dist/; the tree is restored " ) 3 ctx
993 rollback_prepare ( root , members , floor_changes ) 5 ctx
996 #: The release workflow, as the forges address one for a dispatch and
997 #: name one on a run (GitHub lists the path, Gitea the file; the
998 #: basename is the comparison).
999 RELEASE_WORKFLOW = " release.yml " 12 ctx
1002 def _wave_runs ( repo : Repository ) - > tuple [ Run , . . . ] : 12 ctx
1003 """The release workflow's newest dispatched runs, newest first.
1005 Asked of the workflow's own listing, so every poll of a wave reads
1006 one page whatever else was dispatched.
1008 from livery . workshop . _ci_tasks import RECENT_RUNS 11 ctx
1012 for run in repo . checks . runs (
1013 event = " workflow_dispatch " , workflow = RELEASE_WORKFLOW , limit = RECENT_RUNS
1015 if run . workflow . rsplit ( " / " , 1 ) [ - 1 ] == RELEASE_WORKFLOW
1019 #: Seconds between the train's polls of the wave's runs.
1020 _WAVE_POLL = 5.0 12 ctx
1023 def _wave_runs_answered ( 12 ctx
1024 repo : Repository , transient : Transient , * , interval : float = _WAVE_POLL
1025 ) - > tuple [ Run , . . . ] :
1026 """The wave's runs, asked again while the forge does not answer.
1028 An unreadable poll is a retry, as ``fm ci.status --wait`` treats it:
1029 *transient* counts the run of them, and a spent budget ends the train
1030 with the forge's words and the command that follows the wave, which
1031 runs on in CI whatever happens here.
1036 lambda : _wave_runs ( repo ) ,
1037 subject = _WAVE_SUBJECT ,
1041 transient = transient ,
1043 except ForgeUnreachable as exc :
1044 fail ( exc . line . strip ( ) )
1047 def _wave_subject ( ) - > str : 12 ctx
1048 """What a spent budget names: the wave runs on, and the verb that follows it."""
1050 " the wave runs on in CI; follow it with "
1051 f " ` { footman . prog ( ) } ci.status --point=release --wait` "
1055 _WAVE_SUBJECT = _wave_subject 12 ctx
1058 def await_wave ( 12 ctx
1062 timeout : float = 1800.0 ,
1063 interval : float = _WAVE_POLL ,
1064 transient : Transient | None = None ,
1066 """The id of the newest wave run not in *before*, or ``None`` when none appears.
1068 Any state counts: a wave that already finished by the time the
1069 poll saw it is still the wave that ran, and a confirmation that
1070 demanded a live run would miss a fast forge. An unreadable poll is
1071 retried within *transient*'s budget.
1074 def new_run ( ) - > int | Pending : 2 ctx
1075 new = [ run for run in _wave_runs ( repo ) if run . id not in before ] 2 ctx
1076 return new [ 0 ] . id if new else Pending ( ) 2 ctx
1082 subject = _WAVE_SUBJECT ,
1086 transient = transient ,
1088 except ForgeUnreachable as exc : 2 ctx
1089 fail ( exc . line . strip ( ) ) 1 ctx
1090 except FollowTimedOut : 1 ctx
1094 def dispatch_flow ( 12 ctx
1101 again : bool = False ,
1102 timeout : float = 60.0 ,
1103 interval : float = 2.0 ,
1105 """Dispatch the wave for a merged, unpublished release, or say why not.
1107 Reads the manifest on ``origin/<base>`` after a fetch, whatever
1108 commit this checkout stands on, or at *at*, an older release squash
1109 a later release has moved past. A checkout behind the base would
1110 otherwise send the wave to the squash a later release took over.
1111 *workshop* names a released driver for the wave instead of the
1112 squash's own, the recovery for a wave whose workshop was the fault;
1113 empty runs the squash's. Green when there is none, or when
1114 every member's receipt tag is already on the remote: the
1115 manifest is permanent residue of the last release, so presence
1116 is not the signal, missing receipts are. A wave already in
1117 flight is reported green with its run id. A wave that already ran
1118 at the squash with the squash's own driver and ended failure is
1119 reported green too, with its run and the recoveries, and nothing
1120 is dispatched: the same wave fails the same way, and every merge
1121 would otherwise start one more copy of it. *again* dispatches it
1122 anyway, the gesture by hand once the cause is gone, and a named
1123 *workshop* is another wave. Otherwise the wave is dispatched on
1124 *base* with the commit that stamped the manifest as its ``ref``
1125 input, never this run's own sha, so an unrelated merge landing
1126 first cannot move the wave onto another tree; the dispatch is
1127 confirmed by the run id that appears, or refused with the reason.
1128 Remote state only, receipts by ``ls-remote`` and runs by the
1129 forge, so any checkout answers the same as CI.
1131 from livery . workshop . _publish import MANIFEST , read_manifest 11 ctx
1133 where = at or _base_ref ( root , base ) 11 ctx
1134 text = git . file_at ( root , where , MANIFEST ) 11 ctx
1135 recorded = read_manifest ( text ) if text else None 11 ctx
1136 if not recorded : 11 ctx
1137 return [ f " no release manifest at { where } : nothing to dispatch " ] 2 ctx
1138 cut = set ( git . remote_tags ( root ) ) 10 ctx
1139 receipts = [ f " packages/ { directory } /v { version } " for directory , version in recorded ] 10 ctx
1140 missing = [ tag for tag in receipts if tag not in cut ] 10 ctx
1141 if not missing : 10 ctx
1142 return [ f " every receipt is cut ( { ' , ' . join ( receipts ) } ): nothing to dispatch " ] 1 ctx
1143 live = [ run for run in _wave_runs ( repo ) if run . status != " completed " ] 9 ctx
1146 f " the wave is already in flight: run { live [ 0 ] . id } ; "
1147 f " uncut so far: { ' , ' . join ( missing ) } "
1149 stamping = at or git . last_commit_touching ( root , MANIFEST , ref = where ) 8 ctx
1150 if not stamping : 1150 ↛ 1151line 1150 didn't jump to line 1151 because the condition on line 1150 was never true 8 ctx
1152 f " { MANIFEST } is at { where } but no commit touches it: nothing to dispatch "
1154 _require_release_squash ( root , stamping , base ) 8 ctx
1155 if not workshop and not again : 8 ctx
1156 failed = _failed_wave_at ( root , repo , stamping ) 7 ctx
1157 if failed is not None : 7 ctx
1158 prog = footman . prog ( ) 2 ctx
1160 f " a wave already ran at { stamping [ : 12 ] } and ended failure: run "
1161 f " { failed . id } ( { repo . web_url ( ) } /actions/runs/ { failed . id } ); the same "
1162 f " wave fails the same way, so none is dispatched. Uncut: "
1163 f " { ' , ' . join ( missing ) } " ,
1164 f " to run it again once the cause is gone: ` { prog } "
1165 " workflow.release.dispatch --again`; with a released driver: "
1166 f " `--workshop=<version>`; to give the release up: ` { prog } "
1167 " workflow.release --abandon` " ,
1169 seen = { run . id for run in _wave_runs ( repo ) } 8 ctx
1170 inputs = { " ref " : stamping } 8 ctx
1172 inputs [ " workshop " ] = workshop 2 ctx
1174 repo . checks . dispatch ( RELEASE_WORKFLOW , ref = base , inputs = inputs ) 8 ctx
1175 except ForgeError as error : 1 ctx
1176 # Red, never a printed line: the merge point's verdict is the
1177 # exit code, and a wave that did not start leaves the release
1178 # uncut until someone reads the log.
1180 f " the forge refused the dispatch: { error } ; uncut: "
1181 f " { ' , ' . join ( missing ) } . Nothing started; on GitHub the job "
1182 " needs the actions: write grant, and the recovery by hand "
1183 f " is ` { footman . prog ( ) } workflow.release.dispatch` "
1187 deadline = time . monotonic ( ) + timeout 7 ctx
1188 while time . monotonic ( ) < deadline : 7 ctx
1189 new = [ run for run in _wave_runs ( repo ) if run . id not in seen ] 7 ctx
1191 driver = f " driven by { workshop } " if workshop else " " 6 ctx
1193 f " dispatched the wave at { stamping [ : 12 ] } { driver } : run { new [ 0 ] . id } ; "
1194 f " uncut: { ' , ' . join ( missing ) } "
1196 time . sleep ( interval ) 1 ctx
1198 " the dispatch was accepted but no wave run appeared within "
1199 f " { timeout : .0f } s; re-run ` { footman . prog ( ) } workflow.release.dispatch`, "
1200 " which reports a wave that has since appeared "
1204 def _failed_wave_at ( root : Path , repo : Repository , squash : str ) - > Run | None : 12 ctx
1205 """The newest dispatched wave about *squash* that ended failure, or None.
1207 The runs about the squash are the forge's listing for it and the
1208 runs that recorded themselves as its (`runs_about`), since a wave
1209 the forge filed under a tip that moved on is still the squash's.
1210 A cancelled wave, or one that never ran, is not a failure here:
1211 the next merge dispatches again for those, as for a died merge
1214 from livery . workshop . _traces import runs_about 7 ctx
1216 caused , _lines = runs_about ( root , repo , squash ) 7 ctx
1217 ids = { item . run_id for item in caused if item . event == " workflow_dispatch " } 7 ctx
1220 for run in _wave_runs ( repo )
1221 if str ( run . id ) in ids
1222 and run . status == " completed "
1223 and run . conclusion == " failure "
1225 return max ( failed , key = lambda run : run . id ) if failed else None 7 ctx
1228 def _require_release_squash ( root : Path , stamping : str , base : str ) - > None : 12 ctx
1229 """Refuse to send the wave to a commit the wave itself would refuse.
1231 The wave publishes only from a release squash, recognised by the
1232 ``Mined-At`` line the pull request body becomes at the merge. The
1233 last commit touching the manifest on a release branch is the
1234 branch's own stamp commit, which carries no such line, so a
1235 dispatch from a checkout left on that branch would send a wave
1236 that refuses. The refusal names the squash on the base instead.
1238 from livery . workshop . _publish import mined_at 8 ctx
1240 if mined_at ( git . commit_message ( root , stamping ) ) : 8 ctx
1242 squash , subject = newest_release_squash ( root , base ) 1 ctx
1243 prog = footman . prog ( ) 1 ctx
1244 if squash : 1244 ↛ 1245line 1244 didn't jump to line 1245 because the condition on line 1244 was never true 1 ctx
1246 f " the newest release squash on origin/ { base } is { squash [ : 12 ] } "
1247 f " ( { subject } ); run ` { prog } workflow.release.dispatch` from { base } , "
1248 f " or ` { prog } workflow.release.dispatch --at= { squash [ : 12 ] } ` here "
1251 where = f " origin/ { base } holds no release squash in its recent history " 1 ctx
1253 f " { stamping [ : 12 ] } carries no Mined-At line: it is a branch ' s stamp "
1254 " commit, not a release squash, and the wave would refuse it. "
1259 def newest_release_squash ( root : Path , base : str = " main " ) - > tuple [ str , str ] : 12 ctx
1260 """The newest release squash on the base, as (sha, subject); ("", "") when none."""
1261 from livery . workshop . _publish import mined_at 2 ctx
1263 for sha , subject in git . recent_commits ( root , 50 , ref = _base_ref ( root , base ) ) : 2 ctx
1264 if subject . startswith ( " chore(release): released " ) and mined_at ( 1264 ↛ 1267line 1264 didn't jump to line 1267 because the condition on line 1264 was never true 2 ctx
1265 git . commit_message ( root , sha )
1271 def _base_ref ( root : Path , base : str ) - > str : 12 ctx
1272 """``origin/<base>`` after a fetch when the clone knows it, else HEAD.
1274 The release squashes live on the base. HEAD equals the base on the
1275 merge point and on a person's main, and differs on a release
1276 branch, whose history lacks the squash it was merged as; a clone
1277 without the remote (a rig) has only HEAD.
1279 with contextlib . suppress ( git . GitError ) : 15 ctx
1280 git . fetch ( root ) 15 ctx
1282 git . object_id ( root , f " origin/ { base } " ) 15 ctx
1283 except git . GitError :
1285 return f " origin/ { base } " 15 ctx
1288 def pending_release_waves ( 12 ctx
1289 root : Path , base : str = " main "
1290 ) - > tuple [ tuple [ str , tuple [ str , . . . ] ] , . . . ] :
1291 """Every recent release squash whose receipts are not all cut, oldest first.
1293 A merged release whose wave died leaves the squash on the base
1294 with the stamps and changelogs landed and receipt tags missing.
1295 Re-preparing from that state derives an empty release (measured:
1296 an empty pull request the forge never agrees to merge), so the
1297 recovery is the wave at the squash, never a new pull request.
1298 Every release squash in the base's recent history is consulted, so
1299 a later release never strands an earlier died wave, and a checkout
1300 standing on a release branch still finds the squash it was merged
1301 as. A later release squash naming a package takes over that
1302 package's uncut receipt, so a squash abandoned for a new release
1303 (`fm workflow.release --abandon`) is never offered again. Each
1304 entry is the squash sha and its missing receipt tags.
1306 from livery . workshop . _publish import discover_release 4 ctx
1308 cut = set ( git . remote_tags ( root ) ) 4 ctx
1309 pending : list [ tuple [ str , tuple [ str , . . . ] ] ] = [ ] 4 ctx
1310 # Newest first: the packages a later release squash names.
1311 taken : set [ str ] = set ( ) 4 ctx
1312 for sha , subject in git . recent_commits ( root , 50 , ref = _base_ref ( root , base ) ) : 4 ctx
1313 if not subject . startswith ( " chore(release): released " ) : 4 ctx
1315 released = discover_release ( root , sha ) 4 ctx
1316 missing = tuple ( 4 ctx
1317 f " { package . path } /v { version } "
1318 for package , version in released
1319 if f " { package . path } /v { version } " not in cut and package . path not in taken
1321 taken . update ( package . path for package , _version in released ) 4 ctx
1323 pending . append ( ( sha , missing ) ) 4 ctx
1324 pending . reverse ( ) 4 ctx
1325 return tuple ( pending ) 4 ctx
1328 def pending_release_wave ( root : Path ) - > tuple [ str , tuple [ str , . . . ] ] | None : 12 ctx
1329 """The oldest release squash with an uncut receipt, or None.
1331 The set-blind selection, for a dispatch with no set named:
1332 recoveries run in order, oldest first.
1334 waves = pending_release_waves ( root ) 2 ctx
1335 return waves [ 0 ] if waves else None 2 ctx
1338 def pending_release_wave_for ( 12 ctx
1339 root : Path , members : tuple [ Package , . . . ]
1340 ) - > tuple [ str , tuple [ str , . . . ] ] | None :
1341 """The oldest uncut squash whose receipts touch *members*, or None.
1343 A release of one set must find its own died wave even when an
1344 older squash of another set is uncut too: that squash is the
1345 other set's recovery, named by the caller, never a reason to
1346 prepare this set again from a tree already stamped.
1348 for sha , missing in pending_release_waves ( root ) : 2 ctx
1349 if uncut_in_set ( missing , members ) : 2 ctx
1350 return ( sha , missing ) 2 ctx
1354 def uncut_in_set ( 12 ctx
1355 missing : tuple [ str , . . . ] , members : tuple [ Package , . . . ]
1356 ) - > tuple [ str , . . . ] :
1357 """The uncut receipts, `packages/<member>/v<x>`, that belong to *members*."""
1358 names = { member . member for member in members } 4 ctx
1359 return tuple ( tag for tag in missing if receipt_member ( tag ) in names ) 4 ctx
1362 release_group = workflow . group ( " release " , help = " The release train " ) 12 ctx
1365 @release_group . default ( interactive = True ) 12 ctx
1366 def workflow_release ( 12 ctx
1368 armed : Annotated [ bool , doc ( " arm the release PR to merge on green " ) ] = False ,
1370 bool , doc ( " derive, build, validate, report; nothing leaves the machine " )
1372 force_unverified_base : Annotated [
1373 bool , doc ( " release without waiting for the base ' s own CI " )
1375 workshop : Annotated [
1376 str , doc ( " a released livery-workshop version to drive a re-dispatched wave " )
1381 " prepare a new release over a died wave of this set instead of "
1382 " re-dispatching it "
1386 """Release a set of packages: the branch decides the act.
1388 Names the set positionally (``packages/forge`` or just ``forge``).
1389 On a main-family branch this is the release train: one PR,
1390 receipts per member, re-running the recovery at every step;
1391 ``--armed`` follows the pull request to its squash and the wave
1392 to its verdict, from main, the way ``submit --armed`` follows a
1393 feature pull request, and an unarmed run returns at once. On
1394 any other branch it is the dev act: a wheel straight from the
1395 branch at a dev version, published only to the configured custom
1396 index after a confirmation, no reserved branch, no PR, no tags.
1397 ``--local`` is everything that stays on this machine, on either
1398 branch mode. ``--workshop`` applies only to the recovery of a
1399 died wave: the named release drives the wave in place of the
1400 squash's own workshop. ``--abandon`` gives up that recovery: when
1401 no released workshop can drive the died wave, a new release of
1402 the set takes its uncut receipts over.
1404 from livery . workshop . _dev_release import dev_release 2 ctx
1405 from livery . workshop . _extensions import workspace_root 2 ctx
1406 from livery . workshop . _forge_lane import this_repository 2 ctx
1408 root = workspace_root ( ) 2 ctx
1409 if root is None : 1409 ↛ 1410line 1409 didn't jump to line 1410 because the condition on line 1409 was never true 2 ctx
1410 fail ( " no workspace: no workshop.toml above the working directory " )
1411 if not paths : 1411 ↛ 1412line 1411 didn't jump to line 1412 because the condition on line 1411 was never true 2 ctx
1413 f " name the set: ` { footman . prog ( ) } workflow.release forge` (one package) or "
1414 f " ` { footman . prog ( ) } workflow.release forge workshop` (an atomic set) "
1416 members = resolve_set ( root , tuple ( paths ) ) 2 ctx
1417 branch = git . current_branch ( root ) 2 ctx
1420 " HEAD is detached, and the branch decides the act. Check out a "
1421 " branch (main for the release train, any feature branch for a "
1422 " dev build), then run this again. "
1424 if not runs_the_train ( branch ) : 2 ctx
1425 dev_release ( root , members , local = local ) 1 ctx
1428 local_release ( root , members ) 1 ctx
1430 print ( f " act: release train, from ' { branch } ' " ) 1 ctx
1431 pending = pending_release_wave_for ( root , members ) 1 ctx
1432 repo = this_repository ( root ) 1 ctx
1433 if abandon : 1433 ↛ 1446line 1433 didn't jump to line 1446 because the condition on line 1433 was always true 1 ctx
1434 if pending is None : 1 ctx
1436 " --abandon gives up a died wave of this set, and no release "
1437 " squash has an uncut receipt in it; drop the flag to prepare "
1440 squash , missing = pending 1 ctx
1442 f " release squash { squash [ : 12 ] } abandoned; this release takes over "
1443 f " its uncut receipts: { ' , ' . join ( uncut_in_set ( missing , members ) ) } "
1446 if pending is not None : 1446 ↛ 1447line 1446 didn't jump to line 1447 because the condition on line 1446 was never true 1 ctx
1447 squash , missing = pending
1448 print ( f " release squash { squash [ : 12 ] } has uncut receipts: " )
1449 for name in missing :
1451 # CI publishes, never this machine: the wave is dispatched
1452 # at the squash, the duplicate-tolerant wave walks past what
1453 # an earlier attempt already did, and nothing new prepares.
1454 print ( " dispatching the wave at the squash; nothing new prepares " )
1455 for line in dispatch_flow ( root , repo , at = squash , workshop = workshop ) :
1457 print ( " re-run to release work newer than the squash " )
1459 for squash , missing in pending_release_waves ( root ) : 1 ctx
1460 # An uncut receipt outside this set is that set's recovery,
1461 # named so a person can run it; this release goes ahead.
1462 inside = uncut_in_set ( missing , members ) 1 ctx
1463 missing = tuple ( tag for tag in missing if tag not in inside ) 1 ctx
1464 if not missing : 1464 ↛ 1466line 1464 didn't jump to line 1466 because the condition on line 1464 was always true 1 ctx
1466 others = " " . join ( sorted ( { receipt_member ( tag ) for tag in missing } ) )
1468 f " release squash { squash [ : 12 ] } has uncut receipts outside this "
1469 f " set: { ' , ' . join ( missing ) } ; ` { footman . prog ( ) } workflow.release "
1470 f " { others } ` re-dispatches its wave "
1472 if workshop : 1472 ↛ 1473line 1472 didn't jump to line 1473 because the condition on line 1472 was never true 1 ctx
1474 " --workshop pins the driver of a re-dispatched wave, and no "
1475 " release squash has an uncut receipt; drop the flag to prepare "
1485 force_unverified_base = force_unverified_base ,
1493 def run_release ( 12 ctx
1494 make_driver : Callable [ [ ] , ReleaseDriver ] ,
1500 """Drive a release through the engine; an armed one re-derives a stale set.
1502 An armed release whose follow ends red because the base moved
1503 under its set prepares again on the moved base and follows again,
1504 up to [livery.workshop._release_driver.REDERIVE_LIMIT] prepares
1505 in all; any other red is the release's verdict and exits with it.
1507 for attempt in range ( 1 , REDERIVE_LIMIT + 1 ) : 1507 ↛ exitline 1507 didn't return from function 'run_release' because the loop on line 1507 didn't complete 5 ctx
1508 driver = make_driver ( ) 5 ctx
1510 run_workflow ( driver , repo , root ) 5 ctx
1512 except SystemExit : 4 ctx
1515 or attempt == REDERIVE_LIMIT
1516 or not set_moved ( repo , root , driver . name )
1520 f " { driver . branch } : the base moved under the set while its pull "
1521 f " request waited; re-deriving ( { attempt } of "
1522 f " { REDERIVE_LIMIT - 1 } re-derives) "
1526 #: How many times an armed release prepares in all: the first prepare
1527 #: and its re-derives on a base that keeps moving under the set. A
1528 #: base that moves faster than a release can prepare is a repository
1529 #: where releases need merges held, and saying so beats looping.
1530 REDERIVE_LIMIT = 3 12 ctx
1533 def set_moved ( repo : Repository , root : Path , name : str ) - > bool : 12 ctx
1534 """Whether release *name*'s open pull request is stale in its set's paths."""
1535 from livery . workshop . _workflow_state import workflow_states
1539 wf . name == name and wf . blocker . name == " STALE_SET "
1540 for wf in workflow_states ( repo , root )
1544 @release_group . task ( name = " dispatch " ) 12 ctx
1545 def workflow_release_dispatch ( 12 ctx
1547 str , doc ( " an older release squash to dispatch instead of HEAD ' s " )
1549 workshop : Annotated [
1550 str , doc ( " a released livery-workshop version to drive the wave " )
1553 bool , doc ( " dispatch although a wave already failed at the squash " )
1556 """Dispatch the release wave for a merged, unpublished release; green otherwise.
1558 The merge point's last task, and the recovery gesture by hand:
1559 it reads the manifest at HEAD and the receipts on the remote, so
1560 on a normal day it prints green, after a died merge run it
1561 dispatches, a wave in flight is reported with its run id, and a
1562 wave that already failed at the squash is reported with its run
1563 and dispatched again only on ``--again``. ``--at`` names an older
1564 release squash a later release has moved past; ``--workshop``
1565 names a released driver for a wave whose own workshop was the
1568 from livery . workshop . _extensions import workspace_root
1569 from livery . workshop . _forge_lane import this_repository
1571 root = workspace_root ( )
1573 fail ( " no workspace: no workshop.toml above the working directory " )
1574 for line in dispatch_flow (
1575 root , this_repository ( root ) , at = at , workshop = workshop , again = again
1580 @release_group . task ( name = " check-title " , hidden = True ) 12 ctx
1581 def workflow_release_check_title ( 12 ctx
1582 title : Annotated [ str , doc ( " the PR title CI observed " ) ] = " " ,
1584 """Verify a release PR's title against the release's member list.
1586 The publish wave discovers a release from the squash's member
1587 list; the title is presentation. This job keeps the two
1588 consistent: the gate job runs this first, so a title that no
1589 longer names what the list prepared is refused before the
1590 union and the verdict, and the merge waits for a person to fix
1591 the title. Without ``--title`` the title
1592 comes from the runner's event payload; a run that is not a pull
1593 request, or a pull request off a release branch, is green here
1596 from livery . workshop . _extensions import workspace_root 2 ctx
1598 root = workspace_root ( ) 2 ctx
1599 if root is None : 1599 ↛ 1600line 1599 didn't jump to line 1600 because the condition on line 1599 was never true 2 ctx
1600 fail ( " no workspace: no workshop.toml above the working directory " )
1602 # The shell passes no title: the event payload names it, and
1603 # names the head branch too. An explicit --title is always
1604 # checked, whatever branch the runner is on.
1605 from livery . workshop . _ci_context import event_payload 1 ctx
1607 pull = ( event_payload ( ) or { } ) . get ( " pull_request " ) or { } 1 ctx
1608 title = str ( pull . get ( " title " ) or " " ) 1 ctx
1610 print ( " not a pull request: no title to check " ) 1 ctx
1612 head_ref = str ( ( pull . get ( " head " ) or { } ) . get ( " ref " ) or " " ) 1 ctx
1613 if head_ref and not head_ref . startswith ( " workflow/release/ " ) : 1613 ↛ 1616line 1613 didn't jump to line 1616 because the condition on line 1613 was always true 1 ctx
1614 print ( f " { head_ref } is not a release branch: nothing to check " ) 1 ctx
1616 branch = git . current_branch ( root ) 1 ctx
1617 recorded = member_pairs_at ( root , " HEAD " ) 1 ctx
1618 if not recorded : 1618 ↛ 1619line 1618 didn't jump to line 1619 because the condition on line 1618 was never true 1 ctx
1619 print ( f " { branch } : no release member list; nothing to check " )
1621 expected = release_title ( recorded ) 1 ctx
1622 if title and title != expected : 1 ctx
1624 f " the PR title does not match what the member list prepared: \n "
1625 f " title: { title } \n prepared: { expected } \n "
1626 " The title is presentation rebuilt from the branch ' s "
1627 " member list; restore it or re-run workflow.release. "
1629 print ( f " title matches the prepared release: { expected } " ) 1 ctx
1632 @release_group . task ( name = " check-fresh " , hidden = True ) 12 ctx
1633 def workflow_release_check_fresh ( 12 ctx
1634 head : Annotated [ str , doc ( " the pull request ' s head branch " ) ] = " " ,
1635 base : Annotated [ str , doc ( " the branch it merges into " ) ] = " " ,
1637 """Refuse a release pull request whose base moved in its set's paths.
1639 The gate job runs this last, so the time between the check and
1640 the merge it allows is as short as the forge makes it. The
1641 release's manifest names its members and the commit the prepare
1642 mined at; a commit the base gained since then under a member's
1643 directory is code the stamped changelog does not cover, and the
1644 squash's publish would refuse it after the merge, where nothing
1645 can fix the squash. Refused here, the pull request waits while
1646 `workflow.release` re-derives it in place. Without ``--head`` the
1647 branches come from the runner's event payload; a run that is not
1648 a pull request, or one off a release branch, is green and says so.
1652 from livery . workshop . _extensions import workspace_root 4 ctx
1653 from livery . workshop . _publish import MANIFEST , read_manifest 4 ctx
1655 root = workspace_root ( ) 4 ctx
1656 if root is None : 1656 ↛ 1657line 1656 didn't jump to line 1657 because the condition on line 1656 was never true 4 ctx
1657 fail ( " no workspace: no workshop.toml above the working directory " )
1658 if not head : 1658 ↛ 1659line 1658 didn't jump to line 1659 because the condition on line 1658 was never true 4 ctx
1659 from livery . workshop . _ci_context import event_payload
1661 pull = ( event_payload ( ) or { } ) . get ( " pull_request " ) or { }
1663 print ( " not a pull request: nothing to check " )
1665 head = str ( ( pull . get ( " head " ) or { } ) . get ( " ref " ) or " " )
1666 base = base or str ( ( pull . get ( " base " ) or { } ) . get ( " ref " ) or " " )
1667 if not head . startswith ( " workflow/release/ " ) : 4 ctx
1668 print ( f " { head or ' this branch ' } is not a release branch: nothing to check " ) 1 ctx
1670 base = base or " main " 3 ctx
1671 text = git . file_at ( root , " HEAD " , MANIFEST ) 3 ctx
1672 pairs = read_manifest ( text ) if text else None 3 ctx
1674 if pairs : 1674 ↛ 1677line 1674 didn't jump to line 1677 because the condition on line 1674 was always true 3 ctx
1675 with contextlib . suppress ( ValueError , TypeError , AttributeError ) : 3 ctx
1676 mined = str ( json . loads ( text ) . get ( " mined-at " ) or " " ) 3 ctx
1677 if not pairs or not mined : 3 ctx
1678 print ( f " { MANIFEST } records no mining point: nothing to check " ) 1 ctx
1680 git . fetch ( root ) 2 ctx
1681 by_member = { pkg . member : pkg for pkg in discover_packages ( root ) } 2 ctx
1682 pathspecs = tuple ( 2 ctx
1684 for directory , _ in pairs
1686 release_pathspecs ( by_member [ directory ] )
1687 if directory in by_member
1688 else ( f " packages/ { directory } " , )
1691 paths = tuple ( f " packages/ { directory } " for directory , _ in pairs ) 2 ctx
1692 moved = _moved_paths ( root , f " { mined } ..origin/ { base } " , pathspecs ) 2 ctx
1694 listed = " \n " . join ( f " { subject } " for subject in moved ) 1 ctx
1695 members = " " . join ( directory for directory , _ in pairs ) 1 ctx
1697 f " { base } moved under this release since its prepare at "
1698 f " { mined [ : 12 ] } : \n { listed } \n Merged, the squash would ship code "
1699 " its changelog does not cover. ` "
1700 f " { footman . prog ( ) } workflow.release { members } ` re-derives it in "
1701 " place; an armed release does that itself. "
1703 print ( f " fresh: { base } has not moved under { ' , ' . join ( paths ) } since { mined [ : 12 ] } " ) 1 ctx
1706 @release_group . task ( name = " build " , hidden = True ) 12 ctx
1707 def workflow_release_build ( 12 ctx
1708 ref : Annotated [ str , doc ( " the release squash; empty means HEAD " ) ] = " " ,
1710 """Build non-job-built release members and record their SHA-256 digests."""
1711 from livery . workshop . _extensions import workspace_root
1712 from livery . workshop . _publish import build_release_dists
1714 root = workspace_root ( )
1716 fail ( " no workspace: no workshop.toml above the working directory " )
1717 manifest = build_release_dists ( root , ref = ref )
1718 print ( f " built release distributions and wrote { manifest . relative_to ( root ) } " )
1721 @release_group . task ( name = " publish " , hidden = True ) 12 ctx
1722 def workflow_release_publish ( 12 ctx
1723 ref : Annotated [ str , doc ( " the release squash; empty means HEAD " ) ] = " " ,
1724 prebuilt : Annotated [
1725 bool , doc ( " trust the dist/ the run collected for each member a job builds " )
1728 """Publish the squash at --ref: the wave, receipts cut per member.
1730 The CI entry point after a release PR merges, and the recovery
1731 entry when a publish died mid-wave: everything already tagged is
1732 walked past. ``--ref`` exists because HEAD usually moves past the
1733 squash before a recovery runs. Each member publishes to the
1734 registry of the ecosystem its extensions release it to, and the
1735 wave reads what that registry serves through the probe they answer:
1736 the resolved index for a python package, the resolved conan target
1737 for a conan recipe that names a reference.
1738 ``--prebuilt`` says the jobs of the run already built the members
1739 they build before the wave, the workspace's ``job-built-members``
1740 answer: a platform-wheel member's dist/ holds the wheels collected
1741 from every platform, a conan member's the caches saved on every
1742 host, and the wave publishes them instead of building on this
1743 runner alone. Inside CI the wave decides that for itself: such a
1744 member whose dist/ already holds a file was fed by the run, since
1745 a runner's checkout starts with none.
1749 from livery . workshop . _extensions import workspace_root 1 ctx
1750 from livery . workshop . _publish import Registry , publish_release 1 ctx
1751 from livery . workshop . _registries import resolve_registry 1 ctx
1753 root = workspace_root ( ) 1 ctx
1754 if root is None : 1754 ↛ 1755line 1754 didn't jump to line 1755 because the condition on line 1754 was never true 1 ctx
1755 fail ( " no workspace: no workshop.toml above the working directory " )
1756 target = resolve_registry ( root , " python " ) 1 ctx
1757 if not target . publish_url : 1757 ↛ 1758line 1757 didn't jump to line 1758 because the condition on line 1757 was never true 1 ctx
1758 from livery . workshop . _dev_release import INDEX_VAR
1761 " no publish address resolved for python: the declaration "
1762 " names only a read index, and an upload endpoint is "
1763 " never defaulted. Declare [registries.python] publish in "
1764 f " workshop.toml, or set { INDEX_VAR } . "
1766 if not prebuilt : 1766 ↛ 1767line 1766 didn't jump to line 1767 because the condition on line 1766 was never true 1 ctx
1767 prebuilt = collected_wheels ( root , ref )
1768 # Each member's probe is its extensions' answer, asked once and
1769 # polled through the wave's whole wait.
1770 probes : dict [ str , Registry ] = { } 1 ctx
1772 def registry_for ( package : Package ) - > Registry : 1 ctx
1773 probe = probes . get ( package . path ) 1 ctx
1774 if probe is None : 1 ctx
1775 probe = probes [ package . path ] = _lifecycle . registry ( package ) 1 ctx
1778 receipts = publish_release ( 1 ctx
1782 index_url = target . publish_url ,
1783 # UV_PUBLISH_TOKEN is the explicit override; the resolved
1784 # target's credential is the same seam the probe reads, so a
1785 # forge registry publishes with the lane token unprompted.
1786 token = os . environ . get ( " UV_PUBLISH_TOKEN " , " " ) or target . token ,
1789 print ( f " wave: { len ( receipts ) } member(s) published " ) 1 ctx
1792 def collected_wheels ( root : Path , ref : str ) - > bool : 12 ctx
1793 """Whether the run collected what a job built for this wave, judged inside CI alone.
1795 The members a job builds before the wave are the workspace's
1796 ``job-built-members`` answer. A runner's checkout starts with no
1797 dist/, so a file in such a member's dist/ was collected from that
1798 job's artifact, and the wave trusts the collection; each member it
1799 trusts is printed with its job. Outside CI a dist/ may hold a stale
1800 local build, and the wave builds as asked.
1802 from livery . workshop . _ci_context import run_context 1 ctx
1803 from livery . workshop . _publish import collected , discover_release 1 ctx
1804 from livery . workshop . _queries import JOB_BUILT_MEMBERS , answer 1 ctx
1806 if run_context ( ) is None : 1 ctx
1808 built = answer ( root , JOB_BUILT_MEMBERS ) 1 ctx
1810 for package , _version in discover_release ( root , ref or git . head_sha ( root ) ) : 1 ctx
1811 job = built . get ( package . path ) 1 ctx
1812 if job is not None and collected ( package ) : 1 ctx
1814 f " prebuilt: { package . name } : the run collected what the { job } job "