lean-pkg 0.25.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lean_pkg/__init__.py +3 -0
- lean_pkg/adapters/__init__.py +148 -0
- lean_pkg/adapters/github.py +65 -0
- lean_pkg/adapters/leansearch.py +68 -0
- lean_pkg/adapters/loogle.py +45 -0
- lean_pkg/adapters/palomar.py +170 -0
- lean_pkg/adapters/reservoir.py +127 -0
- lean_pkg/anchor.py +678 -0
- lean_pkg/audit.py +716 -0
- lean_pkg/binding_file.py +446 -0
- lean_pkg/blueprint.py +213 -0
- lean_pkg/build_scope.py +282 -0
- lean_pkg/ci_github.py +917 -0
- lean_pkg/claim_axioms.py +421 -0
- lean_pkg/claims.py +1155 -0
- lean_pkg/claims_mark.py +197 -0
- lean_pkg/cli.py +5208 -0
- lean_pkg/cli_parser.py +768 -0
- lean_pkg/command_tree.py +615 -0
- lean_pkg/comparator_config.py +990 -0
- lean_pkg/comparator_contracts.py +382 -0
- lean_pkg/comparator_receipt.py +2854 -0
- lean_pkg/comparator_stage.py +623 -0
- lean_pkg/comparator_types.py +830 -0
- lean_pkg/container.py +172 -0
- lean_pkg/core.py +1570 -0
- lean_pkg/coverage.py +1278 -0
- lean_pkg/data/stacks/lts-2026.10.yaml +73 -0
- lean_pkg/data/toolchain-advisories.yaml +77 -0
- lean_pkg/data/upgrade-breaking.yaml +20 -0
- lean_pkg/data/verify-workflow-pins.yaml +14 -0
- lean_pkg/deps_closure.py +512 -0
- lean_pkg/deps_fill.py +445 -0
- lean_pkg/dup_constants.py +448 -0
- lean_pkg/exercise.py +828 -0
- lean_pkg/exercise_forbid.py +288 -0
- lean_pkg/export_paths.py +77 -0
- lean_pkg/extract.py +1172 -0
- lean_pkg/extract_decls.py +501 -0
- lean_pkg/extract_ledger.py +1408 -0
- lean_pkg/extract_summary.py +132 -0
- lean_pkg/extract_types.py +502 -0
- lean_pkg/extract_write.py +138 -0
- lean_pkg/formalization.py +1078 -0
- lean_pkg/formalization_kept.py +182 -0
- lean_pkg/fresh_repo.py +709 -0
- lean_pkg/gate.py +2141 -0
- lean_pkg/headline.py +211 -0
- lean_pkg/help_topics.py +442 -0
- lean_pkg/holes.py +289 -0
- lean_pkg/host_routes.py +376 -0
- lean_pkg/hypotheses.py +788 -0
- lean_pkg/index.py +1749 -0
- lean_pkg/json_stdout.py +48 -0
- lean_pkg/lake_hygiene.py +289 -0
- lean_pkg/lean_diag.py +280 -0
- lean_pkg/lean_scan.py +1300 -0
- lean_pkg/ledger.py +582 -0
- lean_pkg/next_step.py +510 -0
- lean_pkg/page.py +1831 -0
- lean_pkg/page_html.py +153 -0
- lean_pkg/palomar.py +316 -0
- lean_pkg/palomar_check.py +1027 -0
- lean_pkg/port_modules.py +677 -0
- lean_pkg/prior_art.py +286 -0
- lean_pkg/producer.py +212 -0
- lean_pkg/producer_skew.py +208 -0
- lean_pkg/public_safety.py +1487 -0
- lean_pkg/publish.py +402 -0
- lean_pkg/rebase.py +984 -0
- lean_pkg/receipt.py +2385 -0
- lean_pkg/receipt_check.py +1064 -0
- lean_pkg/receipt_ci.py +660 -0
- lean_pkg/receipt_systemd.py +890 -0
- lean_pkg/recommended.py +232 -0
- lean_pkg/report.py +727 -0
- lean_pkg/reservoir.py +203 -0
- lean_pkg/scaffold.py +588 -0
- lean_pkg/schemas/formalization-0.4.schema.json +344 -0
- lean_pkg/schemas/formalization-0.4.schema.source.txt +15 -0
- lean_pkg/scripts/ClaimAxioms.lean +47 -0
- lean_pkg/scripts/ContractsOnly.lean +300 -0
- lean_pkg/scripts/DupConstants.lean +149 -0
- lean_pkg/scripts/HypProbe.lean +257 -0
- lean_pkg/scripts/comparator-check.sh +396 -0
- lean_pkg/scripts/verify-comparator.sh +135 -0
- lean_pkg/seal_bundle.py +647 -0
- lean_pkg/search.py +865 -0
- lean_pkg/site_profiles/easley.yaml +10 -0
- lean_pkg/site_profiles/github-actions.yaml +12 -0
- lean_pkg/sites.py +225 -0
- lean_pkg/stacks.py +373 -0
- lean_pkg/statements_module.py +217 -0
- lean_pkg/templates/Apache-2.0.txt +202 -0
- lean_pkg/toolchain_advisories.py +225 -0
- lean_pkg/upgrade.py +706 -0
- lean_pkg/verify.py +495 -0
- lean_pkg-0.25.0.dist-info/METADATA +93 -0
- lean_pkg-0.25.0.dist-info/RECORD +103 -0
- lean_pkg-0.25.0.dist-info/WHEEL +5 -0
- lean_pkg-0.25.0.dist-info/entry_points.txt +5 -0
- lean_pkg-0.25.0.dist-info/licenses/LICENSE +202 -0
- lean_pkg-0.25.0.dist-info/top_level.txt +1 -0
lean_pkg/publish.py
ADDED
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
# lean-pkg publish -- the read-only release checklist from verified-private to listed
|
|
2
|
+
"""`lean-pkg publish NAME` (#22.1): one checklist for the whole path from a verified-private
|
|
3
|
+
package to a public, tagged, listed one, composed from checks that already exist elsewhere
|
|
4
|
+
(the promotion checklist, the index license check, the formalization renderer, the claims
|
|
5
|
+
cache, `page --check`), plus the exact next commands. Read-only (`--dry-run` says so
|
|
6
|
+
explicitly): nothing is written, the registry is not locked, `--commit` is ignored. With
|
|
7
|
+
`--corroborate` the page line is rendered as `page --check --corroborate` renders it: the GitHub
|
|
8
|
+
Actions jobs coverage.yaml lists are corroborated against the public GitHub REST API (level 2),
|
|
9
|
+
the checklist's only network use. With `--attested [--trusted-root FILE]` it is rendered as `page
|
|
10
|
+
--check --attested` renders it: each job's committed Sigstore bundle is verified with `gh attestation
|
|
11
|
+
verify` (level 3), which still holds after the run has expired from the API (when `--corroborate`
|
|
12
|
+
can no longer succeed; under both flags level 3 needs both answers, so after expiry drop
|
|
13
|
+
`--corroborate`).
|
|
14
|
+
|
|
15
|
+
`publish NAME --yes` publishes: the promotion checklist, then the GitHub repository goes public
|
|
16
|
+
(the pre-1.0 `promote NAME --yes`, a permanent alias); `--yes --dry-run` runs the same checklist
|
|
17
|
+
and flips nothing (the pre-1.0 `promote NAME`). Tagging and `record` stay commands of their own.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
from __future__ import annotations
|
|
21
|
+
|
|
22
|
+
import argparse
|
|
23
|
+
import re
|
|
24
|
+
import subprocess
|
|
25
|
+
|
|
26
|
+
from . import cli, gate as gate_mod
|
|
27
|
+
from . import core
|
|
28
|
+
|
|
29
|
+
LAKEFILE_PACKAGE_RE = re.compile(r"^\s*package\s+(«[^»\n]+»|[A-Za-z_][A-Za-z0-9_'!?.-]*)", re.MULTILINE)
|
|
30
|
+
PROMOTABLE = ("verified-private",)
|
|
31
|
+
ALREADY_PUBLIC = ("public", "upstreamed")
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
# Evidence that exists on disk but is git-ignored (#40): a default `.gitignore` with `*.log` hides the
|
|
35
|
+
# comparator logs `promote` requires committed, and nobody notices until promote time.
|
|
36
|
+
STAGES_DIR = "comparator-stages"
|
|
37
|
+
IGNORE_REMEDY = ("un-ignore it: add `!.lean-receipts/` and `!**/.lean-receipts/**` to .gitignore after "
|
|
38
|
+
"the ignoring rule (a `!PATH` line for evidence elsewhere), or `git add -f PATH`")
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def evidence_paths(pkg: dict, repo) -> list[str]:
|
|
42
|
+
"""The evidence files on disk that publishing needs committed: the gate receipt, the comparator
|
|
43
|
+
receipt and its logs, the gate receipt's sealed verify log, and the comparator-stages/ files
|
|
44
|
+
(stages.json, stage logs) kept beside them."""
|
|
45
|
+
gate = pkg.get("gate") or {}
|
|
46
|
+
rels = [r for r in (gate.get("receipt"), gate.get("comparator")) if isinstance(r, str) and r]
|
|
47
|
+
comp = gate_mod.recorded_json(repo, gate.get("comparator"))
|
|
48
|
+
if isinstance(comp, dict) and isinstance(comp.get("configs"), list):
|
|
49
|
+
rels += [c["log"] for c in comp["configs"]
|
|
50
|
+
if isinstance(c, dict) and isinstance(c.get("log"), str) and c["log"]]
|
|
51
|
+
lower = gate_mod.recorded_json(repo, gate.get("receipt"))
|
|
52
|
+
if isinstance(lower, dict):
|
|
53
|
+
rels += gate_mod.report_log_rels(repo, lower)
|
|
54
|
+
dirs = {".lean-receipts"} | {r.rsplit("/", 1)[0] for r in rels if "/" in r}
|
|
55
|
+
for d in sorted(dirs):
|
|
56
|
+
base = repo / d
|
|
57
|
+
if not base.is_dir():
|
|
58
|
+
continue
|
|
59
|
+
for stages in sorted(base.rglob(STAGES_DIR)):
|
|
60
|
+
if stages.is_dir():
|
|
61
|
+
rels += [f.relative_to(repo).as_posix() for f in sorted(stages.rglob("*")) if f.is_file()]
|
|
62
|
+
seen: set[str] = set()
|
|
63
|
+
return [r for r in rels if not (r in seen or seen.add(r)) and (repo / r).is_file()]
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def ignored_evidence(repo, rels: list[str]) -> list[dict]:
|
|
67
|
+
"""[{path, rule}] for each of `rels` that git ignores (`git check-ignore -v`; tracked files are never
|
|
68
|
+
ignored); rule is SOURCE:LINE:PATTERN, e.g. `.gitignore:3:*.log`. A git failure reports nothing."""
|
|
69
|
+
if not rels:
|
|
70
|
+
return []
|
|
71
|
+
try:
|
|
72
|
+
p = subprocess.run(["git", "-C", str(repo), "check-ignore", "-v", "-z", "--stdin"],
|
|
73
|
+
input="\0".join(rels) + "\0", capture_output=True, text=True,
|
|
74
|
+
env=core.scrubbed_env(), check=False)
|
|
75
|
+
except OSError:
|
|
76
|
+
return []
|
|
77
|
+
if p.returncode not in (0, 1):
|
|
78
|
+
return []
|
|
79
|
+
f = p.stdout.split("\0")
|
|
80
|
+
out = []
|
|
81
|
+
for i in range(0, len(f) - 3, 4):
|
|
82
|
+
source, line, pattern, path = f[i:i + 4]
|
|
83
|
+
if pattern and not pattern.startswith("!"): # a matched negation means "not ignored"
|
|
84
|
+
out.append({"path": path, "rule": f"{source}:{line}:{pattern}"})
|
|
85
|
+
return out
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def ignored_evidence_item(ignored: list[dict]) -> tuple[str, str] | None:
|
|
89
|
+
"""The checklist WARN naming each ignored evidence path and its rule, with the remedy."""
|
|
90
|
+
if not ignored:
|
|
91
|
+
return None
|
|
92
|
+
return ("WARN", "evidence on disk is git-ignored, so `git add` skips it: "
|
|
93
|
+
+ ", ".join(f"{i['path']} ({i['rule']})" for i in ignored) + f"; {IGNORE_REMEDY}")
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def warn_ignored_evidence(ignored: list[dict]) -> None:
|
|
97
|
+
"""stderr WARN lines for `gate`/`comparator` when the evidence they attached is git-ignored."""
|
|
98
|
+
import sys
|
|
99
|
+
for i in ignored:
|
|
100
|
+
print(f"WARN: {i['path']} is git-ignored ({i['rule']}): `git add` skips it and `publish --yes` needs it "
|
|
101
|
+
f"committed; {IGNORE_REMEDY}", file=sys.stderr)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def lakefile_package_name(repo) -> str | None:
|
|
105
|
+
"""The Lake package name from lakefile.lean (`package NAME`) or lakefile.toml (`name = ...`)."""
|
|
106
|
+
try:
|
|
107
|
+
m = LAKEFILE_PACKAGE_RE.search((repo / "lakefile.lean").read_text(encoding="utf-8", errors="replace"))
|
|
108
|
+
if m:
|
|
109
|
+
return m.group(1).strip("«»")
|
|
110
|
+
except OSError:
|
|
111
|
+
pass
|
|
112
|
+
try:
|
|
113
|
+
import tomllib
|
|
114
|
+
name = tomllib.loads((repo / "lakefile.toml").read_text(encoding="utf-8")).get("name")
|
|
115
|
+
return str(name) if name else None
|
|
116
|
+
except (OSError, ValueError):
|
|
117
|
+
return None
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def tags_at_head(repo) -> list[str]:
|
|
121
|
+
p = core.git(repo, "tag", "--points-at", "HEAD")
|
|
122
|
+
return sorted(t for t in p.stdout.split() if t) if p.returncode == 0 else []
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def license_items(pkg: dict, repo) -> list[tuple[str, str]]:
|
|
126
|
+
from . import index as index_mod
|
|
127
|
+
spdx = pkg.get("license_spdx")
|
|
128
|
+
if not spdx:
|
|
129
|
+
return [("✗", f"license_spdx unset in the registry (`lean-pkg update {pkg['name']} --license-spdx ID`)")]
|
|
130
|
+
problem = index_mod.license_problem(repo, spdx)
|
|
131
|
+
if problem and problem.startswith("no license file"):
|
|
132
|
+
return [("✓", f"license_spdx {spdx}")] # the promote checklist already reports the missing file
|
|
133
|
+
if problem:
|
|
134
|
+
return [("✗", f"license_spdx {spdx}: {problem.replace(' at the pin', ' at the repo root')}")]
|
|
135
|
+
return [("✓", f"license_spdx {spdx}; the LICENSE file matches")]
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def formalization_items(pkg: dict, repo) -> list[tuple[str, str]]:
|
|
139
|
+
from . import formalization as fz
|
|
140
|
+
name = pkg["name"]
|
|
141
|
+
rel = pkg.get("formalization_yaml")
|
|
142
|
+
palomar = pkg.get("upstream_target") == "palomar"
|
|
143
|
+
if not rel:
|
|
144
|
+
return [("✗" if palomar else "WARN",
|
|
145
|
+
f"no formalization.yaml recorded (`lean-pkg formalization {name} --write`)"
|
|
146
|
+
+ (" — Palomar reads it" if palomar else ""))]
|
|
147
|
+
try:
|
|
148
|
+
text, doc, _w, existing = fz.render_for(pkg, repo)
|
|
149
|
+
except (core.Fail, core.UsageError) as e:
|
|
150
|
+
return [("✗", f"{rel} cannot be rendered: {str(e)[:160]}")]
|
|
151
|
+
mode, errors = fz.validate_doc(doc)
|
|
152
|
+
if errors:
|
|
153
|
+
return [("✗", f"{rel} fails the {fz.SCHEMA_VERSION} schema ({mode}): {errors[0]}")]
|
|
154
|
+
if existing is None:
|
|
155
|
+
return [("✗", f"{rel} is missing (`lean-pkg formalization {name} --write`)")]
|
|
156
|
+
if existing != text:
|
|
157
|
+
return [("✗", f"{rel} is stale: {fz.stale_hint(name, existing, text)}")]
|
|
158
|
+
placeholders = fz.find_placeholders(doc)
|
|
159
|
+
if placeholders:
|
|
160
|
+
return [("WARN", f"{rel} is current and valid ({mode}) but has {len(placeholders)} placeholder(s): "
|
|
161
|
+
+ ", ".join(placeholders[:3]))]
|
|
162
|
+
return [("✓", f"{rel} is current and valid ({mode})")]
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def claims_item(pkg: dict, repo, head: str | None) -> tuple[str, str]:
|
|
166
|
+
rel = pkg.get("claims_file") or "claims.yaml"
|
|
167
|
+
if not head or not core.tracked_at(repo, rel):
|
|
168
|
+
return ("✓", f"no {rel} tracked at HEAD (nothing to sync)")
|
|
169
|
+
synced = pkg.get("claims_synced_commit")
|
|
170
|
+
if synced:
|
|
171
|
+
ok, _note, _docs = gate_mod.package_descendant(repo, synced, head, pkg)
|
|
172
|
+
if ok:
|
|
173
|
+
return ("✓", f"claims synced at {str(synced)[:12]}")
|
|
174
|
+
return ("✗", f"{rel} not synced at HEAD {head[:12]} (`lean-pkg claims sync {pkg['name']}`)")
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def consent_item(pkg: dict) -> tuple[str, str]:
|
|
178
|
+
consent = cli.consent_unique(pkg) # one name per (who, role), however often recorded (#23.1)
|
|
179
|
+
if consent:
|
|
180
|
+
who = ", ".join(str(c.get("who")) for c in consent)
|
|
181
|
+
return ("✓", f"consent recorded ({who})")
|
|
182
|
+
return ("✗", f"no consent recorded (`lean-pkg record {pkg['name']} consent-recorded --field who=W "
|
|
183
|
+
f"--field role=R --field pointer=P`)")
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def github_remote(repo, pkg: dict) -> str | None:
|
|
187
|
+
"""The checkout's GitHub remote, found by URL (#23.2): `origin` may be a private mirror while
|
|
188
|
+
GitHub is another remote. Prefers the remote whose URL names the package's `repo`, else the
|
|
189
|
+
first github.com remote (by name); None when no remote points at GitHub."""
|
|
190
|
+
p = core.git(repo, "remote", "-v")
|
|
191
|
+
if p.returncode != 0:
|
|
192
|
+
return None
|
|
193
|
+
found: dict[str, str] = {}
|
|
194
|
+
for line in p.stdout.splitlines():
|
|
195
|
+
parts = line.split()
|
|
196
|
+
if len(parts) >= 2 and "github.com" in parts[1].lower():
|
|
197
|
+
found.setdefault(parts[0], parts[1])
|
|
198
|
+
want = core.gh_nwo(pkg.get("repo") or "")
|
|
199
|
+
for name in sorted(found):
|
|
200
|
+
if want and (core.gh_nwo(found[name]) or "").casefold() == want.casefold():
|
|
201
|
+
return name
|
|
202
|
+
return sorted(found)[0] if found else None
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
def tag_command(pkg: dict, repo) -> str:
|
|
206
|
+
"""The tag-and-push hint, naming the GitHub remote (#23.2)."""
|
|
207
|
+
name = pkg["name"]
|
|
208
|
+
tag = f"git -C {repo} tag -a vX.Y.Z -m '{name} vX.Y.Z'"
|
|
209
|
+
when = "" if pkg.get("status") in ALREADY_PUBLIC else ", after publish --yes"
|
|
210
|
+
remote = github_remote(repo, pkg)
|
|
211
|
+
if remote:
|
|
212
|
+
return f"{tag} && git -C {repo} push {remote} vX.Y.Z # push the tag to {remote} (GitHub){when}"
|
|
213
|
+
return (f"{tag} # no GitHub remote in this checkout: add one (git remote add NAME "
|
|
214
|
+
f"git@github.com:OWNER/REPO.git) and push the tag there{when}")
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def next_commands(pkg: dict, repo, ready: bool, tags: list[str]) -> list[str]:
|
|
218
|
+
name, status = pkg["name"], pkg.get("status")
|
|
219
|
+
cmds: list[str] = []
|
|
220
|
+
if not ready:
|
|
221
|
+
cmds.append(f"fix every ✗ above, then: lean-pkg publish {name} --dry-run")
|
|
222
|
+
if status in PROMOTABLE:
|
|
223
|
+
cmds += [f"lean-pkg publish {name} --yes --dry-run", f"lean-pkg publish {name} --yes # ONE-WAY"]
|
|
224
|
+
if not tags:
|
|
225
|
+
cmds.append(tag_command(pkg, repo))
|
|
226
|
+
nwo = core.gh_nwo(pkg.get("repo") or "")
|
|
227
|
+
if not pkg.get("reservoir"):
|
|
228
|
+
url = (f"https://reservoir.lean-lang.org/@{nwo}" if nwo
|
|
229
|
+
else "https://reservoir.lean-lang.org/@OWNER/NAME")
|
|
230
|
+
cmds.append(f"lean-pkg record {name} reservoir-listed --field url={url} # once Reservoir lists it")
|
|
231
|
+
if pkg.get("upstream_target") == "palomar" and not pkg.get("palomar"):
|
|
232
|
+
cmds.append(f"lean-pkg record {name} palomar-submitted --field commit=<40hex> "
|
|
233
|
+
f"--field submission_id=ID --field comparator_config=REL # after submitting")
|
|
234
|
+
return cmds
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
def do_publish_check(reg: dict, name: str, public_safety: bool = False, corroborate: bool = False,
|
|
238
|
+
fetch=None, *, attested: bool = False,
|
|
239
|
+
trusted_root: str | None = None) -> tuple[list[str], int, dict]:
|
|
240
|
+
pkg = core.get_pkg(reg, name)
|
|
241
|
+
repo = core.repo_path(pkg)
|
|
242
|
+
if not repo.is_dir():
|
|
243
|
+
raise core.Fail(f"{name}: local_path does not exist: {repo}")
|
|
244
|
+
head = core.git_head(repo)
|
|
245
|
+
if head is None:
|
|
246
|
+
raise core.Fail(f"{name}: {repo} is not a git checkout with a commit")
|
|
247
|
+
status = pkg.get("status")
|
|
248
|
+
items: list[tuple] = []
|
|
249
|
+
ignored: list[dict] = []
|
|
250
|
+
led: dict | None = None
|
|
251
|
+
if status in PROMOTABLE:
|
|
252
|
+
items.append(("✓", f"status {status}"))
|
|
253
|
+
led = {}
|
|
254
|
+
items += cli.promote_checklist(pkg, repo, ignored_sink=ignored, ledger_sink=led)
|
|
255
|
+
elif status in ALREADY_PUBLIC:
|
|
256
|
+
items.append(("✓", f"status {status} (promoted at {pkg.get('promoted_at') or '?'}); publish --yes not needed"))
|
|
257
|
+
items.append(cli.head_pushed_item(repo))
|
|
258
|
+
else:
|
|
259
|
+
items.append(("✗", f"status {status}: publishing starts from verified-private "
|
|
260
|
+
f"(`lean-pkg gate {name} --receipt R` first)"))
|
|
261
|
+
if status not in PROMOTABLE: # the promote checklist already carries this WARN
|
|
262
|
+
ignored = ignored_evidence(repo, evidence_paths(pkg, repo))
|
|
263
|
+
item = ignored_evidence_item(ignored)
|
|
264
|
+
if item:
|
|
265
|
+
items.append(item)
|
|
266
|
+
safety = None
|
|
267
|
+
if public_safety: # #35: private strings in the tree or the history
|
|
268
|
+
from . import public_safety as ps_mod
|
|
269
|
+
item, safety = ps_mod.checklist_item(pkg, repo)
|
|
270
|
+
items.append(item)
|
|
271
|
+
from . import public_safety as ps_ident # #339: the addresses the flip publishes
|
|
272
|
+
if (item := ps_ident.identity_item(repo)) is not None:
|
|
273
|
+
items.append(item)
|
|
274
|
+
items.append(consent_item(pkg))
|
|
275
|
+
items += license_items(pkg, repo)
|
|
276
|
+
items += formalization_items(pkg, repo)
|
|
277
|
+
items.append(claims_item(pkg, repo, head))
|
|
278
|
+
from . import page as page_mod
|
|
279
|
+
item, page_state = page_mod.publish_item(pkg, repo, corroborate=corroborate, fetch=fetch, attested=attested,
|
|
280
|
+
trusted_root=trusted_root)
|
|
281
|
+
items.append(item)
|
|
282
|
+
lake_name = lakefile_package_name(repo)
|
|
283
|
+
items.append(("✓", f"lakefile package name {lake_name}") if lake_name else
|
|
284
|
+
("✗", "no package name in lakefile.lean or lakefile.toml (Reservoir indexes the Lake package)"))
|
|
285
|
+
tags = tags_at_head(repo)
|
|
286
|
+
items.append(("✓", f"tag at HEAD: {', '.join(tags)}") if tags else
|
|
287
|
+
("WARN", f"no tag at HEAD {head[:12]} (tag the release after publish --yes)"))
|
|
288
|
+
deprecations = registry_opt_in_deprecations(pkg, repo)
|
|
289
|
+
for d in deprecations: # proposal 0002, stage G3: a WARN item while the opt-in is registry-only
|
|
290
|
+
items.append(("WARN", f"docs-only opt-in only in the registry record (deprecated): {d['message']}; "
|
|
291
|
+
f"migrate with {d['replacement']}"))
|
|
292
|
+
from . import palomar_check # advisory (feature request #6): a WARN item, never a ✗
|
|
293
|
+
palomar = palomar_check.summary(pkg, repo, head)
|
|
294
|
+
if warning := palomar_check.summary_warning(palomar):
|
|
295
|
+
items.append(("WARN", warning))
|
|
296
|
+
ready = not any(i[0] == "✗" for i in items)
|
|
297
|
+
cmds = next_commands(pkg, repo, ready, tags)
|
|
298
|
+
from . import ledger as ledger_mod
|
|
299
|
+
findings = (led or {}).get("manuscript_findings") or ledger_mod.package_findings(pkg, repo) # #6: no status
|
|
300
|
+
lines = [f"publish checklist for {name} ({repo}) — dry run, nothing written:"]
|
|
301
|
+
lines += [f" {i[0]} {i[1]}" for i in items]
|
|
302
|
+
fl = ledger_mod.findings_line(findings)
|
|
303
|
+
if fl:
|
|
304
|
+
lines.append(fl)
|
|
305
|
+
lines.append("ready: every check passes" if ready else "not ready: the checklist has failures")
|
|
306
|
+
lines.append("next:")
|
|
307
|
+
lines += [f" {c}" for c in cmds]
|
|
308
|
+
payload = {"ok": ready, "name": name, "dry_run": True, "ready": ready, "head": head,
|
|
309
|
+
"checklist": [dict({"status": cli._MARK_TO_STATUS[i[0]], "label": i[1]},
|
|
310
|
+
**({"reason": i[2]} if len(i) > 2 else {})) for i in items],
|
|
311
|
+
"next": cmds, "ignored_evidence": ignored, "claims_ledger": led, "manuscript_findings": findings,
|
|
312
|
+
"palomar_check": palomar, "page": page_state}
|
|
313
|
+
if safety is not None:
|
|
314
|
+
payload["public_safety"] = safety
|
|
315
|
+
if deprecations:
|
|
316
|
+
payload["deprecations"] = deprecations
|
|
317
|
+
return lines, 0 if ready else 1, payload
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
def registry_opt_in_deprecations(pkg: dict, repo) -> list[dict]:
|
|
321
|
+
"""[the deprecation] while the docs-only opt-in exists only in the registry record: docs_descendants: true
|
|
322
|
+
and no lean-pkg-binding.yaml at the gate-bound commit (HEAD when no gate receipt is readable); else []."""
|
|
323
|
+
from . import binding_file
|
|
324
|
+
if pkg.get("docs_descendants") is not True:
|
|
325
|
+
return []
|
|
326
|
+
rec = gate_mod.recorded_json(repo, (pkg.get("gate") or {}).get("receipt"))
|
|
327
|
+
commit = str(rec.get("commit") or "") if isinstance(rec, dict) else ""
|
|
328
|
+
commit = commit or core.git_head(repo) or ""
|
|
329
|
+
if not binding_file.registry_only(repo, commit, pkg):
|
|
330
|
+
return []
|
|
331
|
+
return [binding_file.registry_only_deprecation(pkg["name"], commit)]
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
def cmd_publish(args) -> int:
|
|
335
|
+
from .receipt_check import attested_usage
|
|
336
|
+
attested = getattr(args, "attested", False)
|
|
337
|
+
trusted_root = attested_usage(attested, getattr(args, "trusted_root", None))
|
|
338
|
+
if args.yes: # the promotion: the pre-1.0 `promote NAME [--yes]`
|
|
339
|
+
if getattr(args, "corroborate", False):
|
|
340
|
+
raise core.UsageError("--corroborate renders the read-only checklist's page line from corroborated "
|
|
341
|
+
"GitHub Actions runs; it does not go with --yes")
|
|
342
|
+
if attested:
|
|
343
|
+
raise core.UsageError("--attested renders the read-only checklist's page line from attested GitHub "
|
|
344
|
+
"Actions receipts; it does not go with --yes")
|
|
345
|
+
if args.public_safety:
|
|
346
|
+
raise core.UsageError("--public-safety adds the scan to the read-only checklist; --yes always runs it "
|
|
347
|
+
"(unless --skip-public-safety)")
|
|
348
|
+
return cli.cmd_promote(argparse.Namespace(**{**vars(args), "yes": not args.dry_run}))
|
|
349
|
+
extra = [f for f, on in (("--skip-public-safety", args.skip_public_safety), ("--agent", args.agent is not None))
|
|
350
|
+
if on]
|
|
351
|
+
if extra:
|
|
352
|
+
raise core.UsageError(f"{', '.join(extra)} go(es) with --yes (the read-only checklist takes no lease and "
|
|
353
|
+
f"always lists the public-safety state with --public-safety)")
|
|
354
|
+
reg_path = core.registry_path(args)
|
|
355
|
+
lines, rc, payload = do_publish_check(core.load_registry(reg_path), args.name, args.public_safety,
|
|
356
|
+
corroborate=getattr(args, "corroborate", False),
|
|
357
|
+
attested=attested, trusted_root=trusted_root)
|
|
358
|
+
from . import binding_file
|
|
359
|
+
binding_file.print_deprecations(payload)
|
|
360
|
+
for w in (payload.get("page") or {}).get("warnings") or []: # only under --attested, as page prints them
|
|
361
|
+
print(f"lean-pkg: warning: {w}", file=core.sys.stderr)
|
|
362
|
+
if getattr(args, "json_out", False):
|
|
363
|
+
core.print_json(payload)
|
|
364
|
+
else:
|
|
365
|
+
print("\n".join(lines))
|
|
366
|
+
return rc
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
def add_parsers(sub, add_json) -> None:
|
|
370
|
+
s = sub.add_parser("publish", help="the checklist from verified-private to listed, with the exact next commands "
|
|
371
|
+
"(read-only); --yes makes the repository public (`promote` is the same)")
|
|
372
|
+
s.add_argument("name")
|
|
373
|
+
s.add_argument("--yes", action="store_true",
|
|
374
|
+
help="publish: run the promotion checklist, then gh repo edit --visibility public (ONE-WAY); "
|
|
375
|
+
"first fetches origin's branches, tags and pull-request heads so the public-safety scan "
|
|
376
|
+
"covers them (a failed fetch refuses). With --dry-run: the same checklist, nothing flipped")
|
|
377
|
+
s.add_argument("--dry-run", action="store_true",
|
|
378
|
+
help="write nothing (the default without --yes); with --yes: the promotion checklist only")
|
|
379
|
+
s.add_argument("--public-safety", action="store_true",
|
|
380
|
+
help="read-only checklist: also scan the tree and git history for private patterns "
|
|
381
|
+
"(`lean-pkg public-safety`); --yes always scans")
|
|
382
|
+
s.add_argument("--corroborate", action="store_true",
|
|
383
|
+
help="read-only checklist: render the page line as `page --check --corroborate` does, asking "
|
|
384
|
+
"the public GitHub REST API about each GitHub Actions job (level 2), so a README carrying "
|
|
385
|
+
"the GitHub Actions sentence can pass; GH_TOKEN or GITHUB_TOKEN only raises the rate limit")
|
|
386
|
+
s.add_argument("--attested", action="store_true",
|
|
387
|
+
help="read-only checklist: render the page line as `page --check --attested` does, verifying "
|
|
388
|
+
"each GitHub Actions job's committed Sigstore bundle with `gh attestation verify` (level "
|
|
389
|
+
"3), which holds after the run has expired from the API; with --corroborate too, level 2 "
|
|
390
|
+
"must also hold, so after expiry drop --corroborate")
|
|
391
|
+
s.add_argument("--trusted-root", default=None, metavar="FILE",
|
|
392
|
+
help="with --attested: verify offline against this Sigstore trusted root (gh attestation "
|
|
393
|
+
"verify --custom-trusted-root)")
|
|
394
|
+
s.add_argument("--skip-public-safety", action="store_true",
|
|
395
|
+
help="with --yes: do not run the public-safety scan of the tree and history (a WARN line "
|
|
396
|
+
"instead; the scan covers the whole repository when the package is a subdirectory of it)")
|
|
397
|
+
s.add_argument("--agent", default=None,
|
|
398
|
+
help="with --yes: the agent acting (recorded as the promoted event's actor); another agent's "
|
|
399
|
+
"live lease then refuses")
|
|
400
|
+
add_json(s)
|
|
401
|
+
s.set_defaults(fn=cmd_publish)
|
|
402
|
+
|