|
| 1 | +import yaml |
| 2 | +from jinja2 import Template |
| 3 | + |
| 4 | +import requests |
| 5 | +import os |
| 6 | + |
| 7 | +GITHUB_TOKEN = os.environ.get("GITHUB_TOKEN") |
| 8 | +HEADERS = { |
| 9 | + "Authorization": f"Bearer {GITHUB_TOKEN}", |
| 10 | + "Accept": "application/vnd.github+json" |
| 11 | +} |
| 12 | + |
| 13 | +def get_commit_sha_from_tag(repo, tag): |
| 14 | + tag_url = f"https://api.github.com/repos/{repo}/git/ref/tags/{tag}" |
| 15 | + tag_data = requests.get(tag_url, headers=HEADERS).json() |
| 16 | + if tag_data.get("object", {}).get("type") == "tag": |
| 17 | + tag_obj_url = tag_data["object"]["url"] |
| 18 | + tag_obj = requests.get(tag_obj_url, headers=HEADERS).json() |
| 19 | + return tag_obj["object"]["sha"] |
| 20 | + else: |
| 21 | + return tag_data["object"]["sha"] |
| 22 | + |
| 23 | +def get_pr_for_commit(repo, sha): |
| 24 | + pr_url = f"https://api.github.com/repos/{repo}/commits/{sha}/pulls" |
| 25 | + pr_data = requests.get(pr_url, headers={ |
| 26 | + **HEADERS, |
| 27 | + "Accept": "application/vnd.github.groot-preview+json" |
| 28 | + }).json() |
| 29 | + return pr_data[0] if pr_data else None |
| 30 | + |
| 31 | +def get_ci_checks_for_commit(repo, sha): |
| 32 | + checks_url = f"https://api.github.com/repos/{repo}/commits/{sha}/check-runs" |
| 33 | + check_data = requests.get(checks_url, headers=HEADERS).json() |
| 34 | + return [ |
| 35 | + { |
| 36 | + "name": c["name"], |
| 37 | + "url": c["html_url"], |
| 38 | + "status": c["conclusion"] |
| 39 | + } |
| 40 | + for c in check_data.get("check_runs", []) |
| 41 | + ] |
| 42 | + |
| 43 | +with open("release-llm-d-1.1.0.yaml") as f: |
| 44 | + data = yaml.safe_load(f) |
| 45 | + |
| 46 | +for c in data["components"]: |
| 47 | + if c.get("old_version") == c.get("version"): |
| 48 | + c["has_changes"] = False |
| 49 | + continue |
| 50 | + |
| 51 | + c["has_changes"] = True |
| 52 | + c["ci_url"] = f"https://github.com/{c['repo']}/actions?query=event:push+tag:{c['version']}" |
| 53 | + if c.get("old_version"): |
| 54 | + c["changelog_url"] = f"https://github.com/{c['repo']}/compare/{c['old_version']}...{c['version']}" |
| 55 | + |
| 56 | + try: |
| 57 | + sha = get_commit_sha_from_tag(c["repo"], c["version"]) |
| 58 | + pr = get_pr_for_commit(c["repo"], sha) |
| 59 | + c["commit_sha"] = sha |
| 60 | + c["pr_number"] = pr["number"] if pr else None |
| 61 | + c["ci_checks"] = get_ci_checks_for_commit(c["repo"], sha) |
| 62 | + except Exception as e: |
| 63 | + print(f"⚠️ Failed to get CI info for {c['name']}: {e}") |
| 64 | + c["ci_checks"] = [] |
| 65 | + |
| 66 | + |
| 67 | +template = Template(""" |
| 68 | +# 📦 llm-d {{ project_version }} Release Notes |
| 69 | +
|
| 70 | +**Release Date:** {{ release_date }} |
| 71 | +**Chart Version:** {{ chart_version }} |
| 72 | +
|
| 73 | +--- |
| 74 | +
|
| 75 | +## 🧩 Component Summary |
| 76 | +
|
| 77 | +| Component | Version | Previous Version | |
| 78 | +|-----------|---------|------------------| |
| 79 | +{% for c in components -%} |
| 80 | +| {{ c.name }} | `{{ c.version }}` | `{{ c.old_version or "-" }}` | |
| 81 | +{% endfor %} |
| 82 | +
|
| 83 | +--- |
| 84 | +
|
| 85 | +{%- for c in components %} |
| 86 | +## 🔹 {{ c.name }} |
| 87 | +
|
| 88 | +{%- if c.has_changes %} |
| 89 | +- **Changelog**: [{{ c.old_version }} → {{ c.version }}]({{ c.changelog_url }}) |
| 90 | +{%- else %} |
| 91 | +_No version change in this release._ |
| 92 | +{%- endif %} |
| 93 | +
|
| 94 | +- **CI Checks:** |
| 95 | +{%- if c.ci_checks %} |
| 96 | +{%- for check in c.ci_checks %} |
| 97 | + - [{{ check.name }}]({{ check.url }}) [`{{ check.status }}`] |
| 98 | +{%- endfor %} |
| 99 | +{%- else %} |
| 100 | + - _No CI checks found_ |
| 101 | +{%- endif %} |
| 102 | +
|
| 103 | +--- |
| 104 | +{%- endfor %} |
| 105 | +""") |
| 106 | + |
| 107 | +output = template.render(**data) |
| 108 | + |
| 109 | +filename = f"release-{data['project_version']}.md" |
| 110 | + |
| 111 | +with open(filename, "w") as f: |
| 112 | + f.write(output) |
| 113 | + |
| 114 | +print(f"✅ Release notes written to {filename}") |
0 commit comments