Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 60 additions & 13 deletions .github/release/complete_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
release-please release-pr refuses new PRs while a merged release PR is pending.
Publishers own the tags, so they must also acknowledge completed release PRs.
"""
import base64
import json
import os
import subprocess
Expand All @@ -16,32 +17,78 @@ def gh_json(*args):
return json.loads(subprocess.check_output(["gh", *args], text=True))


def changed_release_paths(repo, pr):
"""{manifest path: version} for every version this merged release PR changed, or None when that cannot be read."""
try:
merge = pr["mergeCommit"]["oid"]
parent = gh_json("api", f"repos/{repo}/commits/{merge}")["parents"][0]["sha"]

def manifest(ref):
d = gh_json("api", f"repos/{repo}/contents/.release-please-manifest.json?ref={ref}")
return json.loads(base64.b64decode(d["content"]))

before, after = manifest(parent), manifest(merge)
return {path: version for path, version in after.items() if before.get(path) != version}
except Exception:
return None


def with_version(package, version):
"""The package as released at version: tags end in the version (name-vX, npm-...-vX, java-vX, go/x/vX)."""
tag = package["tag"]
if tag.endswith(package["version"]):
tag = tag[: -len(package["version"])] + version
return {**package, "version": version, "tag": tag}


def unreleased(packages, tags, skip):
"""The first reason these package versions are not fully released, or None."""
missing = [p["tag"] for p in packages if p["name"] not in skip and p["tag"] not in tags]
if missing:
return f"{len(missing)} package releases ({', '.join(missing[:5])}); finish credentials/publishing and rerun Release"
for package in packages:
if package["name"] in skip:
continue
versions = published_versions(package)
if versions is None or package["version"] not in versions:
return f"{package['name']} {package['version']} is not served by its registry"
return None


def main():
repo = os.environ["GITHUB_REPOSITORY"]
pending = gh_json("pr", "list", "--repo", repo, "--base", "main", "--state", "merged", "--label", "autorelease: pending",
"--limit", "100", "--json", "number,headRefName")
"--limit", "100", "--json", "number,headRefName,mergeCommit")
pending = [p for p in pending if p["headRefName"].startswith("release-please--branches--main")]
if not pending:
return
releases = gh_json("api", "--paginate", "--slurp", f"repos/{repo}/releases?per_page=100")
tags = {r["tag_name"] for page in releases for r in page}
skip = load_config().get("skip", {})
packages = python_packages(REPO_ROOT) + typescript_packages(REPO_ROOT) + other_packages(REPO_ROOT)
missing = [p["tag"] for p in packages if p["name"] not in skip and p["tag"] not in tags]
if missing:
print(f"Still pending: {len(missing)} package releases; finish credentials/publishing and rerun Release.")
return
for package in packages:
if package["name"] in skip:
continue
versions = published_versions(package)
if versions is None or package["version"] not in versions:
print(f"Still pending: {package['name']} {package['version']} is not served by its registry")
return
complete = []
for pr in pending:
# Each release PR is complete once the versions it changed are released, checked at the
# version it released (a later bump on main may have moved past it). A first-time package
# still waiting on its registry does not hold back unrelated release PRs. If a PR's changes
# cannot be read, it stays pending: the current checkout says nothing about what it released.
changed = changed_release_paths(repo, pr)
if changed is None:
print(f"Still pending: release PR #{pr['number']}: could not read the versions it released")
continue
required = [with_version(p, changed[path]) for p in packages if (path := p.get("release_path", p["dir"])) in changed]
reason = unreleased(required, tags, skip)
if reason:
print(f"Still pending: release PR #{pr['number']}: {reason}")
else:
complete.append(pr)
if not complete:
return
subprocess.run(["gh", "label", "create", "autorelease: tagged", "--repo", repo, "--force", "--color", "0e8a16",
"--description", "release-please: release PR whose versions are all tagged and released"], check=False)
for pr in complete:
subprocess.run(["gh", "pr", "edit", str(pr["number"]), "--repo", repo,
"--remove-label", "autorelease: pending", "--add-label", "autorelease: tagged"], check=True)


if __name__ == "__main__":
main()
23 changes: 17 additions & 6 deletions .github/release/release_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def _get_json(url: str) -> dict | None:
raise # Authentication failures, rate limits and server errors must never mean 'not published'.


def published_versions(p: dict) -> set[str] | None:
def published_versions(p: dict, *, strict: bool = True) -> set[str] | None:
eco = p["ecosystem"]
if eco == "python":
d = _get_json(f"https://pypi.org/pypi/{p['name']}/json")
Expand All @@ -219,16 +219,27 @@ def published_versions(p: dict) -> set[str] | None:
return {p["version"]} if d else None
if eco == "java":
# Query canonical repository files rather than the eventually consistent search index.
# One reactor publishes together; do not skip if any module is missing.
for artifact in p["artifacts"]:
# Verification (strict) needs every reactor artifact served. The plan's skip decision
# (strict=False) needs only the parent: the reactor is one Central deployment, Central never
# accepts a second upload of a published version, and a module added later ships with the
# next reactor version.
def on_central(artifact):
url = f"https://repo.maven.apache.org/maven2/{p['group'].replace('.', '/')}/{artifact}/{p['version']}/{artifact}-{p['version']}.pom"
try:
with urllib.request.urlopen(url, timeout=30):
pass
return True
except urllib.error.HTTPError as e:
if e.code == 404:
return None
return False
raise
parent, *modules = p["artifacts"] # other_packages lists the reactor parent first
if not on_central(parent):
return None
later = [a for a in modules if not on_central(a)]
if later and strict:
return None
if later:
print(f"{p['group']}:{parent} {p['version']} is published; {', '.join(later)} ship with the next reactor version", file=sys.stderr)
return {p["version"]}
raise ValueError(f"Unknown ecosystem: {eco}")

Expand All @@ -247,7 +258,7 @@ def plan(packages: list[dict], config: dict, *, offline: bool = False, only: set
out["skipped"].append({"name": p["name"], "reason": "Central requires com.futureagi release coordinates; merge the Java release-profile PR first"})
continue
if not offline:
have = published_versions(p)
have = published_versions(p, strict=False)
published = have is not None and p["version"] in have
if published and not include_published:
out["skipped"].append({"name": p["name"], "reason": f"{p['version']} is already published"})
Expand Down
Loading
Loading