KofTwentyTwo/ci-policy: ci / fork-guard (push) Skipped
KofTwentyTwo/ci-policy: native / fork-deny (push) Skipped
KofTwentyTwo/ci-policy: native / build-macos-0 (push) Skipped
KofTwentyTwo/ci-policy: native / build-macos-1 (push) Skipped
KofTwentyTwo/ci-policy: native / build-macos-2 (push) Skipped
KofTwentyTwo/ci-policy: native / build-macos-3 (push) Skipped
KofTwentyTwo/ci-policy: native / build-windows-4 (push) Skipped
KofTwentyTwo/ci-policy: native / build-windows-5 (push) Skipped
KofTwentyTwo/ci-policy: native / build-windows-6 (push) Skipped
KofTwentyTwo/ci-policy: native / build-windows-7 (push) Skipped
KofTwentyTwo/ci-policy: native / dotnet-8 (push) Skipped
KofTwentyTwo/ci-policy: native / dotnet-9 (push) Skipped
KofTwentyTwo/ci-policy: native / dotnet-10 (push) Skipped
KofTwentyTwo/ci-policy: native / dotnet-11 (push) Skipped
KofTwentyTwo/ci-policy: native / swift-12 (push) Skipped
KofTwentyTwo/ci-policy: native / swift-13 (push) Skipped
KofTwentyTwo/ci-policy: native / swift-14 (push) Skipped
KofTwentyTwo/ci-policy: native / swift-15 (push) Skipped
KofTwentyTwo/ci-policy: native / swift-16 (push) Skipped
KofTwentyTwo/ci-policy: native / swift-17 (push) Skipped
KofTwentyTwo/ci-policy: native / swift-18 (push) Skipped
KofTwentyTwo/ci-policy: native / swift-19 (push) Skipped
KofTwentyTwo/ci-policy: ci / Scoped workflow [workflow 487dc0a5652510eaf62e13eb643cad6de8dc2cbe] (push) Successful in 6s
KofTwentyTwo/ci-policy: native / native-result (push) Successful in 8s
KofTwentyTwo/ci-policy: ci / go-0 (push) Skipped
KofTwentyTwo/ci-policy: ci / go-nix-1 (push) Skipped
KofTwentyTwo/ci-policy: ci / gradle-2 (push) Skipped
KofTwentyTwo/ci-policy: ci / gradle-3 (push) Skipped
KofTwentyTwo/ci-policy: ci / java-docker-4 (push) Skipped
KofTwentyTwo/ci-policy: ci / java-maven-5 (push) Skipped
KofTwentyTwo/ci-policy: ci / manifests-6 (push) Skipped
KofTwentyTwo/ci-policy: ci / nix-7 (push) Skipped
KofTwentyTwo/ci-policy: ci / node-8 (push) Skipped
KofTwentyTwo/ci-policy: ci / python-9 (push) Skipped
KofTwentyTwo/ci-policy: ci / rust-10 (push) Skipped
KofTwentyTwo/ci-policy: ci / rust-11 (push) Skipped
KofTwentyTwo/ci-policy: ci / rust-12 (push) Skipped
KofTwentyTwo/ci-policy: ci / source-config-13 (push) Skipped
KofTwentyTwo/ci-policy: ci / source-config-14 (push) Skipped
KofTwentyTwo/ci-policy: ci / source-config-15 (push) Skipped
KofTwentyTwo/ci-policy: ci / image-build-0 (push) Skipped
KofTwentyTwo/ci-policy: ci / image-build-1 (push) Skipped
KofTwentyTwo/ci-policy: ci / image-build-2 (push) Skipped
KofTwentyTwo/ci-policy: ci / image-build-3 (push) Skipped
KofTwentyTwo/ci-policy: ci / image-build-4 (push) Skipped
KofTwentyTwo/ci-policy: ci / image-build-5 (push) Skipped
KofTwentyTwo/ci-policy: ci / image-build-6 (push) Skipped
KofTwentyTwo/ci-policy: ci / image-build-7 (push) Skipped
KofTwentyTwo/ci-policy: ci / content-validate-0 (push) Skipped
KofTwentyTwo/ci-policy: ci / standards-0 (push) Skipped
KofTwentyTwo/ci-policy: ci / node-matrix-0 (push) Skipped
KofTwentyTwo/ci-policy: ci / shared-pipeline (push) Skipped
KofTwentyTwo/ci-policy: ci / not-enrolled (push) Failing after 5s
KofTwentyTwo/ci-policy: ci / ci-result (push) Failing after 6s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
202 lines
9.4 KiB
Python
202 lines
9.4 KiB
Python
"""Move repositories onto ci-workflows: open PR, report status, merge green PRs.
|
|
|
|
python rollout.py open repos.txt
|
|
python rollout.py status repos.txt
|
|
python rollout.py merge repos.txt
|
|
|
|
Uses the logged-in `tea` CLI for every API call. repos.txt: one owner/name per line.
|
|
"""
|
|
|
|
import base64
|
|
import json
|
|
import subprocess
|
|
import sys
|
|
|
|
BRANCH = "ci/ci-workflows"
|
|
CALLER_PATH = ".gitea/workflows/build.yaml"
|
|
CALLER = """name: build
|
|
on:
|
|
push:
|
|
jobs:
|
|
maven:
|
|
uses: self:KofTwentyTwo/ci-workflows/.gitea/workflows/maven.yaml@v1
|
|
secrets: inherit
|
|
"""
|
|
REMOVE = [".gitea/workflows/qrun-release.yaml", ".gitea/workflows/release-rc.yaml", ".ci.yaml", ".gitea/workflows/qrun-next-release.yaml"]
|
|
MESSAGE = (
|
|
"ci: use shared ci-workflows Maven workflow\n\n"
|
|
"Replace the platform-ci release callers with one caller of\n"
|
|
"KofTwentyTwo/ci-workflows maven.yaml (qqq-orb port).\n\n"
|
|
"Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>\n"
|
|
)
|
|
|
|
|
|
def api(path, method="GET", body=None, missing_ok=False):
|
|
command = ["tea", "api", "-X", method, path]
|
|
if body is not None:
|
|
command += ["-d", json.dumps(body)]
|
|
result = subprocess.run(command, capture_output=True, text=True, encoding="utf-8")
|
|
text = result.stdout.strip()
|
|
if result.returncode != 0 or text.startswith('{"message"') or text.startswith('{"errors"'):
|
|
if missing_ok:
|
|
return None
|
|
raise RuntimeError(f"{method} {path}: {text or result.stderr.strip()}")
|
|
return json.loads(text) if text else None
|
|
|
|
|
|
def open_pr(repo, base=None):
|
|
"""Open the migration PR against `base` (default branch when omitted)."""
|
|
base = base or api(f"/repos/{repo}")["default_branch"]
|
|
branch = BRANCH if base == api(f"/repos/{repo}")["default_branch"] else f"{BRANCH}-{base}"
|
|
if api(f"/repos/{repo}/branches/{branch}", missing_ok=True):
|
|
return f"branch exists (base {base})"
|
|
def yaml_value(value):
|
|
"""Quote values YAML could misread (spaces, leading indicators); keep true/false/plain words bare."""
|
|
return json.dumps(value) if " " in value or value[:1] in "&*!|>'\"%@`{[" else value
|
|
caller = CALLER + (" with:\n" + "".join(f" {key}: {yaml_value(value)}\n" for key, value in WITH.get(repo, {}).items())
|
|
if WITH.get(repo) else "")
|
|
files = [{"operation": "create", "path": CALLER_PATH,
|
|
"content": base64.b64encode(caller.encode()).decode()}]
|
|
for path in REMOVE:
|
|
existing = api(f"/repos/{repo}/contents/{path}?ref={base}", missing_ok=True)
|
|
if existing and existing.get("sha"):
|
|
files.append({"operation": "delete", "path": path, "sha": existing["sha"]})
|
|
api(f"/repos/{repo}/contents", "POST",
|
|
{"branch": base, "new_branch": branch, "message": MESSAGE, "files": files})
|
|
pr = api(f"/repos/{repo}/pulls", "POST",
|
|
{"head": branch, "base": base, "title": "ci: use shared ci-workflows Maven workflow",
|
|
"body": "Moves this repository to KofTwentyTwo/ci-workflows (qqq-orb port), publishing to "
|
|
"the Gitea Maven registry (git.kof22.com/api/packages/QRun-IO/maven).\n\n"
|
|
"- every push: `mvn verify`\n"
|
|
"- `develop`: publishes the SNAPSHOT and commits any version bump\n"
|
|
"- `release/X.Y`: publishes `X.Y.0-RC.N` and commits the bump\n"
|
|
"- `hotfix/*`: publishes patch + 1\n"
|
|
"- **`main` only verifies; push a `vX.Y.Z` tag to publish a release**\n\n"
|
|
"Removes `qrun-release.yaml`, `release-rc.yaml` and `.ci.yaml` (old platform-ci path).\n\n"
|
|
"\U0001F916 Generated with [Claude Code](https://claude.com/claude-code)"})
|
|
return f"PR #{pr['number']} -> {base} ({len(files) - 1} files removed)"
|
|
|
|
|
|
def find_prs(repo):
|
|
"""Open or closed rollout PRs: migration (ci/ci-workflows*) and pin (ci/pin-v1-*)."""
|
|
return [pr for pr in api(f"/repos/{repo}/pulls?state=all&limit=50") or []
|
|
if pr["head"]["ref"].startswith((BRANCH, "ci/pin-v1-"))]
|
|
|
|
|
|
def build_result(repo, sha):
|
|
runs = api(f"/repos/{repo}/actions/runs?head_sha={sha}&limit=20") or {}
|
|
for run in runs.get("workflow_runs", []):
|
|
if run["path"].startswith("build.yaml") and run["head_sha"] == sha:
|
|
return run["status"], run.get("conclusion"), run["id"]
|
|
return "none", None, None
|
|
|
|
|
|
def describe(repo, pr):
|
|
state, conclusion, run_id = build_result(repo, pr["head"]["sha"])
|
|
merged = "merged" if pr.get("merged") else pr["state"]
|
|
return f"PR #{pr['number']} ->{pr['base']['ref']} {merged}; build run {run_id}: {state}/{conclusion}"
|
|
|
|
|
|
def status(repo):
|
|
prs = find_prs(repo)
|
|
return " | ".join(describe(repo, pr) for pr in prs) if prs else "no PR"
|
|
|
|
|
|
def merge(repo):
|
|
results = []
|
|
for pr in find_prs(repo):
|
|
if pr.get("merged") or pr["state"] != "open":
|
|
results.append(describe(repo, pr))
|
|
continue
|
|
state, conclusion, run_id = build_result(repo, pr["head"]["sha"])
|
|
if conclusion != "success":
|
|
results.append(f"PR #{pr['number']} not merged: build run {run_id} {state}/{conclusion}")
|
|
continue
|
|
try:
|
|
api(f"/repos/{repo}/pulls/{pr['number']}/merge", "POST",
|
|
{"Do": "merge", "delete_branch_after_merge": True})
|
|
results.append(f"merged PR #{pr['number']} ->{pr['base']['ref']}")
|
|
except RuntimeError as error: # keep going with the repository's other PRs
|
|
results.append(f"PR #{pr['number']} not merged: {error}")
|
|
return " | ".join(results) or "no PR"
|
|
|
|
|
|
def pin(repo):
|
|
"""Open PRs switching build.yaml from @main to @v1 on the default branch and develop."""
|
|
default = api(f"/repos/{repo}")["default_branch"]
|
|
targets = [default] + (["develop"] if default != "develop"
|
|
and api(f"/repos/{repo}/branches/develop", missing_ok=True) else [])
|
|
results = []
|
|
for base in targets:
|
|
current = api(f"/repos/{repo}/contents/{CALLER_PATH}?ref={base}", missing_ok=True)
|
|
if not current:
|
|
results.append(f"{base}: no build.yaml")
|
|
continue
|
|
text = base64.b64decode(current["content"]).decode()
|
|
if "maven.yaml@main" not in text:
|
|
results.append(f"{base}: already pinned")
|
|
continue
|
|
branch = f"ci/pin-v1-{base}"
|
|
if api(f"/repos/{repo}/branches/{branch}", missing_ok=True):
|
|
results.append(f"{base}: pin branch exists")
|
|
continue
|
|
api(f"/repos/{repo}/contents", "POST", {
|
|
"branch": base, "new_branch": branch,
|
|
"message": "ci: pin shared workflow to v1\n\nCo-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>\n",
|
|
"files": [{"operation": "update", "path": CALLER_PATH, "sha": current["sha"],
|
|
"content": base64.b64encode(text.replace("maven.yaml@main", "maven.yaml@v1").encode()).decode()}]})
|
|
pr = api(f"/repos/{repo}/pulls", "POST", {
|
|
"head": branch, "base": base, "title": "ci: pin shared workflow to v1",
|
|
"body": "Pins KofTwentyTwo/ci-workflows to the tested `v1` tag instead of `main`, so shared workflow "
|
|
"changes are proven on a canary before reaching this repository.\n\n"
|
|
"\U0001F916 Generated with [Claude Code](https://claude.com/claude-code)"})
|
|
results.append(f"{base}: PR #{pr['number']}")
|
|
return " | ".join(results)
|
|
|
|
|
|
def retrigger(repo):
|
|
"""Push an empty commit to each open migration PR whose build failed, to run the current workflow."""
|
|
import tempfile
|
|
results = []
|
|
for pr in find_prs(repo):
|
|
if pr.get("merged") or pr["state"] != "open":
|
|
continue
|
|
state, conclusion, run_id = build_result(repo, pr["head"]["sha"])
|
|
if conclusion not in ("failure", "cancelled"):
|
|
continue
|
|
branch = pr["head"]["ref"]
|
|
with tempfile.TemporaryDirectory() as work:
|
|
url = f"ssh://git@git.kof22.com:22/{repo}.git"
|
|
subprocess.run(["git", "clone", "-q", "--depth", "1", "--branch", branch, url, work], check=True)
|
|
subprocess.run(["git", "-C", work, "-c", "user.name=CI", "-c", "user.email=ci@kof22.com",
|
|
"commit", "-q", "--allow-empty", "-m", "ci: rerun shared workflow"], check=True)
|
|
subprocess.run(["git", "-C", work, "push", "-q", "origin", f"HEAD:{branch}"], check=True)
|
|
results.append(f"retriggered PR #{pr['number']} (run {run_id} {conclusion})")
|
|
return " | ".join(results) or "nothing to retrigger"
|
|
|
|
|
|
WITH = {} # repo -> workflow inputs, from list lines like "owner/repo publish=false browsers=true"
|
|
|
|
|
|
def main():
|
|
action, list_file = sys.argv[1], sys.argv[2]
|
|
import shlex
|
|
for line in open(list_file, encoding="utf-8"):
|
|
parts = shlex.split(line)
|
|
if len(parts) > 1:
|
|
WITH[parts[0]] = dict(part.split("=", 1) for part in parts[1:])
|
|
base = sys.argv[3] if len(sys.argv) > 3 else None
|
|
handlers = {"open": lambda repo: open_pr(repo, base), "status": status, "merge": merge,
|
|
"retrigger": retrigger, "pin": pin}
|
|
handler = handlers[action]
|
|
repos = [shlex.split(line)[0] for line in open(list_file, encoding="utf-8") if line.strip()]
|
|
for repo in repos:
|
|
try:
|
|
print(f"{repo}: {handler(repo)}", flush=True)
|
|
except Exception as error: # report and continue with the batch
|
|
print(f"{repo}: ERROR {error}", flush=True)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|