Mirror script: remake a GitHub release that another account made (#310)
* Mirror script: remake a GitHub release another account made
- CI / Typecheck and bundlesuccess
- CI / Unit tests (1/2)success
- CI / Unit tests (2/2)success
- Deploy / Deploy to Cloudflaresuccess
- Deploy / Main's current tipsuccess
- End-to-end / End-to-end (agent reviews, tasks, Today)success
- End-to-end / End-to-end (git, PRs, Actions)success
- End-to-end / End-to-end (large pushes)success
- End-to-end / End-to-end (passkeys, registry, email)success
- End-to-end / End-to-end (real histories)success
- End-to-end / End-to-end (runner Docker)success
- End-to-end / End-to-end (security)success
- Live test / Containers, registry, sandboxes, webhooks, schedules, LFS and pull requestssuccess
- Mirror to GitHub / Push main to the GitHub mirrorsuccess
1 file changed+12−1
modifiedscripts/mirror-to-github.sh+12−1View file
| @@ -102,11 +102,14 @@ | ||
| 102 | 102 | req.add_header("Authorization", f"Bearer {token}") |
| 103 | 103 | try: |
| 104 | 104 | with urllib.request.urlopen(req, timeout=30) as r: |
| 105 | - return r.status, json.load(r) | |
| 105 | + data = r.read() | |
| 106 | + return r.status, json.loads(data) if data else None | |
| 106 | 107 | except urllib.error.HTTPError as e: |
| 107 | 108 | return e.code, None |
| 108 | 109 | |
| 109 | 110 | token = os.environ["GITHUB_MIRROR_TOKEN"] |
| 111 | +status, me = call("GET", f"{dst.split('/repos/')[0]}/user", token=token) | |
| 112 | +me = me.get("login") if status == 200 else None | |
| 110 | 113 | status, releases = call("GET", f"{src}/releases?per_page=100", token=os.environ.get("DIFFINERY_TOKEN")) |
| 111 | 114 | if status != 200: |
| 112 | 115 | raise SystemExit(f"could not list Diffinery releases ({status})") |
| @@ -115,6 +118,14 @@ | ||
| 115 | 118 | continue |
| 116 | 119 | want = {"name": r["name"], "body": r["body"] or "", "prerelease": r["prerelease"]} |
| 117 | 120 | status, have = call("GET", f"{dst}/releases/tags/{r['tag_name']}", token=token) |
| 121 | + if status == 200 and me and (have.get("author") or {}).get("login") != me: | |
| 122 | + # A mirrored release belongs to the mirror's account: one made by anyone else is made again. | |
| 123 | + status, _ = call("DELETE", f"{dst}/releases/{have['id']}", token=token) | |
| 124 | + if status != 204: | |
| 125 | + print(f"warning: could not replace GitHub release {r['tag_name']} ({status})") | |
| 126 | + continue | |
| 127 | + print(f"release {r['tag_name']}: deleted the copy {have['author']['login']} made") | |
| 128 | + status = 404 | |
| 118 | 129 | if status == 404: |
| 119 | 130 | status, _ = call("POST", f"{dst}/releases", {"tag_name": r["tag_name"], **want}, token) |
| 120 | 131 | print(f"release {r['tag_name']}: created ({status})") |