Skip to content
Closed
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
89 changes: 18 additions & 71 deletions .cursor/skills/release/SKILL.md
Original file line number Diff line number Diff line change
@@ -1,90 +1,37 @@
---
name: release
description: >-
Prepares a version bump in pyproject.toml, opens a PR from branch release/VERSION
toward main with auto-merge, and coordinates with CI that publishes a GitHub Release
when that branch merges. Use when the user invokes /release, /release VERSION, asks
for a release PR, version bump, or release automation.
Cuts a release with the Prepare release workflow. That workflow opens a
release/VERSION pull request for a person to merge. Merging publishes to
PyPI and tags vVERSION. Use when the user invokes /release, /release VERSION,
asks for a release PR, version bump, or release automation.
---

# Release (`/release` and optional VERSION)
# Release

## When this applies
Follow `RELEASING.md` at the repository root. Leave the pull request for a person to merge.

- User message starts with **`/release`** or **`/release VERSION`** (VERSION optional).
- User asks to cut a release, bump the package version, or open a release PR with auto-merge.
## Version

## Preconditions

- Working tree clean (`git status`); stash or commit unrelated work first.
- `gh` CLI authenticated (`gh auth status`).
- Remote `origin` is GitHub.
- Repository allows **auto-merge** (Settings → General → Pull Requests → Allow auto-merge). If auto-merge is unavailable, open the PR anyway and tell the user to merge manually after checks pass.

## Version selection

1. Read the current version from `pyproject.toml` under `[project]` → `version` (PEP 440 / semver `MAJOR.MINOR.PATCH`).
2. If **VERSION was provided**: set the new version to that string (must match `^\d+\.\d+\.\d+` unless the project already uses a different scheme—then follow existing `pyproject.toml` format).
3. If **VERSION was omitted**: bump the **patch** segment only (e.g. `0.2.1` → `0.2.2`). If the current value is not `x.y.z`, stop and ask the user for an explicit VERSION.
Read `[project].version` in `pyproject.toml`. `/release` with no version means `patch`. `/release X.Y.Z` uses that version. The value is `X.Y.Z`, `patch`, `minor`, or `major`.

## Git identity (this repo)

Configure once if needed:
## Preconditions

```bash
git config user.email "cursor@proxymesh.com"
git config user.name "Cursor"
```
- `## Unreleased` in `CHANGELOG.md` on `main` already contains the release notes.
- `gh` CLI authenticated.
- Prepare release is on `main` (`.github/workflows/prepare-release.yml`).

## Steps

1. **Sync main**

```bash
git fetch origin main
```

2. **Compute** `NEW_VERSION` (per rules above). **Branch name** is `release/${NEW_VERSION}` (no `v` prefix in the branch name).

3. **Create branch from latest main**

```bash
git checkout -B "release/${NEW_VERSION}" origin/main
```

4. **Edit** `pyproject.toml`: set `version = "NEW_VERSION"` in `[project]`.

5. **Commit and push** (never push to `main`; push only the release branch)

```bash
git add pyproject.toml
git commit -m "chore: bump version to ${NEW_VERSION}"
git push -u origin "release/${NEW_VERSION}"
```

6. **Open PR** into `main` with a short body (no Cursor boilerplate). Example:
1. Run Prepare release from `main`:

```bash
gh pr create --base main --head "release/${NEW_VERSION}" \
--title "Release ${NEW_VERSION}" \
--body "Bumps the package version to ${NEW_VERSION} for release."
gh workflow run "Prepare release" --ref main -f version=VERSION
```

7. **Enable auto-merge** after the PR exists. In non-interactive mode, `gh` requires an explicit merge strategy with `--auto` (use the repository default: usually **`--merge`** for a merge commit, or **`--squash`** / **`--rebase`** if that is what the repo uses).

```bash
gh pr merge <PR_NUMBER_OR_URL> --auto --merge
```

If `--auto` fails (permissions, auto-merge disabled, or pending checks), leave the PR open and report the error; the user can merge manually after CI passes. You can poll with `gh pr checks <PR_NUMBER_OR_URL> --watch` then retry `gh pr merge ... --auto --merge`, or merge manually.

## After merge

Merging the PR into `main` runs **Release on merge** (`.github/workflows/github_release_on_release_branch_merge.yml`), which creates a **GitHub Release** for tag `v{version}` from the merge commit. Because releases created with the default `GITHUB_TOKEN` do not trigger other workflows, **Publish to PyPI** (`publish.yml`) is also started via **`workflow_run`** when that release workflow finishes. Manual or API-created releases still match the `release: published` trigger on `publish.yml`.
2. The workflow runs the version, changelog, and package checks, then opens `Release X.Y.Z` from `release/X.Y.Z`. A pull request it opens does not start `pull_request` workflows.
3. Merging publishes to PyPI, tags `vX.Y.Z`, and creates the GitHub Release.

## Quick reference
If Prepare release is not on `main` yet, make the same edits by hand: set `pyproject.toml` `version` and `docs/conf.py` `release`, move `## Unreleased` to `## X.Y.Z - YYYY-MM-DD`, push `release/X.Y.Z`, and open the pull request with that changelog section as the body.

| Input | Result |
|--------------------|---------------------------------------------|
| `/release` | Patch bump, branch `release/x.y.(z+1)` |
| `/release 1.4.0` | Version `1.4.0`, branch `release/1.4.0` |
Git identity for those hand edits: `cursor@proxymesh.com` / `Cursor`.
161 changes: 161 additions & 0 deletions .github/scripts/release_lib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
"""Bump version manifests and print the changelog notes for a release."""

