forked from wrenn/wrenn
v0.1.4 (#38) — pipeline test
This commit is contained in:
241
.woodpecker/scripts/release_notes.py
Normal file
241
.woodpecker/scripts/release_notes.py
Normal file
@ -0,0 +1,241 @@
|
||||
import base64
|
||||
import os
|
||||
import sys
|
||||
|
||||
from wrenn import Capsule
|
||||
|
||||
REPO_URL = "https://git.omukk.dev/tksadik92/wrenn-releases.git"
|
||||
REPO_DIR = "/opt/wrenn-releases"
|
||||
CAPSULE_OUTPUT = "/tmp/release_notes.md"
|
||||
LOCAL_OUTPUT = os.path.join(os.path.dirname(__file__), "..", "release_notes.md")
|
||||
ZHIPU_API_KEY = os.environ.get("ZHIPU_API_KEY", "")
|
||||
|
||||
if ZHIPU_API_KEY:
|
||||
DEFAULT_MODEL = "zhipuai-coding-plan/glm-5.1"
|
||||
auth_env = f"ZHIPU_API_KEY={ZHIPU_API_KEY}"
|
||||
else:
|
||||
DEFAULT_MODEL = "opencode/minimax-m2.5-free"
|
||||
|
||||
RELEASE_NOTES_EXAMPLE = """
|
||||
## What's new
|
||||
Sandbox HTTP proxying, terminal reliability, and auth robustness improvements.
|
||||
|
||||
### Proxy
|
||||
- Fixed redirect loops for apps served inside sandboxes (Python HTTP server, Jupyter, etc.)
|
||||
- Proxy traffic no longer interferes with terminal and exec connections
|
||||
- Services that take a moment to start up inside a sandbox are now retried instead of immediately failing
|
||||
|
||||
### Terminal (PTY)
|
||||
- Terminal input is no longer blocked by slow network conditions — fast typing no longer causes timeouts or disconnects
|
||||
- Input bursts are coalesced into fewer round trips — lower latency under fast typing
|
||||
|
||||
### Authentication
|
||||
- WebSocket connections now authenticate correctly for both SDK clients (header-based) and browser clients (message-based)
|
||||
|
||||
### Bug Fixes
|
||||
- Fixed crash in envd when a process exits without a PTY
|
||||
- Fixed goroutine leak on sandbox pause
|
||||
|
||||
### Others
|
||||
- Version bump
|
||||
""".strip()
|
||||
|
||||
|
||||
def run(capsule: Capsule, cmd: str, cwd: str | None = None, timeout: int = 30) -> int:
|
||||
result = capsule.commands.run(cmd, cwd=cwd, timeout=timeout)
|
||||
if result.exit_code != 0:
|
||||
print(f"FAIL [{cmd.split()[0]}]: exit={result.exit_code}", file=sys.stderr)
|
||||
if result.stderr:
|
||||
print(result.stderr.strip(), file=sys.stderr)
|
||||
return result.exit_code
|
||||
print(f"OK [{cmd.split()[0]}]")
|
||||
return 0
|
||||
|
||||
|
||||
def install_opencode(capsule: Capsule) -> None:
|
||||
print("Installing OpenCode...")
|
||||
if run(capsule, "apt update", timeout=60) != 0:
|
||||
sys.exit(1)
|
||||
if (
|
||||
run(
|
||||
capsule,
|
||||
"curl -fsSL https://opencode.ai/install | bash -s -- --version 1.14.31",
|
||||
timeout=120,
|
||||
)
|
||||
!= 0
|
||||
):
|
||||
sys.exit(1)
|
||||
print("OK [opencode installed]")
|
||||
|
||||
|
||||
def get_tags(capsule: Capsule) -> tuple[str, str | None]:
|
||||
result = capsule.commands.run(
|
||||
f"cd {REPO_DIR} && git tag --sort=-version:refname",
|
||||
cwd=REPO_DIR,
|
||||
timeout=30,
|
||||
)
|
||||
if result.exit_code != 0:
|
||||
print(f"FAIL [git tag]: {result.stderr}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
tags = [t for t in result.stdout.strip().split("\n") if t]
|
||||
if not tags:
|
||||
print("No tags found", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
current_tag = tags[0]
|
||||
previous_tag = tags[1] if len(tags) > 1 else None
|
||||
print(f"Current tag: {current_tag}")
|
||||
print(f"Previous tag: {previous_tag}")
|
||||
return current_tag, previous_tag
|
||||
|
||||
|
||||
def get_git_context(
|
||||
capsule: Capsule, current_tag: str, previous_tag: str | None
|
||||
) -> tuple[str, str]:
|
||||
if previous_tag:
|
||||
log_cmd = f"cd {REPO_DIR} && git log {previous_tag}..{current_tag} --pretty=format:'%s (%h)' -n 2"
|
||||
else:
|
||||
log_cmd = (
|
||||
f"cd {REPO_DIR} && git log {current_tag} --pretty=format:'%s (%h)' -n 2"
|
||||
)
|
||||
|
||||
log_result = capsule.commands.run(log_cmd, cwd=REPO_DIR, timeout=30)
|
||||
if log_result.exit_code != 0:
|
||||
print(f"FAIL [git log]: {log_result.stderr}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
if previous_tag:
|
||||
diff_cmd = f"cd {REPO_DIR} && git diff {previous_tag}..{current_tag} --stat"
|
||||
else:
|
||||
diff_cmd = f"cd {REPO_DIR} && git show {current_tag} --stat"
|
||||
|
||||
diff_result = capsule.commands.run(diff_cmd, cwd=REPO_DIR, timeout=30)
|
||||
if diff_result.exit_code != 0:
|
||||
print(f"FAIL [git diff]: {diff_result.stderr}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
return log_result.stdout.strip(), diff_result.stdout.strip()
|
||||
|
||||
|
||||
def generate_release_notes(
|
||||
capsule: Capsule,
|
||||
current_tag: str,
|
||||
git_log: str,
|
||||
git_diff: str,
|
||||
output_path: str,
|
||||
model: str,
|
||||
) -> None:
|
||||
prompt = (
|
||||
f"You are writing release notes for version {current_tag} of a software project.\n\n"
|
||||
f"Here is what changed between the previous version and this one:\n\n"
|
||||
f"Commit messages:\n{git_log}\n\n"
|
||||
f"Files and areas that changed:\n{git_diff}\n\n"
|
||||
f"Write the release notes in plain, friendly language that any developer can understand "
|
||||
f"without deep knowledge of the codebase. Avoid jargon like 'goroutine', 'PTY', 'envd', "
|
||||
f"or internal function names — describe what the change means for the user instead. "
|
||||
f"Group related changes under headings that reflect what actually changed. "
|
||||
f"Only include sections that are relevant to these specific changes. "
|
||||
f"Start with a short one-line summary of what this release is about. "
|
||||
f"Keep each bullet point to one clear sentence.\n\n"
|
||||
f"Here is an example of the style to aim for — not a template to copy:\n\n"
|
||||
f"{RELEASE_NOTES_EXAMPLE}\n\n"
|
||||
f"You MUST start the document with `## What's New`\n"
|
||||
f"The very next line MUST be a single short summary sentence.\n"
|
||||
f"Output only the markdown. No intro, no explanation."
|
||||
f"CRITICAL: Do not output any conversational filler, acknowledgments, or thoughts "
|
||||
f"like 'Let me look at the changes'. Output absolutely nothing except the final markdown."
|
||||
)
|
||||
|
||||
prompt_b64 = base64.b64encode(prompt.encode("utf-8")).decode("utf-8")
|
||||
|
||||
write_prompt_cmd = f"echo '{prompt_b64}' | base64 -d > /tmp/oc_prompt.txt"
|
||||
|
||||
result = capsule.commands.run(
|
||||
write_prompt_cmd,
|
||||
cwd=REPO_DIR,
|
||||
timeout=10,
|
||||
)
|
||||
if result.exit_code != 0:
|
||||
print(f"FAIL [write prompt]: {result.stderr}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
result = capsule.commands.run("~/.opencode/bin/opencode models", timeout=30)
|
||||
print(f"STDOUT:\n{result.stdout}", file=sys.stderr)
|
||||
print(f"STDERR:\n{result.stderr}", file=sys.stderr)
|
||||
|
||||
opencode_cmd = (
|
||||
f"{auth_env} "
|
||||
f"~/.opencode/bin/opencode run "
|
||||
f'"Read the attached file and generate the release notes. Output ONLY markdown." '
|
||||
f"--model {model} "
|
||||
f"--file /tmp/oc_prompt.txt "
|
||||
f"> {output_path}"
|
||||
)
|
||||
|
||||
result = capsule.commands.run(
|
||||
opencode_cmd,
|
||||
cwd=REPO_DIR,
|
||||
timeout=120,
|
||||
)
|
||||
if result.exit_code != 0:
|
||||
print(f"FAIL [opencode]: exit={result.exit_code}", file=sys.stderr)
|
||||
print(f"STDOUT:\n{result.stdout}", file=sys.stderr)
|
||||
print(f"STDERR:\n{result.stderr}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
result = capsule.commands.run(f"cat {output_path}")
|
||||
print(result.stdout)
|
||||
print(result.stderr)
|
||||
|
||||
print(f"OK [opencode] release notes written to {output_path}")
|
||||
|
||||
|
||||
def download_release_notes(capsule: Capsule) -> None:
|
||||
local_path = os.path.normpath(LOCAL_OUTPUT)
|
||||
os.makedirs(os.path.dirname(local_path), exist_ok=True)
|
||||
|
||||
print(f"Downloading release notes from capsule...")
|
||||
content = capsule.files.read_bytes(CAPSULE_OUTPUT)
|
||||
with open(local_path, "wb") as f:
|
||||
f.write(content)
|
||||
|
||||
print(f"OK [download] release notes → {local_path}")
|
||||
print(content.decode("utf-8", errors="replace"))
|
||||
|
||||
|
||||
def main() -> None:
|
||||
# gitea_token = os.environ["GITEA_TOKEN"]
|
||||
# minimax_api_key = os.environ["MINIMAX_API_KEY"]
|
||||
model = os.environ.get("OPENCODE_MODEL", DEFAULT_MODEL)
|
||||
|
||||
with Capsule(wait=True, vcpus=2, memory_mb=2048) as capsule:
|
||||
print(f"Capsule: {capsule.capsule_id}")
|
||||
|
||||
install_opencode(capsule)
|
||||
|
||||
capsule.git.clone(
|
||||
REPO_URL,
|
||||
REPO_DIR,
|
||||
username="tksadik92",
|
||||
)
|
||||
print("OK [git clone]")
|
||||
|
||||
current_tag, previous_tag = get_tags(capsule)
|
||||
git_log, git_diff = get_git_context(capsule, current_tag, previous_tag)
|
||||
|
||||
output_path = os.path.normpath(CAPSULE_OUTPUT)
|
||||
os.makedirs(os.path.dirname(output_path), exist_ok=True)
|
||||
|
||||
generate_release_notes(
|
||||
capsule,
|
||||
current_tag,
|
||||
git_log,
|
||||
git_diff,
|
||||
output_path,
|
||||
model,
|
||||
)
|
||||
|
||||
download_release_notes(capsule)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user