Coverage for packages/workshop/src/livery/workshop/_workflow_tasks.py: 79%
Measured by coverage.py 7.16.2 on CPython 3.14 while the suites of tests, packages/workshop/tests/test_workshop_workflow.py, packages/workshop/tests/test_workshop_without_docs.py, packages/workshop/tests/test_workshop_vocabulary.py, packages/workshop/tests/test_workshop_update.py, packages/workshop/tests/test_workshop_sync.py, packages/workshop/tests/test_workshop_submit.py, packages/workshop/tests/test_workshop_shells.py, packages/workshop/tests/test_workshop_security.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_isolated.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.
230 statements
185 run
45 missing
0 excluded
11 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 """The ``workflow`` group: the reserved-branch lifecycles' surface.
3 ``workflow.abort`` stops a reserved workflow, policy layered over the
4 same teardown mechanism ``fm abandon`` uses. The hidden
5 ``workflow.configure`` asserts repository settings from the workspace
6 contract, run at birth, as release aftercare, and after an abort.
7 The lifecycle drivers (``workflow.release``, ``workflow.update``)
8 arrive with their own modules; this one owns what every kind shares.
11 from __future__ import annotations 14 ctx
13 from pathlib import Path 14 ctx
14 from typing import Annotated 14 ctx
16 import livery . footman as footman 14 ctx
17 from livery import git 14 ctx
18 from livery . footman import doc , fail , group , suggest 14 ctx
19 from livery . forge import Forge , Label , RepoConfig , Repository 14 ctx
20 from livery . workshop . _contract import load_contract 14 ctx
21 from livery . workshop . _extensions import workspace_root 14 ctx
22 from livery . workshop . _workflow_state import ( 14 ctx
29 workflow = group ( " workflow " , help = " The reserved-branch lifecycles " ) 14 ctx
32 def _root ( ) - > Path : 14 ctx
33 root = workspace_root ( ) 10 ctx
34 if root is None : 34 ↛ 35line 34 didn't jump to line 35 because the condition on line 34 was never true 10 ctx
35 fail ( " no workspace: no workshop.toml above the working directory " )
39 def _resolved ( ) - > tuple [ Repository , Path ] : 14 ctx
40 from livery . workshop . _forge_lane import this_repository
43 return this_repository ( root ) , root
46 def render_workflows ( states : tuple [ WorkflowStatus , . . . ] ) - > None : 14 ctx
47 """Print one line per workflow: name, state, author, the way forward."""
49 print ( " no reserved workflows in flight " ) 1 ctx
51 for wf in states : 1 ctx
52 author = f " ( { wf . author } ) " if wf . author else " " 1 ctx
53 extra = f " - { wf . detail } " if wf . detail else " " 1 ctx
55 f " [tagged: { ' , ' . join ( wf . tagged ) } ] "
56 if wf . tagged and wf . state is not WorkflowState . SUCCEEDED
59 print ( f " { wf . name } : { wf . state . value } { author } { extra } { tagged } " ) 1 ctx
62 def abort_policy ( 14 ctx
65 states : tuple [ WorkflowStatus , . . . ] ,
70 interactive : bool = False ,
72 """The abort's state gates, then the shared teardown.
74 Bare with one workflow targets it; several ask interactively or
75 refuse by name, silence never picks a teardown target. UNKNOWN
76 refuses without force, never tear down on a blip; a live state
77 refuses without force; a bare ``--force`` with several in flight
78 refuses, force one by name.
81 print ( " no reserved workflows to abort " ) 1 ctx
83 target : WorkflowStatus | None = None 4 ctx
85 target = next ( ( wf for wf in states if wf . name == name ) , None ) 1 ctx
86 if target is None : 1 ctx
87 known = " , " . join ( wf . name for wf in states ) 1 ctx
88 fail ( f " no workflow named { name !r} ; in flight: { known } " ) 1 ctx
89 elif len ( states ) == 1 : 4 ctx
90 target = states [ 0 ] 2 ctx
91 elif interactive : 2 ctx
92 options : list [ tuple [ str , WorkflowStatus | None ] ] = [ 1 ctx
93 ( f " { wf . name } ( { wf . author or ' unknown author ' } , { wf . state . value } ) " , wf )
96 options . append ( ( " nothing - leave them all running " , None ) ) 1 ctx
97 picked = footman . select ( " abort which? " , options ) 1 ctx
98 # The select's typing admits a bare-label pick; every option
99 # here carries a value, so a str can only mean no target.
100 target = picked if not isinstance ( picked , str ) else None 1 ctx
101 if target is None : 1 ctx
102 raise SystemExit ( " nothing aborted " ) 1 ctx
104 listed = " \n " . join ( 1 ctx
105 f " { footman . prog ( ) } workflow.abort { wf . name } "
106 + ( f " ( { wf . author } , { wf . state . value } ) " if wf . author else " " )
110 " several workflows are in flight, and silence must not pick a "
111 f " teardown target. Abort one by name: \n { listed } "
113 assert target is not None 4 ctx
114 if force and not name and len ( states ) > 1 : 114 ↛ 115line 114 didn't jump to line 115 because the condition on line 114 was never true 4 ctx
116 " --force with several workflows in flight needs a name: a bare "
117 " force must not sweep what someone else is running "
119 if target . state is WorkflowState . UNKNOWN and not force : 4 ctx
121 f " { target . name } ' s state could not be read, and a blip must never "
122 " look like permission to tear down. Retry when the forge "
123 f " answers, or ` { footman . prog ( ) } workflow.abort { target . name } "
127 if target . state not in TEARDOWN_SAFE and not force : 3 ctx
128 who = target . author or " someone " 1 ctx
130 f " { target . name } is { target . state . value } ( { who } ); aborting it "
131 " loses in-flight work. Wait for it, coordinate with its "
132 f " author, or ` { footman . prog ( ) } workflow.abort { target . name } "
134 " it down deliberately. "
136 from livery . workshop . _submit import teardown_branch 2 ctx
140 head_sha = git . any_head ( root , target . branch ) 2 ctx
143 teardown_branch ( repo , root , target . branch , base ) 2 ctx
144 _reconcile_configuration ( root , head_sha ) 2 ctx
147 def _active_names ( ) - > tuple [ str , . . . ] : 14 ctx
148 """The in-flight workflow names, for completion; empty off a workspace."""
150 repo , root = _resolved ( )
151 return tuple ( wf . name for wf in workflow_states ( repo , root ) )
156 @workflow . task ( name = " abort " , interactive = True ) 14 ctx
157 def workflow_abort ( 14 ctx
160 suggest ( _active_names , strict = False ) ,
161 doc ( " the workflow to stop; bare targets the only one in flight " ) ,
163 force : Annotated [ bool , doc ( " tear down a live or unreadable workflow " ) ] = False ,
165 """Stop a reserved workflow: disarm, close its PR, tear its branch down.
167 Bare targets the only workflow in flight; with several, an
168 interactive run lists them and asks, a non-interactive run
169 refuses naming each. A live or unreadable workflow refuses
170 without ``--force``, and a bare ``--force`` never sweeps several.
171 Ends by re-asserting the repository configuration, so an aborted
172 workflow that had moved settings forward cannot leave protection
173 demanding contexts that never report again.
175 repo , root = _resolved ( )
176 states = workflow_states ( repo , root )
183 interactive = footman . attended ( ) ,
187 def required_context_string ( forge_kind : str , context : str ) - > str : 14 ctx
188 """The status context string protection must require, per forge.
190 The name in the contract is the gate job's; forges report it
191 differently. GitHub reports the job name itself. Gitea reports
192 Actions statuses as ``<workflow name> / <job> (<event>)``, so a
193 bare job name never matches and the required check can never
194 pass; the workflow's emitted name is ``ci``, and the merge-
195 deciding event is the pull request's. GitLab has no required
196 contexts (the capability probe drops the half), so its spelling
197 never reaches a forge.
199 if forge_kind == " gitea " : 14 ctx
200 return f " ci / { context } (pull_request) " 2 ctx
204 def contract_config ( root : Path ) - > RepoConfig : 14 ctx
205 """The repository settings the workspace contract states.
207 The approvals half derives from the owner declarations
208 (livery.workshop._governance): the highest declared count, with
209 codeowner review required whenever anyone is declared. A forge
210 without the min_approvals capability gets the config without
211 that half rather than a refusal: governance degrades to the
212 codeowners file alone, which is what the forge can honour.
214 from livery . forge import EnvironmentConfig 7 ctx
215 from livery . workshop . _governance import ci_environments , governance_config 7 ctx
216 from livery . workshop . _points import EVERY_RUNNER_LABEL 7 ctx
218 contract = load_contract ( root / " workshop.toml " ) 7 ctx
219 ci = contract . get ( " ci " ) or { } 7 ctx
220 context = str ( ci . get ( " required-context " ) or " gate " ) 7 ctx
221 forge_kind = str ( ( contract . get ( " forge " ) or { } ) . get ( " kind " , " " ) ) 7 ctx
222 approvals = governance_config ( root ) 7 ctx
223 env_names = tuple ( dict . fromkeys ( ci_environments ( contract ) . values ( ) ) ) 7 ctx
224 return RepoConfig ( 7 ctx
226 delete_branch_on_merge = True ,
227 allow_auto_merge = True ,
228 required_contexts = ( required_context_string ( forge_kind , context ) , ) ,
229 # The release train's receipts: once cut, no ordinary push
230 # may delete or move them. A forge's glob stops at a slash, so
231 # a package in a group directory needs the second pattern.
232 protected_tag_patterns = ( " packages/*/v* " , " packages/*/*/v* " ) ,
233 # The same truth spelled for a forge that cannot name
234 # contexts: the server refuses merges while the head is not
235 # green, the UI's merge button included.
236 require_pipeline_success = True ,
237 min_approvals = approvals . min_approvals ,
238 require_codeowner_review = approvals . require_codeowner_review ,
239 dismiss_stale_reviews = approvals . dismiss_stale_reviews ,
241 EnvironmentConfig ( name = name , protected_branches_only = True )
242 for name in env_names
244 # The label `submit --every-runner` sets, so a forge that
245 # refuses a label it does not carry has it before any submit.
248 name = EVERY_RUNNER_LABEL ,
250 description = " the gate runs every runner for this pull request " ,
256 #: The paths whose change means the repository's settings may have
257 #: moved: the contracts and the owners file, on every forge's spelling.
258 GOVERNED_PATHS = ( 14 ctx
262 " .github/CODEOWNERS " ,
266 def contract_changed ( root : Path ) - > tuple [ str , . . . ] : 14 ctx
267 """The governed paths HEAD's own commit changed; empty is none.
269 The merge point's commit is one squash on main, so its file list
270 is the merge's whole diff. A shallow checkout of depth one reads
271 a squash as a root commit and lists every file, so the shell
274 changed = git . files_in_commit ( root , " HEAD " ) 2 ctx
278 if path in GOVERNED_PATHS
279 or ( path . startswith ( " packages/ " ) and path . endswith ( " /workshop.toml " ) )
283 @workflow . task ( name = " configure " , hidden = True ) 14 ctx
284 def workflow_configure ( 14 ctx
285 if_changed : Annotated [
286 bool , doc ( " only when HEAD changed a contract or the owners file " )
289 """Assert the contract's repository settings; idempotent drift repair.
291 Run at repository birth, as release aftercare, after an abort,
292 and at the merge point, where ``--if-changed`` makes it classify
293 its own commit and exit fast when no contract path changed.
294 Resolves the admin ladder (``FORGE_ADMIN_TOKEN``, host-qualified
295 first, the everyday token as the fallback); a refused write
296 teaches the grant and the variable. Declared owners the forge
297 does not know refuse before anything is applied: a review chain
298 pointing at nobody is worse than unapplied settings.
302 changed = contract_changed ( root ) 1 ctx
303 if not changed : 303 ↛ 306line 303 didn't jump to line 306 because the condition on line 303 was always true 1 ctx
304 print ( " no contract or owners path changed in HEAD; nothing to reconcile " ) 1 ctx
306 print ( f " governed paths changed: { ' , ' . join ( changed ) } " )
307 assert_configuration ( root ) 6 ctx
310 def assert_configuration ( root : Path ) - > None : 14 ctx
311 """The configure flow, root-taking so birth can call it too."""
312 from livery . forge import ForgeError , Unsupported 6 ctx
313 from livery . workshop . _forge_lane import admin_forge , admin_repository 6 ctx
314 from livery . workshop . _governance import unknown_owners 6 ctx
316 repo , admin_var = admin_repository ( root ) 6 ctx
317 forge , _ = admin_forge ( root ) 6 ctx
318 contract = load_contract ( root / " workshop.toml " ) 6 ctx
319 owner = str ( ( contract . get ( " forge " ) or { } ) . get ( " owner " , " " ) ) 6 ctx
320 missing = unknown_owners ( root , forge , owner ) 6 ctx
322 listed = " \n " . join ( f " { entry } " for entry in missing ) 1 ctx
324 " the owner declarations name people or teams this forge does "
325 f " not know: \n { listed } \n Fix the declarations (or the org "
326 " membership) and re-run. "
328 from dataclasses import replace 5 ctx
330 config = contract_config ( root ) 5 ctx
331 if config . min_approvals is not None and not forge . supports ( " min_approvals " ) : 5 ctx
332 # The forge cannot enforce the count (GitLab's paid tiers);
333 # the codeowners file still documents it, so the rest of the
334 # contract applies rather than nothing.
336 " note: this instance cannot enforce approval counts "
337 " (capability: min_approvals); the codeowners file still "
338 " names the reviewers "
340 config = replace ( 2 ctx
343 require_codeowner_review = None ,
344 dismiss_stale_reviews = None ,
346 if config . dismiss_stale_reviews is not None and not forge . supports ( 346 ↛ 349line 346 didn't jump to line 349 because the condition on line 346 was never true 5 ctx
347 " dismiss_stale_reviews "
350 " note: this instance cannot dismiss stale approving reviews "
351 " (capability: dismiss_stale_reviews) "
353 config = replace ( config , dismiss_stale_reviews = None )
354 if config . required_contexts is not None and not forge . supports ( " required_contexts " ) : 5 ctx
355 # GitLab: protection cannot name check contexts, and the
356 # pipeline-success block carries the same truth there, the
357 # UI's merge button included.
359 " note: this forge cannot name required check contexts "
360 " (capability: required_contexts); the pipeline-success "
361 " block enforces green-before-merge instead, the forge "
364 config = replace ( config , required_contexts = None ) 1 ctx
365 if ( 365 ↛ 368line 365 didn't jump to line 368 because the condition on line 365 was never true
366 config . environments is not None or config . environment_secrets is not None
367 ) and not forge . supports ( " scoped_secrets " ) :
369 " note: this forge cannot scope CI secrets to protected "
370 " branches (capability: scoped_secrets) "
372 config = replace ( config , environments = None , environment_secrets = None )
374 repo . configure ( config ) 5 ctx
375 except Unsupported as error : 2 ctx
376 # A decline the probes above did not predict: name it
377 # verbatim, never half-teach a token that would not help.
379 f " the forge declined part of the configuration: \n { error } \n "
380 f " ` { footman . prog ( ) } doctor` says what this forge grants. "
382 except ForgeError as error : 1 ctx
383 used = admin_var or " the everyday token " 1 ctx
385 f " the forge refused the configuration using { used } : \n { error } \n "
386 " An administrator ' s token applies it: set FORGE_ADMIN_TOKEN "
387 " (host-qualified FORGE_ADMIN_TOKEN__<HOST> where one machine "
388 f " serves several forges) and re-run "
389 f " ` { footman . prog ( ) } workflow.configure`. "
391 from livery . workshop . _points import job_seams 3 ctx
393 if " pages " in job_seams ( root ) . values ( ) and forge . supports ( " pages_config " ) : 393 ↛ 394line 393 didn't jump to line 394 because the condition on line 393 was never true 3 ctx
394 repo . ensure_pages ( build_type = " workflow " )
395 print ( " pages hosting asserted (workflow build type) " )
396 for line in reconcile_schedules ( repo , forge ) : 3 ctx
398 print ( " repository configuration asserted from the contract " ) 3 ctx
401 #: How the reconcile names the schedules it owns; any other schedule
402 #: on the repository is a person's and is never touched.
403 SCHEDULE_PREFIX = " workshop: " 14 ctx
406 def reconcile_schedules ( repo : Repository , forge : Forge ) - > list [ str ] : 14 ctx
407 """Make the forge's clock match the points that run on it; what was done.
409 A forge whose clock is in the workflow file (GitHub, Gitea) has
410 nothing to reconcile and says so. On a forge with pipeline
411 schedules (GitLab) every declared point whose events include
412 ``schedule`` gets one schedule on ``main``, named
413 ``workshop: <point>``, at the point's cron, starting its pipeline
414 with ``FORGE_WORKFLOW`` set to the point's workflow file so the
415 document routes it; a schedule the reconcile named for a point
416 no longer declared is deleted.
418 from livery . workshop . _points import DECLARED 3 ctx
420 if not forge . supports ( " pipeline_schedules " ) : 3 ctx
421 return [ " schedules: the clock is in the workflow file; nothing to reconcile " ] 1 ctx
423 f " { SCHEDULE_PREFIX } { point . name } " : point
424 for point in DECLARED
425 if " schedule " in point . events
427 lines : list [ str ] = [ ] 3 ctx
428 for description , point in wanted . items ( ) : 3 ctx
429 schedule = repo . schedule . ensure ( 3 ctx
433 variables = { " FORGE_WORKFLOW " : point . workflow } ,
436 f " schedule { description !r} : { schedule . cron } on { schedule . ref } , "
437 f " FORGE_WORKFLOW= { point . workflow } "
439 for schedule in repo . schedule . list ( ) : 3 ctx
441 schedule . description . startswith ( SCHEDULE_PREFIX )
442 and schedule . description not in wanted
444 repo . schedule . delete ( schedule . description ) 1 ctx
445 lines . append ( f " schedule { schedule . description !r} : deleted, no such point " ) 1 ctx
449 def _spawn_configure ( ) - > footman . Result : 14 ctx
450 """Run the configure verb in a fresh process; the reconcile's seam.
452 Fresh, because the abort may sit inside a workflow whose update
453 rewrote this very toolchain.
457 return footman . run ( 1 ctx
458 [ sys . executable , " -m " , " livery.footman " , " workflow.configure " ] ,
465 def _reconcile_configuration ( root : Path , head_sha : str ) - > None : 14 ctx
466 """Re-assert configuration after an abort; silent when provably unneeded.
468 The ladder: an offline diff of the governance paths from the
469 aborted PR's head sha (which persists after the branch deletion)
470 skips everything untouched with certainty; touched paths run the
471 configure in a fresh process (the abort may sit inside a
472 workflow whose update rewrote this toolchain). A failed
473 configure prints its reason verbatim under a conditional note,
474 never an asserted problem: the abort already succeeded, and the
475 repair verb is the same either way.
477 from livery . workshop . _governance import governance_paths 3 ctx
479 if head_sha : 479 ↛ 499line 479 didn't jump to line 499 because the condition on line 479 was always true 3 ctx
481 # The branch side of the diff: an aborted branch that
482 # touched governance may have applied protection before
483 # its merge (the rename heal), and the abort leaves main
484 # demanding the old contract.
485 changed = git . run ( 3 ctx
489 f " origin/main... { head_sha } " ,
492 " packages/*/workshop.toml " ,
493 * [ p for p in governance_paths ( _root ( ) ) if " * " not in p ] ,
495 except Exception : 1 ctx
496 changed = " unknown " 1 ctx
498 return # nothing config-implying moved: provably unneeded 1 ctx
499 result = _spawn_configure ( ) 2 ctx
500 if result . code != 0 : 500 ↛ exitline 500 didn't return from function '_reconcile_configuration' because the condition on line 500 was always true 2 ctx
501 detail = result . stderr . strip ( ) or result . stdout . strip ( ) or " (no output) " 2 ctx
502 indented = " \n " . join ( f " { line } " for line in detail . splitlines ( ) ) 2 ctx
504 " note: the configuration could not be re-asserted from here; "
505 f " if governance settings changed, ` { footman . prog ( ) } workflow.configure` "
506 " repairs them (an administrator ' s token may be needed): \n "
511 secret = workflow . group ( " secret " , help = " Place CI secrets in protected scopes " ) 14 ctx
514 def place_secret ( 14 ctx
519 environment : str = " " ,
520 forge : Forge | None = None ,
521 repo : Repository | None = None ,
523 """Write CI secret *name* into its protected scope on the forge.
525 On GitHub, ensures the target deployment environment exists with
526 ``protected_branches_only=True`` and stores *value* in that
527 environment (never at repository scope). On GitLab, stores *value*
528 as a ``protected: true`` project CI variable. On forges lacking
529 ``scoped_secrets`` (such as Gitea), refuses plainly with guidance.
532 A human-readable summary of where *name* was placed (never
535 from livery . forge import EnvironmentConfig , ForgeError , Unsupported 2 ctx
536 from livery . workshop . _governance import ci_environments 2 ctx
537 from livery . workshop . _security import SECRET_ROLES 2 ctx
539 cleaned = name . strip ( ) 2 ctx
540 if not cleaned : 540 ↛ 541line 540 didn't jump to line 541 because the condition on line 540 was never true 2 ctx
541 fail ( " secret name must be non-empty " )
542 if not value : 542 ↛ 543line 542 didn't jump to line 543 because the condition on line 542 was never true 2 ctx
543 fail ( f " refusing to write an empty value for { cleaned } " )
545 contract = load_contract ( root / " workshop.toml " ) 2 ctx
546 kind = str ( ( contract . get ( " forge " ) or { } ) . get ( " kind " , " " ) ) 2 ctx
547 envs = ci_environments ( contract ) 2 ctx
548 target_env = environment . strip ( ) 2 ctx
549 if not target_env and cleaned in SECRET_ROLES : 2 ctx
550 target_env = envs [ SECRET_ROLES [ cleaned ] ] 2 ctx
552 if forge is None or repo is None : 552 ↛ 553line 552 didn't jump to line 553 because the condition on line 552 was never true 2 ctx
553 from livery . workshop . _forge_lane import admin_forge , admin_repository
555 resolved_repo , _var = admin_repository ( root )
556 resolved_forge , _fvar = admin_forge ( root )
557 repo = repo or resolved_repo
558 forge = forge or resolved_forge
560 if not forge . supports ( " scoped_secrets " ) : 2 ctx
562 f " { kind or ' this forge ' } lacks branch-scoped CI secrets "
563 " (capability: scoped_secrets). Require fork-only contributions "
564 " or keep FORGE_ADMIN_TOKEN off CI and run "
565 f " ` { footman . prog ( ) } workflow.configure` from a maintainer ' s desk. "
568 if kind == " github " and not target_env : 2 ctx
569 known = " , " . join ( sorted ( dict . fromkeys ( envs . values ( ) ) ) ) 1 ctx
571 f " { cleaned } has no default GitHub environment: pass "
572 f " --environment=<name> (configured environments: { known } ); "
573 " refusing to place a secret at repository scope "
576 env_key = target_env or " protected " 2 ctx
577 cfg = RepoConfig ( 2 ctx
578 environments = ( EnvironmentConfig ( name = env_key , protected_branches_only = True ) , ) ,
579 environment_secrets = { env_key : { cleaned : value } } ,
582 repo . configure ( cfg ) 2 ctx
583 except ( Unsupported , ForgeError ) as error :
584 fail ( f " failed to store scoped secret { cleaned } : \n { error } " )
586 if kind == " gitlab " : 2 ctx
587 return f " { cleaned } : stored as protected CI variable (protected=True) " 1 ctx
589 f " { cleaned } : stored in protected environment { target_env !r} "
590 " (protected_branches_only=True) "
594 @secret . task ( name = " set " , interactive = True ) 14 ctx
595 def workflow_secret_set ( 14 ctx
598 doc ( " CI secret name (e.g. FORGE_ADMIN_TOKEN, FORGE_TOKEN, PYPI_TOKEN) " ) ,
602 doc ( " secret value; omitted prompts securely or reads --from-env " ) ,
604 environment : Annotated [
606 doc ( " explicit protected environment name (defaults by secret role) " ) ,
610 doc ( " read the secret value from the local environment variable <NAME> " ) ,
613 """Place a CI secret directly into its protected scope, never repo scope.
615 Maps ``FORGE_ADMIN_TOKEN`` to ``govern``, ``FORGE_TOKEN`` to ``bot``,
616 and ``PYPI_TOKEN`` / ``UV_PUBLISH_TOKEN`` to ``pypi`` (respecting
617 ``[ci.environments]`` overrides in ``workshop.toml``). On GitHub,
618 creates or locks the target environment to protected branches before
619 storing the secret; on GitLab, marks the project CI variable
620 ``protected: true``; on Gitea, refuses plainly with mitigation steps.
627 if from_env and not secret_value :
628 secret_value = os . environ . get ( name , " " )
630 fail ( f " --from-env requested but { name } is unset or empty " )
632 if not footman . attended ( ) :
634 f " no value supplied for { name } : pass --from-env or run "
635 " interactively to enter the secret safely "
637 secret_value = getpass . getpass ( f " Value for { name } : " )
638 summary = place_secret ( root , name , secret_value , environment = environment )