import os
import re
import sys
from datetime import datetime, timezone
from pathlib import Path

ROOT = Path(__file__).resolve().parents[2]
VERSION = re.compile(r"^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$")
DATED = re.compile(
r"^## ((?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)) - (\d{4}-\d{2}-\d{2})\s*$"
)


def assignment(text, key):
pattern = re.compile(
rf"^(?P<pre>{key}\s*=\s*['\"])(?P<value>[^'\"]*)['\"]\s*$",
re.MULTILINE,
)
found = list(pattern.finditer(text))
if len(found) != 1:
raise SystemExit(f"expected one {key} assignment, found {len(found)}")
return found[0]


def parse_version(value):
if VERSION.fullmatch(value) is None:
raise SystemExit(f"version {value!r} must look like X.Y.Z")
return tuple(int(part) for part in value.split("."))


def next_version(current, spec):
spec = spec.strip()
major, minor, patch = parse_version(current)
name = spec.lower()
if name == "patch":
return f"{major}.{minor}.{patch + 1}"
if name == "minor":
return f"{major}.{minor + 1}.0"
if name == "major":
return f"{major + 1}.0.0"
new = parse_version(spec)
if new <= (major, minor, patch):
raise SystemExit(f"version {spec} is not newer than {current}")
return ".".join(str(part) for part in new)


def span(lines, pred):
starts = [index for index, line in enumerate(lines) if pred(line)]
if len(starts) != 1:
raise SystemExit(f"expected one changelog heading, found {len(starts)}")
start = starts[0]
end = next(
(i for i in range(start + 1, len(lines)) if lines[i].startswith("## ")),
len(lines),
)
return start, end


def check():
pyproject = (ROOT / "pyproject.toml").read_text(encoding="utf-8")
docs = (ROOT / "docs" / "conf.py").read_text(encoding="utf-8")
version = assignment(pyproject, "version").group("value")
docs_version = assignment(docs, "release").group("value")
parse_version(version)
if docs_version != version:
raise SystemExit(
f"docs/conf.py release is {docs_version}; pyproject version is {version}."
)
changelog = (ROOT / "CHANGELOG.md").read_text(encoding="utf-8")
dates = [
match.group(2)
for line in changelog.splitlines()
if (match := DATED.match(line.strip())) and match.group(1) == version
]
if len(dates) != 1:
raise SystemExit(f"CHANGELOG.md needs one '## {version} - YYYY-MM-DD' section.")
datetime.strptime(dates[0], "%Y-%m-%d")
head = os.environ.get("GITHUB_HEAD_REF") or os.environ.get("HEAD_REF") or ""
if head.startswith("release/") and head != f"release/{version}":
raise SystemExit(f"branch {head} does not match version {version}.")
print(f"Version {version} matches the manifests and CHANGELOG.md.")


def write_assignment(path, key, new):
text = path.read_text(encoding="utf-8")
match = assignment(text, key)
path.write_text(
text[: match.start("value")] + new + text[match.end("value") :],
encoding="utf-8",
newline="\n",
)


def bump():
spec = os.environ.get("VERSION_INPUT", "").strip()
if not spec:
raise SystemExit("Set version to X.Y.Z, patch, minor, or major.")
py_path = ROOT / "pyproject.toml"
docs_path = ROOT / "docs" / "conf.py"
log_path = ROOT / "CHANGELOG.md"
pyproject = py_path.read_text(encoding="utf-8")
new = next_version(assignment(pyproject, "version").group("value"), spec)
day = datetime.now(timezone.utc).date().isoformat()
lines = log_path.read_text(encoding="utf-8").splitlines(keepends=True)
start, end = span(lines, lambda line: line.strip() == "## Unreleased")
body = "".join(lines[start + 1 : end])
if not body.strip():
raise SystemExit("The Unreleased section in CHANGELOG.md is empty.")
heading = f"## {new} - {day}\n"
lines[start] = "## Unreleased\n\n" + heading
updated = "".join(lines)
write_assignment(py_path, "version", new)
write_assignment(docs_path, "release", new)
log_path.write_text(updated, encoding="utf-8", newline="\n")
notes_file = os.environ.get("NOTES_FILE")
if notes_file:
Path(notes_file).write_text(
(heading + body).strip() + "\n",
encoding="utf-8",
newline="\n",
)
output = os.environ.get("GITHUB_OUTPUT")
if output:
with Path(output).open("a", encoding="utf-8") as handle:
handle.write(f"version={new}\n")
print(new)


def notes():
version = assignment(
(ROOT / "pyproject.toml").read_text(encoding="utf-8"),
"version",
).group("value")
lines = (
(ROOT / "CHANGELOG.md").read_text(encoding="utf-8").splitlines(keepends=True)
)

def is_version(line):
match = DATED.match(line.strip())
return match is not None and match.group(1) == version

start, end = span(lines, is_version)
sys.stdout.write("".join(lines[start:end]).strip() + "\n")


def main(argv):
command = argv[1] if len(argv) > 1 else ""
if command == "bump":
bump()
elif command == "check":
check()
elif command == "notes":
notes()
else:
raise SystemExit("usage: release_lib.py bump|check|notes")


if __name__ == "__main__":
main(sys.argv)
68 changes: 0 additions & 68 deletions .github/workflows/github_release_on_release_branch_merge.yml

This file was deleted.

Loading