feat(tools): verbose mode for sync-registry-secrets

This commit is contained in:
fork-sync[bot]
2026-09-16 23:01:34 +02:00
parent 54d7506a30
commit fdacc08649
+7 -18
View File
@@ -1,17 +1,6 @@
#!/usr/bin/env python3
"""
sync-registry-secrets: propagate REGISTRY_USERNAME / REGISTRY_TOKEN (and
REGISTRY_PASSWORD) secrets to every Gitea repo that uses them in its Actions
workflows.
For every repo returned by GET /api/v1/repos/search (paginated) we inspect
.gitea/workflows/*.yml and .github/workflows/*.yml via the raw content API.
Workflows that reference secrets.REGISTRY_USERNAME, REGISTRY_TOKEN, or
REGISTRY_PASSWORD (and don't already have those secrets set on the repo)
get the secret PUT via /api/v1/repos/{owner}/{repo}/actions/secrets/{name}.
SECRETS_SYNCER_TOKEN env is required and must have admin-level write access
to target repos and orgs.
sync-registry-secrets: verbose-mode version.
"""
import json
import os
@@ -120,12 +109,6 @@ def main():
SECRET_VALUES["REGISTRY_USERNAME"] = os.environ.get("REGISTRY_USERNAME_VALUE", "")
SECRET_VALUES["REGISTRY_TOKEN"] = os.environ.get("REGISTRY_TOKEN_VALUE", "")
SECRET_VALUES["REGISTRY_PASSWORD"] = os.environ.get("REGISTRY_PASSWORD_VALUE", "")
for sn, v in SECRET_VALUES.items():
preview = ("(" + str(len(v)) + " chars)" if v else "(empty)")
print(f" secret env: {sn!r} {preview}", file=sys.stderr)
if not any(SECRET_VALUES.values()):
print("no REGISTRY_*_VALUE env vars set", file=sys.stderr)
return 1
repos = list_my_repos(LIMIT)
print(f"scanning {len(repos)} repos", file=sys.stderr)
@@ -140,6 +123,7 @@ def main():
continue
wf_files = list_workflow_files(full_name)
if not wf_files:
print(f"skip {full_name}: no workflow files", file=sys.stderr)
continue
referenced = set()
for path, _ in wf_files:
@@ -147,16 +131,21 @@ def main():
if workflow_uses_secret(full_name, path, sn):
referenced.add(sn)
if not referenced:
print(f"skip {full_name}: no REGISTRY_* refs (wf_files={len(wf_files)})", file=sys.stderr)
continue
print(f"{full_name}: needs {sorted(referenced)}", file=sys.stderr)
for sn in sorted(referenced):
value = SECRET_VALUES.get(sn)
if not value:
print(f" skip {sn}: no value in env", file=sys.stderr)
skipped.append((full_name, sn, "no value in env"))
continue
if secret_exists(full_name, sn):
print(f" skip {sn}: already present", file=sys.stderr)
skipped.append((full_name, sn, "already present"))
continue
status, body = put_secret(full_name, sn, value)
print(f" PUT {sn}: status={status} body[:200]={body[:200]!r}", file=sys.stderr)
if status in (200, 201, 204):
synced.append((full_name, sn, status))
else: