Skip to content

Commit 3aad4af

Browse files
authored
Add workflow to draft release notes (open-telemetry#18359)
1 parent 6b25bb0 commit 3aad4af

2 files changed

Lines changed: 78 additions & 48 deletions

File tree

.github/scripts/draft-release-notes/merge.py

Lines changed: 5 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
section and bullet, is reported on stderr and excluded.
1414
1515
By default writes to stdout. Use --splice to rewrite CHANGELOG.md in
16-
place, replacing just the `## Unreleased` block and preserving any
17-
unlinked summary bullets under `### 🚫 Deprecations` by pulling them
18-
forward into the new block.
16+
place, replacing the entire `## Unreleased` block. Any hand-written
17+
content in that block is discarded; review the resulting diff to recover
18+
anything worth keeping.
1919
"""
2020

2121
from __future__ import annotations
@@ -42,37 +42,6 @@
4242
PR_URL = "https://github.com/open-telemetry/opentelemetry-java-instrumentation/pull/{pr}"
4343

4444

45-
def extract_unlinked_deprecations(changelog_text: str) -> list[str]:
46-
"""Return bullet blocks under ## Unreleased / ### 🚫 Deprecations that
47-
have no PR link, preserving multi-line wrapping."""
48-
m = re.search(r"^## Unreleased\n(.*?)(?=^## |\Z)", changelog_text, re.S | re.M)
49-
if not m:
50-
return []
51-
unreleased = m.group(1)
52-
m = re.search(
53-
r"^### 🚫 Deprecations\n(.*?)(?=^### |\Z)",
54-
unreleased,
55-
re.S | re.M,
56-
)
57-
if not m:
58-
return []
59-
section = m.group(1)
60-
# Split into bullet blocks. A bullet starts with "- " at column 0 and runs
61-
# until the next "- " at column 0; indented lines and blank lines inside
62-
# a bullet are absorbed, anything else outside a bullet is dropped.
63-
blocks: list[list[str]] = []
64-
for line in section.splitlines():
65-
if line.startswith("- "):
66-
blocks.append([line])
67-
elif blocks and (line.startswith(" ") or not line.strip()):
68-
blocks[-1].append(line)
69-
# Keep only blocks without a PR link.
70-
return [
71-
b for b in ("\n".join(lines).rstrip() for lines in blocks)
72-
if b and not re.search(r"\[#\d+\]\(", b)
73-
]
74-
75-
7645
def load_decisions() -> list[dict]:
7746
out = []
7847
if not BUNDLE_ROOT.is_dir():
@@ -168,26 +137,17 @@ def main() -> int:
168137
continue
169138
grouped[section].append(d)
170139

171-
unlinked_deprecations: list[str] = []
172-
if args.splice and CHANGELOG.exists():
173-
unlinked_deprecations = extract_unlinked_deprecations(
174-
CHANGELOG.read_text(encoding="utf-8")
175-
)
176-
177140
out_lines = [
178141
"## Unreleased",
179142
"",
180143
]
181144

182145
for key, header in SECTION_ORDER:
183146
items = sorted(grouped[key], key=lambda d: d["pr"])
184-
preserved = unlinked_deprecations if key == "deprecations" else []
185-
if not items and not preserved:
147+
if not items:
186148
continue
187149
out_lines.append(header)
188150
out_lines.append("")
189-
for block in preserved:
190-
out_lines.append(block)
191151
for d in items:
192152
out_lines.append(format_bullet(d["bullet"], d["pr"]))
193153
out_lines.append("")
@@ -208,17 +168,14 @@ def main() -> int:
208168
new_text = text[: m.start()] + block + "\n" + text[m.end():]
209169
CHANGELOG.write_text(new_text, encoding="utf-8")
210170
bullet_count = sum(len(v) for v in grouped.values())
211-
suffix = f", {len(unlinked_deprecations)} unlinked deprecation(s) preserved" if unlinked_deprecations else ""
212-
print(f"Rewrote {CHANGELOG} ({bullet_count} PR-linked bullets{suffix})", file=sys.stderr)
171+
print(f"Rewrote {CHANGELOG} ({bullet_count} PR-linked bullets)", file=sys.stderr)
213172
else:
214173
sys.stdout.write(block)
215174

216175
if args.report:
217176
print("Section counts:", file=sys.stderr)
218177
for key, header in SECTION_ORDER:
219178
print(f" {key}: {len(grouped[key])}", file=sys.stderr)
220-
if unlinked_deprecations:
221-
print(f" unlinked-deprecations preserved: {len(unlinked_deprecations)}", file=sys.stderr)
222179

223180
return 1 if errors else 0
224181

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Draft release notes
2+
3+
on:
4+
workflow_dispatch:
5+
6+
permissions:
7+
contents: read
8+
9+
concurrency:
10+
group: draft-release-notes
11+
12+
jobs:
13+
draft:
14+
if: github.repository == 'open-telemetry/opentelemetry-java-instrumentation'
15+
runs-on: ubuntu-latest
16+
environment: protected
17+
steps:
18+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
19+
20+
- name: Install Copilot CLI
21+
run: |
22+
curl -fsSL https://gh.io/copilot-install | bash
23+
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
24+
25+
- name: Use CLA approved bot
26+
run: .github/scripts/use-cla-approved-bot.sh
27+
28+
- name: Run draft-release-notes
29+
env:
30+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31+
COPILOT_GITHUB_TOKEN: ${{ secrets.COPILOT_GITHUB_TOKEN }}
32+
run: python .github/scripts/draft-release-notes/draft-release-notes.py
33+
34+
- name: Upload draft diagnostics artifact
35+
if: always()
36+
id: upload-diagnostics
37+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
38+
with:
39+
name: draft-release-notes-diagnostics-${{ github.run_id }}
40+
path: build/changelog-bundle/**
41+
42+
- uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
43+
id: otelbot-token
44+
with:
45+
app-id: ${{ vars.OTELBOT_APP_ID }}
46+
private-key: ${{ secrets.OTELBOT_PRIVATE_KEY }}
47+
48+
- name: Create pull request against main
49+
env:
50+
ARTIFACT_URL: ${{ steps.upload-diagnostics.outputs.artifact-url }}
51+
# not using secrets.GITHUB_TOKEN since pull requests from that token do not run workflows
52+
GH_TOKEN: ${{ steps.otelbot-token.outputs.token }}
53+
run: |
54+
message="Draft release notes"
55+
body=$(cat <<EOF
56+
Automated draft of the \`## Unreleased\` section of \`CHANGELOG.md\`.
57+
58+
The entire \`## Unreleased\` block was regenerated from per-PR
59+
classifications. Review the diff to recover any hand-written
60+
content that should be retained.
61+
62+
[Download draft diagnostics]($ARTIFACT_URL)
63+
EOF
64+
)
65+
branch="otelbot/draft-release-notes-${GITHUB_RUN_ID}"
66+
67+
git checkout -b $branch
68+
git add CHANGELOG.md
69+
git commit -m "$message"
70+
git push --set-upstream origin $branch
71+
gh pr create --title "$message" \
72+
--body "$body" \
73+
--base main

0 commit comments

Comments
 (0)