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.

1"""The ``workflow`` group: the reserved-branch lifecycles' surface.
2
3``workflow.abort`` stops a reserved workflow, policy layered over the
4same teardown mechanism ``fm abandon`` uses. The hidden
5``workflow.configure`` asserts repository settings from the workspace
6contract, run at birth, as release aftercare, and after an abort.
7The lifecycle drivers (``workflow.release``, ``workflow.update``)
8arrive with their own modules; this one owns what every kind shares.
9"""
10
11from __future__ import annotations
12
13from pathlib import Path
14from typing import Annotated
15
16import livery.footman as footman
17from livery import git
18from livery.footman import doc, fail, group, suggest
19from livery.forge import Forge, Label, RepoConfig, Repository
20from livery.workshop._contract import load_contract
21from livery.workshop._extensions import workspace_root
22from livery.workshop._workflow_state import (
23 TEARDOWN_SAFE,
24 WorkflowState,
25 WorkflowStatus,
26 workflow_states,
27)
28
29workflow = group("workflow", help="The reserved-branch lifecycles")
30
31
32def _root() -> Path:
33 root = workspace_root()
34 if root is None:34 ↛ 35line 34 didn't jump to line 35 because the condition on line 34 was never true
35 fail("no workspace: no workshop.toml above the working directory")
36 return root
37
38
39def _resolved() -> tuple[Repository, Path]:
40 from livery.workshop._forge_lane import this_repository
41
42 root = _root()
43 return this_repository(root), root
44
45
46def render_workflows(states: tuple[WorkflowStatus, ...]) -> None:
47 """Print one line per workflow: name, state, author, the way forward."""
48 if not states:
49 print(" no reserved workflows in flight")
50 return
51 for wf in states:
52 author = f" ({wf.author})" if wf.author else ""
53 extra = f" - {wf.detail}" if wf.detail else ""
54 tagged = (
55 f" [tagged: {', '.join(wf.tagged)}]"
56 if wf.tagged and wf.state is not WorkflowState.SUCCEEDED
57 else ""
58 )
59 print(f" {wf.name}: {wf.state.value}{author}{extra}{tagged}")
60
61
62def abort_policy(
63 repo: Repository,
64 root: Path,
65 states: tuple[WorkflowStatus, ...],
66 name: str,
67 *,
68 force: bool,
69 base: str = "main",
70 interactive: bool = False,
71) -> None:
72 """The abort's state gates, then the shared teardown.
73
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.
79 """
80 if not states:
81 print(" no reserved workflows to abort")
82 return
83 target: WorkflowStatus | None = None
84 if name:
85 target = next((wf for wf in states if wf.name == name), None)
86 if target is None:
87 known = ", ".join(wf.name for wf in states)
88 fail(f"no workflow named {name!r}; in flight: {known}")
89 elif len(states) == 1:
90 target = states[0]
91 elif interactive:
92 options: list[tuple[str, WorkflowStatus | None]] = [
93 (f"{wf.name} ({wf.author or 'unknown author'}, {wf.state.value})", wf)
94 for wf in states
95 ]
96 options.append(("nothing - leave them all running", None))
97 picked = footman.select("abort which?", options)
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
101 if target is None:
102 raise SystemExit(" nothing aborted")
103 else:
104 listed = "\n".join(
105 f" {footman.prog()} workflow.abort {wf.name}"
106 + (f" ({wf.author}, {wf.state.value})" if wf.author else "")
107 for wf in states
108 )
109 fail(
110 "several workflows are in flight, and silence must not pick a"
111 f" teardown target. Abort one by name:\n{listed}"
112 )
113 assert target is not None
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
115 fail(
116 "--force with several workflows in flight needs a name: a bare"
117 " force must not sweep what someone else is running"
118 )
119 if target.state is WorkflowState.UNKNOWN and not force:
120 fail(
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}"
124 " --force` if you"
125 " know it is dead."
126 )
127 if target.state not in TEARDOWN_SAFE and not force:
128 who = target.author or "someone"
129 fail(
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}"
133 " --force` to tear"
134 " it down deliberately."
135 )
136 from livery.workshop._submit import teardown_branch
137
138 head_sha = ""
139 try:
140 head_sha = git.any_head(root, target.branch)
141 except Exception:
142 head_sha = ""
143 teardown_branch(repo, root, target.branch, base)
144 _reconcile_configuration(root, head_sha)
145
146
147def _active_names() -> tuple[str, ...]:
148 """The in-flight workflow names, for completion; empty off a workspace."""
149 try:
150 repo, root = _resolved()
151 return tuple(wf.name for wf in workflow_states(repo, root))
152 except Exception:
153 return ()
154
155
156@workflow.task(name="abort", interactive=True)
157def workflow_abort(
158 name: Annotated[
159 str,
160 suggest(_active_names, strict=False),
161 doc("the workflow to stop; bare targets the only one in flight"),
162 ] = "",
163 force: Annotated[bool, doc("tear down a live or unreadable workflow")] = False,
164) -> None:
165 """Stop a reserved workflow: disarm, close its PR, tear its branch down.
166
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.
174 """
175 repo, root = _resolved()
176 states = workflow_states(repo, root)
177 abort_policy(
178 repo,
179 root,
180 states,
181 name,
182 force=force,
183 interactive=footman.attended(),
184 )
185
186
187def required_context_string(forge_kind: str, context: str) -> str:
188 """The status context string protection must require, per forge.
189
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.
198 """
199 if forge_kind == "gitea":
200 return f"ci / {context} (pull_request)"
201 return context
202
203
204def contract_config(root: Path) -> RepoConfig:
205 """The repository settings the workspace contract states.
206
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.
213 """
214 from livery.forge import EnvironmentConfig
215 from livery.workshop._governance import ci_environments, governance_config
216 from livery.workshop._points import EVERY_RUNNER_LABEL
217
218 contract = load_contract(root / "workshop.toml")
219 ci = contract.get("ci") or {}
220 context = str(ci.get("required-context") or "gate")
221 forge_kind = str((contract.get("forge") or {}).get("kind", ""))
222 approvals = governance_config(root)
223 env_names = tuple(dict.fromkeys(ci_environments(contract).values()))
224 return RepoConfig(
225 squash_only=True,
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,
240 environments=tuple(
241 EnvironmentConfig(name=name, protected_branches_only=True)
242 for name in env_names
243 ),
244 # The label `submit --every-runner` sets, so a forge that
245 # refuses a label it does not carry has it before any submit.
246 labels=(
247 Label(
248 name=EVERY_RUNNER_LABEL,
249 color="1d76db",
250 description="the gate runs every runner for this pull request",
251 ),
252 ),
253 )
254
255
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.
258GOVERNED_PATHS = (
259 "workshop.toml",
260 "CODEOWNERS",
261 ".gitea/CODEOWNERS",
262 ".github/CODEOWNERS",
263)
264
265
266def contract_changed(root: Path) -> tuple[str, ...]:
267 """The governed paths HEAD's own commit changed; empty is none.
268
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
272 fetches two.
273 """
274 changed = git.files_in_commit(root, "HEAD")
275 return tuple(
276 path
277 for path in changed
278 if path in GOVERNED_PATHS
279 or (path.startswith("packages/") and path.endswith("/workshop.toml"))
280 )
281
282
283@workflow.task(name="configure", hidden=True)
284def workflow_configure(
285 if_changed: Annotated[
286 bool, doc("only when HEAD changed a contract or the owners file")
287 ] = False,
288) -> None:
289 """Assert the contract's repository settings; idempotent drift repair.
290
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.
299 """
300 root = _root()
301 if if_changed:
302 changed = contract_changed(root)
303 if not changed:303 ↛ 306line 303 didn't jump to line 306 because the condition on line 303 was always true
304 print(" no contract or owners path changed in HEAD; nothing to reconcile")
305 return
306 print(f" governed paths changed: {', '.join(changed)}")
307 assert_configuration(root)
308
309
310def assert_configuration(root: Path) -> None:
311 """The configure flow, root-taking so birth can call it too."""
312 from livery.forge import ForgeError, Unsupported
313 from livery.workshop._forge_lane import admin_forge, admin_repository
314 from livery.workshop._governance import unknown_owners
315
316 repo, admin_var = admin_repository(root)
317 forge, _ = admin_forge(root)
318 contract = load_contract(root / "workshop.toml")
319 owner = str((contract.get("forge") or {}).get("owner", ""))
320 missing = unknown_owners(root, forge, owner)
321 if missing:
322 listed = "\n".join(f" {entry}" for entry in missing)
323 fail(
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."
327 )
328 from dataclasses import replace
329
330 config = contract_config(root)
331 if config.min_approvals is not None and not forge.supports("min_approvals"):
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.
335 print(
336 " note: this instance cannot enforce approval counts"
337 " (capability: min_approvals); the codeowners file still"
338 " names the reviewers"
339 )
340 config = replace(
341 config,
342 min_approvals=None,
343 require_codeowner_review=None,
344 dismiss_stale_reviews=None,
345 )
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
347 "dismiss_stale_reviews"
348 ):
349 print(
350 " note: this instance cannot dismiss stale approving reviews"
351 " (capability: dismiss_stale_reviews)"
352 )
353 config = replace(config, dismiss_stale_reviews=None)
354 if config.required_contexts is not None and not forge.supports("required_contexts"):
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.
358 print(
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"
362 " UI included"
363 )
364 config = replace(config, required_contexts=None)
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"):
368 print(
369 " note: this forge cannot scope CI secrets to protected"
370 " branches (capability: scoped_secrets)"
371 )
372 config = replace(config, environments=None, environment_secrets=None)
373 try:
374 repo.configure(config)
375 except Unsupported as error:
376 # A decline the probes above did not predict: name it
377 # verbatim, never half-teach a token that would not help.
378 fail(
379 f"the forge declined part of the configuration:\n{error}\n"
380 f" `{footman.prog()} doctor` says what this forge grants."
381 )
382 except ForgeError as error:
383 used = admin_var or "the everyday token"
384 fail(
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`."
390 )
391 from livery.workshop._points import job_seams
392
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
394 repo.ensure_pages(build_type="workflow")
395 print(" pages hosting asserted (workflow build type)")
396 for line in reconcile_schedules(repo, forge):
397 print(line)
398 print(" repository configuration asserted from the contract")
399
400
401#: How the reconcile names the schedules it owns; any other schedule
402#: on the repository is a person's and is never touched.
403SCHEDULE_PREFIX = "workshop: "
404
405
406def reconcile_schedules(repo: Repository, forge: Forge) -> list[str]:
407 """Make the forge's clock match the points that run on it; what was done.
408
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.
417 """
418 from livery.workshop._points import DECLARED
419
420 if not forge.supports("pipeline_schedules"):
421 return [" schedules: the clock is in the workflow file; nothing to reconcile"]
422 wanted = {
423 f"{SCHEDULE_PREFIX}{point.name}": point
424 for point in DECLARED
425 if "schedule" in point.events
426 }
427 lines: list[str] = []
428 for description, point in wanted.items():
429 schedule = repo.schedule.ensure(
430 description,
431 ref="main",
432 cron=point.cron,
433 variables={"FORGE_WORKFLOW": point.workflow},
434 )
435 lines.append(
436 f" schedule {description!r}: {schedule.cron} on {schedule.ref},"
437 f" FORGE_WORKFLOW={point.workflow}"
438 )
439 for schedule in repo.schedule.list():
440 if (
441 schedule.description.startswith(SCHEDULE_PREFIX)
442 and schedule.description not in wanted
443 ):
444 repo.schedule.delete(schedule.description)
445 lines.append(f" schedule {schedule.description!r}: deleted, no such point")
446 return lines
447
448
449def _spawn_configure() -> footman.Result:
450 """Run the configure verb in a fresh process; the reconcile's seam.
451
452 Fresh, because the abort may sit inside a workflow whose update
453 rewrote this very toolchain.
454 """
455 import sys
456
457 return footman.run(
458 [sys.executable, "-m", "livery.footman", "workflow.configure"],
459 nofail=True,
460 recorded=False,
461 cwd=_root(),
462 )
463
464
465def _reconcile_configuration(root: Path, head_sha: str) -> None:
466 """Re-assert configuration after an abort; silent when provably unneeded.
467
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.
476 """
477 from livery.workshop._governance import governance_paths
478
479 if head_sha:479 ↛ 499line 479 didn't jump to line 499 because the condition on line 479 was always true
480 try:
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(
486 root,
487 "diff",
488 "--name-only",
489 f"origin/main...{head_sha}",
490 "--",
491 "workshop.toml",
492 "packages/*/workshop.toml",
493 *[p for p in governance_paths(_root()) if "*" not in p],
494 ).strip()
495 except Exception:
496 changed = "unknown"
497 if not changed:
498 return # nothing config-implying moved: provably unneeded
499 result = _spawn_configure()
500 if result.code != 0:500 ↛ exitline 500 didn't return from function '_reconcile_configuration' because the condition on line 500 was always true
501 detail = result.stderr.strip() or result.stdout.strip() or "(no output)"
502 indented = "\n".join(f" {line}" for line in detail.splitlines())
503 print(
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"
507 f"{indented}"
508 )
509
510
511secret = workflow.group("secret", help="Place CI secrets in protected scopes")
512
513
514def place_secret(
515 root: Path,
516 name: str,
517 value: str,
518 *,
519 environment: str = "",
520 forge: Forge | None = None,
521 repo: Repository | None = None,
522) -> str:
523 """Write CI secret *name* into its protected scope on the forge.
524
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.
530
531 Returns:
532 A human-readable summary of where *name* was placed (never
533 containing *value*).
534 """
535 from livery.forge import EnvironmentConfig, ForgeError, Unsupported
536 from livery.workshop._governance import ci_environments
537 from livery.workshop._security import SECRET_ROLES
538
539 cleaned = name.strip()
540 if not cleaned:540 ↛ 541line 540 didn't jump to line 541 because the condition on line 540 was never true
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
543 fail(f"refusing to write an empty value for {cleaned}")
544
545 contract = load_contract(root / "workshop.toml")
546 kind = str((contract.get("forge") or {}).get("kind", ""))
547 envs = ci_environments(contract)
548 target_env = environment.strip()
549 if not target_env and cleaned in SECRET_ROLES:
550 target_env = envs[SECRET_ROLES[cleaned]]
551
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
553 from livery.workshop._forge_lane import admin_forge, admin_repository
554
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
559
560 if not forge.supports("scoped_secrets"):
561 fail(
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."
566 )
567
568 if kind == "github" and not target_env:
569 known = ", ".join(sorted(dict.fromkeys(envs.values())))
570 fail(
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"
574 )
575
576 env_key = target_env or "protected"
577 cfg = RepoConfig(
578 environments=(EnvironmentConfig(name=env_key, protected_branches_only=True),),
579 environment_secrets={env_key: {cleaned: value}},
580 )
581 try:
582 repo.configure(cfg)
583 except (Unsupported, ForgeError) as error:
584 fail(f"failed to store scoped secret {cleaned}:\n{error}")
585
586 if kind == "gitlab":
587 return f"{cleaned}: stored as protected CI variable (protected=True)"
588 return (
589 f"{cleaned}: stored in protected environment {target_env!r}"
590 " (protected_branches_only=True)"
591 )
592
593
594@secret.task(name="set", interactive=True)
595def workflow_secret_set(
596 name: Annotated[
597 str,
598 doc("CI secret name (e.g. FORGE_ADMIN_TOKEN, FORGE_TOKEN, PYPI_TOKEN)"),
599 ],
600 value: Annotated[
601 str,
602 doc("secret value; omitted prompts securely or reads --from-env"),
603 ] = "",
604 environment: Annotated[
605 str,
606 doc("explicit protected environment name (defaults by secret role)"),
607 ] = "",
608 from_env: Annotated[
609 bool,
610 doc("read the secret value from the local environment variable <NAME>"),
611 ] = False,
612) -> None:
613 """Place a CI secret directly into its protected scope, never repo scope.
614
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.
621 """
622 import getpass
623 import os
624
625 root = _root()
626 secret_value = value
627 if from_env and not secret_value:
628 secret_value = os.environ.get(name, "")
629 if not secret_value:
630 fail(f"--from-env requested but {name} is unset or empty")
631 if not secret_value:
632 if not footman.attended():
633 fail(
634 f"no value supplied for {name}: pass --from-env or run"
635 " interactively to enter the secret safely"
636 )
637 secret_value = getpass.getpass(f"Value for {name}: ")
638 summary = place_secret(root, name, secret_value, environment=environment)
639 print(f" {summary}")