andreahlert commented on code in PR #743:
URL: https://github.com/apache/burr/pull/743#discussion_r3117759702
##########
scripts/apache_release.py:
##########
@@ -119,6 +122,255 @@ def _run_command(
_fail(f"{error_message}{error_detail}")
+def _render_template(template_name: str, context: dict[str, Any]) -> str:
+ """Render a template with Jinja2."""
+ template_path = TEMPLATES_DIR / template_name
+
+ if not template_path.exists():
+ _fail(f"Template not found: {template_path}")
+
+ from jinja2 import Environment, FileSystemLoader, StrictUndefined
+
+ environment = Environment(
+ loader=FileSystemLoader(str(TEMPLATES_DIR)),
+ autoescape=False,
+ keep_trailing_newline=True,
+ trim_blocks=True,
+ lstrip_blocks=True,
+ undefined=StrictUndefined,
+ )
+ return environment.get_template(template_name).render(**context)
+
+
+def _clipboard_commands() -> list[list[str]]:
+ """Return clipboard commands for macOS, Linux, and Windows."""
+ return [
+ ["pbcopy"], # macOS
+ ["xclip", "-selection", "clipboard"], # Linux with xclip
+ ["xsel", "--clipboard", "--input"], # Linux with xsel
+ ["clip"], # Windows
+ ]
+
+
+def _copy_to_clipboard(content: str) -> bool:
+ """Copy content to the system clipboard when a known clipboard tool
exists."""
+ for command in _clipboard_commands():
+ if shutil.which(command[0]) is None:
+ continue
+ try:
+ subprocess.run(command, input=content, text=True, check=True)
+ return True
+ except subprocess.CalledProcessError:
+ continue
+ return False
+
+
+def _emit_email_output(content: str, copy_to_clipboard: bool = False) -> None:
+ """Emit rendered email to stdout and optionally copy it to the
clipboard."""
+ print(content)
+ if copy_to_clipboard:
+ if _copy_to_clipboard(content):
+ print("\n Copied email content to clipboard", file=sys.stderr)
+ else:
+ print(
+ "\n Clipboard tool not found; email content was printed to
stdout instead",
+ file=sys.stderr,
+ )
+
+
+def _parse_semver(version: str) -> tuple[int, int, int]:
+ """Parse an X.Y.Z version string into a sortable tuple."""
+ match = re.fullmatch(r"(\d+)\.(\d+)\.(\d+)", version)
+ if not match:
+ _fail(f"Invalid version format: {version}")
+ return tuple(int(part) for part in match.groups())
+
+
+def _list_release_tags() -> list[tuple[tuple[int, int, int], str]]:
+ """List known release tags in the repository."""
+ try:
+ result = subprocess.run(
+ ["git", "tag", "--list"],
+ check=True,
+ capture_output=True,
+ text=True,
+ )
+ except subprocess.CalledProcessError:
+ return []
+
+ tags: list[tuple[tuple[int, int, int], str]] = []
+ for line in result.stdout.splitlines():
+ match = re.fullmatch(r"(?:v|burr-)(\d+\.\d+\.\d+)", line.strip())
+ if match:
+ tags.append((_parse_semver(match.group(1)), line.strip()))
+ return sorted(tags)
+
+
+def _find_previous_release_tag(version: str) -> Optional[str]:
+ """Find the most recent release tag strictly older than the requested
version."""
+ target = _parse_semver(version)
+ previous_tags = [tag for parsed, tag in _list_release_tags() if parsed <
target]
+ if not previous_tags:
+ return None
+ return previous_tags[-1]
+
+
+def _find_release_tag(version: str) -> Optional[str]:
+ """Find the exact release tag for a version, if it exists."""
+ target = _parse_semver(version)
+ matching_tags = [tag for parsed, tag in _list_release_tags() if parsed ==
target]
+ if not matching_tags:
+ return None
+ return matching_tags[-1]
+
+
+def _build_changelog_summary(
+ version: str, previous_tag: Optional[str] = None, max_entries: int = 8
+) -> str:
+ """Summarize recent commits since the prior release tag."""
+ if previous_tag is None:
+ previous_tag = _find_previous_release_tag(version)
+ release_tag = _find_release_tag(version)
+
+ if not previous_tag:
+ return "- Changelog summary unavailable; please add a short summary
before sending."
+
+ revision_range = f"{previous_tag}..{release_tag or 'HEAD'}"
+
+ try:
+ result = subprocess.run(
+ ["git", "log", revision_range, "--pretty=format:%s"],
+ check=True,
+ capture_output=True,
+ text=True,
+ )
+ except subprocess.CalledProcessError:
+ return f"- Changelog summary unavailable; review commits in
{revision_range} manually."
+
+ subjects = []
+ for line in result.stdout.splitlines():
+ cleaned = line.strip()
+ if cleaned and cleaned not in subjects:
+ subjects.append(cleaned)
+
+ if not subjects:
+ return f"- No commits found in {revision_range}; verify the tag range
before sending."
+
+ summary_lines = [f"- {subject}" for subject in subjects[:max_entries]]
+ remaining = len(subjects) - len(summary_lines)
+ if remaining > 0:
+ summary_lines.append(f"- ... plus {remaining} more commits in
{revision_range}")
+ return "\n".join(summary_lines)
+
+
+def _build_vote_deadline(hours: int = 72) -> datetime:
+ """Return the vote deadline timestamp in UTC."""
+ return datetime.now(timezone.utc) + timedelta(hours=hours)
+
+
+def _format_vote_deadline(deadline: datetime) -> str:
+ """Format the vote deadline for email output."""
+ return deadline.astimezone(timezone.utc).strftime("%Y-%m-%d %H:%M UTC")
+
+
+def _build_vote_email_context(
+ version: str,
+ rc_num: str,
+ svn_url: Optional[str] = None,
+ pypi_url: Optional[str] = None,
+ keys_url: Optional[str] = None,
+ changelog_summary: Optional[str] = None,
+ previous_tag: Optional[str] = None,
+ deadline: Optional[datetime] = None,
+) -> dict[str, str]:
+ """Build rendering context for the vote email template."""
+ version_with_incubating = f"{version}-incubating"
+ svn_url = svn_url or _build_svn_dev_url(version, rc_num)
+ deadline = deadline or _build_vote_deadline()
+ return {
+ "project_short_name": PROJECT_SHORT_NAME,
+ "project_display_name": PROJECT_SHORT_NAME.capitalize(),
+ "version": version,
+ "version_with_incubating": version_with_incubating,
+ "rc_num": rc_num,
+ "svn_url": svn_url,
+ "pypi_url": pypi_url or _build_pypi_rc_url(version, rc_num),
+ "keys_url": keys_url or _build_keys_url(),
+ "git_tag": f"v{version}-incubating-RC{rc_num}",
+ "changelog_summary": changelog_summary
+ or _build_changelog_summary(version, previous_tag=previous_tag),
+ "vote_deadline": _format_vote_deadline(deadline),
+ }
+
+
+def _build_result_email_context(
+ version: str,
+ rc_num: str,
+ binding_yes: int,
+ non_binding_yes: int,
+ abstain: int,
+ no_votes: int,
+ vote_thread_url: Optional[str] = None,
+) -> dict[str, str]:
+ """Build rendering context for the result email template."""
+ release_passed = binding_yes >= 3 and binding_yes > no_votes
Review Comment:
`no_votes` mixes binding and non-binding -1 votes, but Apache voting rules
only allow binding -1 to block a release. Concrete failure case: 3 binding +1,
2 binding -1, 3 non-binding -1 — `no_votes=5`, `3 > 5` is False, script outputs
"not passed", but the binding tally (3 vs 2) actually passes under Apache rules.
Suggested fix — split into two flags and compare only binding -1:
```python
# argparse (~line 1319) — replace --no-votes with:
result_email_parser.add_argument("--binding-no", type=int, default=0,
help="Number of binding -1 votes")
result_email_parser.add_argument("--non-binding-no", type=int, default=0,
help="Number of non-binding -1 votes")
```
```python
# _build_result_email_context — update signature and logic:
def _build_result_email_context(version, rc_num, binding_yes,
non_binding_yes, abstain, binding_no, non_binding_no, vote_thread_url=None):
release_passed = binding_yes >= 3 and binding_yes > binding_no
```
The template tally line (`-1: {{ no_votes }}`) would need updating to show
binding and non-binding -1 separately too.
🤖 Generated with [Claude Code](https://claude.ai/code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]