feat(site-publish): scope publication with an artifacts selection
Test / contract (pull_request) Successful in 7s
Test / contract (pull_request) Successful in 7s
A repository whose artifacts ship on different cadences has no way to publish one of them. Baseline needs it: every merge to main must put the catalogue live in under five minutes, while `dist/` is content-addressed and may only be written by a tag release. Today the action iterates cfg["artifacts"] unconditionally, so the only lever is deleting the distributions artifact from site.yaml — which changes the stored publication contract and drives the route-retirement path. The new `artifacts:` input names the subset this run builds and publishes. Selection scopes the build, the immutable preflight, the CORS reconcile, the S3 sync, and credential resolution. It deliberately does not scope manifest rendering or the immutable-path history: those stay whole, so a scoped run can never retire another artifact's route or delete its bucket contents. An undeclared name fails before the first bucket is touched; `enabled: false` refuses a selection because decommissioning is whole-site. Default is unchanged: no input publishes every declared artifact. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UjQqc4qFmdpAWaYfy2Aypb
This commit is contained in:
co-authored by
Claude Fable 5.1
parent
9287e4861a
commit
3dfee64335
@@ -274,6 +274,7 @@ def _legacy_config(raw, site_name):
|
||||
"aliases": _aliases(raw.get("aliases"), raw["domain"]),
|
||||
"enabled": raw.get("enabled", True),
|
||||
"artifacts": [artifact],
|
||||
"selected": ["site"],
|
||||
"routes": [{
|
||||
"name": "site", "path": "/", "artifact": "site", "access": "legacy",
|
||||
"access_middleware": None,
|
||||
@@ -457,6 +458,33 @@ def _validate_multi(cfg):
|
||||
raise ConfigError("a public '/' catch-all would expose unmatched protected content")
|
||||
|
||||
|
||||
def _artifact_selection(cfg, requested):
|
||||
"""Resolve the subset of declared artifacts this run publishes."""
|
||||
declared = [artifact["name"] for artifact in cfg["artifacts"]]
|
||||
if not requested or not requested.strip():
|
||||
return declared
|
||||
names = [part for part in re.split(r"[,\s]+", requested.strip()) if part]
|
||||
unknown = sorted({name for name in names if name not in declared})
|
||||
if unknown:
|
||||
raise ConfigError(
|
||||
"artifacts selects undeclared artifact(s) " + ", ".join(unknown)
|
||||
+ "; site.yaml declares " + ", ".join(declared)
|
||||
)
|
||||
return [name for name in declared if name in set(names)]
|
||||
|
||||
|
||||
def selected_artifacts(cfg):
|
||||
"""Artifacts this run builds and publishes, in declaration order."""
|
||||
chosen = set(cfg["selected"])
|
||||
return [artifact for artifact in cfg["artifacts"] if artifact["name"] in chosen]
|
||||
|
||||
|
||||
def selected_routes(cfg):
|
||||
"""Routes whose artifact this run publishes, in route order."""
|
||||
chosen = set(cfg["selected"])
|
||||
return [route for route in cfg["routes"] if route["artifact"] in chosen]
|
||||
|
||||
|
||||
def normalize_site_config(raw, site_name):
|
||||
raw = _mapping(raw, "site.yaml")
|
||||
domain = _hostname(raw.get("domain"), "domain")
|
||||
@@ -482,6 +510,7 @@ def normalize_site_config(raw, site_name):
|
||||
"routes": sorted(routes, key=lambda item: (-len(item["path"]), item["path"], item["name"])),
|
||||
}
|
||||
_validate_multi(cfg)
|
||||
cfg["selected"] = [artifact["name"] for artifact in cfg["artifacts"]]
|
||||
for route in cfg["routes"]:
|
||||
if len(f"{k8s_name(site_name)}-{route['name']}") > 63:
|
||||
raise ConfigError(f"route {route['name']} makes the generated Service name exceed 63 characters")
|
||||
@@ -534,12 +563,14 @@ def parse_site_yaml(site_dir, site_name=None):
|
||||
try:
|
||||
with open(path) as stream:
|
||||
cfg = normalize_site_config(yaml.safe_load(stream), site_name)
|
||||
cfg["selected"] = _artifact_selection(cfg, os.environ.get("SITE_ARTIFACTS"))
|
||||
except (ConfigError, yaml.YAMLError) as exc:
|
||||
die(str(exc))
|
||||
print("Site config:")
|
||||
print(f" domain: {cfg['domain']}")
|
||||
print(f" contract: {cfg['compatibility'] or 'split-surface-v2'}")
|
||||
print(f" artifacts: {[item['name'] for item in cfg['artifacts']]}")
|
||||
print(f" publishing: {cfg['selected']}")
|
||||
print(f" routes: {[(item['path'], item['access']) for item in cfg['routes']]}")
|
||||
return cfg
|
||||
|
||||
|
||||
Reference in New Issue
Block a user