diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..b6a38f0 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,9 @@ +## What changed + + + +## How you tested it + + + +Please don't change the version in `plugin.yaml` or `PLUGIN_VERSION`. Merged changes are released together, and the release bumps the version. diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 955b5e4..45ee08b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,9 +1,10 @@ name: Release -# A merge to main that bumps the plugin version publishes it as a GitHub Release. -# The bighelp app and `hermes bighelp update` install the latest release. +# The maintainer starts this when a batch of merged changes is ready: +# gh workflow run release.yml +# It publishes the version in plugin.yaml as a GitHub Release, from the commit that +# set that version. The bighelp app and `hermes bighelp update` install the latest +# release, so a release reaches every host. on: - push: - branches: [main] workflow_dispatch: permissions: contents: write @@ -13,10 +14,14 @@ concurrency: cancel-in-progress: false jobs: publish: + if: github.ref == 'refs/heads/main' runs-on: ubuntu-latest timeout-minutes: 5 steps: - uses: actions/checkout@v4 + with: + # Finding the commit that set the version needs the history. + fetch-depth: 0 - uses: actions/setup-python@v5 with: python-version: '3.12' diff --git a/AGENTS.md b/AGENTS.md index b5ea2af..6ced32c 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -19,11 +19,16 @@ Many features span both repos. The app's side of each route lives in the app rep ## Mindset -- **A merge that bumps the version is a release.** - - `.github/workflows/release.yml` publishes it as a GitHub Release. The bighelp app offers the latest release to - every host, and `hermes bighelp update` installs it. No app build is needed to ship a plugin update. - - Bump the version for any change in behavior; a merge without a bump publishes nothing. Keep `main` - releasable anyway. +- **Releases are batched, and the maintainer starts them.** + - Pull requests don't change the version. Merged changes collect on `main`, which must stay releasable. + - When the maintainer decides to ship, a release PR bumps `plugin.yaml` and `PLUGIN_VERSION` and lists + everything since the last release. Its title leads with the version. Its description becomes the release + notes, and the app shows the first 1,500 characters on its update screen, so open with a short summary in + plain words for people who run hosts. Credit outside contributors. + - After it merges, the maintainer runs the Release workflow (`gh workflow run release.yml`). It publishes the + version from the release PR's merge; anything merged later waits for the next release. + - The bighelp app offers the latest release to every host, and `hermes bighelp update` installs it. No app + build is needed to ship a plugin update. - The maintainer merges. - **Never break older apps.** Add fields and add new capability names. Don't rename, remove or change the meaning of what an app build already uses. @@ -114,10 +119,10 @@ shared through one `sys.modules` entry (see `sys.modules.setdefault(...)` in `ma - Add it to `PROCESS_FEATURES` in `tests/test_native_startup_logging.py`. - Add unit tests for the module itself. 4. **Docs:** add `docs/.md` with the full route contract, and a row in the README feature table. -5. **Version:** bump `plugin.yaml` and `PLUGIN_VERSION` in `loopdy_plugin/link_contracts.py` together. - `tests/test_portability.py` checks that they match. -6. **After merge:** the release workflow publishes the new version and the app offers it to hosts. The app adds - its side of the route in its own release. +5. **Version:** leave it alone. The next release PR bumps `plugin.yaml` and `PLUGIN_VERSION` in + `loopdy_plugin/link_contracts.py` together; `tests/test_portability.py` checks that they match. +6. **After the release:** the app offers the new version to hosts. The app adds its side of the route in its own + release. ## What agents are told diff --git a/README.md b/README.md index 146fd4c..d09c27a 100644 --- a/README.md +++ b/README.md @@ -43,8 +43,8 @@ hermes bighelp update --restart # …and restart the gateway once hermes bighelp update-status # check the last update ``` -Every merge that bumps the version publishes a [GitHub Release](https://github.com/promptclickrun/bighelp-plugin/releases) -(`.github/workflows/release.yml`); other merges don't reach hosts. The updater looks up the latest release, pins +Hosts only get [GitHub Releases](https://github.com/promptclickrun/bighelp-plugin/releases). Merged changes are +released together from time to time (`.github/workflows/release.yml`), so a merge alone doesn't reach hosts. The updater looks up the latest release, pins its exact commit, validates it, backs up the current copy and installs it with Hermes' own installer. It never moves a host to an older version. Your settings stay in place. It refuses to overwrite a modified install. Self-update needs macOS launchd or Linux user systemd. diff --git a/scripts/publish_release.py b/scripts/publish_release.py index ec22a4f..3cb9243 100644 --- a/scripts/publish_release.py +++ b/scripts/publish_release.py @@ -1,8 +1,10 @@ -"""Publish the plugin version on main as a GitHub Release, once. +"""Publish the plugin version in plugin.yaml as a GitHub Release, once. -Runs from .github/workflows/release.yml after every push to main. The bighelp app -and `hermes bighelp update` install the latest release, so a merge that bumps the -version reaches hosts and one that doesn't (its release already exists) stops here. +Runs only when the maintainer starts .github/workflows/release.yml. Pull requests +collect on main unreleased; a release PR bumps the version and lists what's in it. +The release is main as of that PR's merge, with its description as the notes, so a +change merged after it waits for the next release. The bighelp app and +`hermes bighelp update` install the latest release. """ import json import os @@ -17,20 +19,36 @@ MAX_NOTES = 100_000 -def plugin_version(root: Path = ROOT) -> str: - match = VERSION.search((root / "plugin.yaml").read_text(encoding="utf-8")) +def manifest_version(text: str) -> str: + match = VERSION.search(text) if not match: raise SystemExit("plugin.yaml has no version") return match.group(1) +def plugin_version(root: Path = ROOT) -> str: + return manifest_version((root / "plugin.yaml").read_text(encoding="utf-8")) + + def version_key(version: str) -> tuple[int, ...]: parts = [int(part) for part in version.split(".")] return tuple(parts + [0] * (4 - len(parts))) +def _git(*args: str, root: Path = ROOT) -> str: + return subprocess.run(["git", *args], cwd=root, check=True, capture_output=True, text=True).stdout + + +def version_commit(root: Path = ROOT) -> str: + """The last commit that changed plugin.yaml's version: the release PR's merge.""" + commit = _git("log", "-1", "--format=%H", "-G", "^version:", "--", "plugin.yaml", root=root).strip() + if not commit: + raise SystemExit("No commit sets the plugin version") + return commit + + def release_notes(pull: dict | None, commit_message: str) -> str: - """The merged pull request's title and description, else the commit message.""" + """The release pull request's title and description, else the commit message.""" if pull and pull.get("title"): notes = f"## {pull['title']}\n\n{(pull.get('body') or '').strip()}".strip() else: @@ -39,11 +57,14 @@ def release_notes(pull: dict | None, commit_message: str) -> str: def _gh(*args: str, check: bool = True) -> subprocess.CompletedProcess: - return subprocess.run(["gh", *args], check=check, capture_output=True, text=True) + result = subprocess.run(["gh", *args], capture_output=True, text=True) + if check and result.returncode != 0: + raise SystemExit(f"gh {args[0]} {args[1]} failed: {result.stderr.strip() or result.returncode}") + return result def main() -> int: - repository, commit = os.environ["GITHUB_REPOSITORY"], os.environ["GITHUB_SHA"] + repository = os.environ["GITHUB_REPOSITORY"] version = plugin_version() tag = f"v{version}" if _gh("release", "view", tag, "--repo", repository, check=False).returncode == 0: @@ -56,12 +77,13 @@ def main() -> int: print(f"plugin.yaml says {version}, which isn't newer than the latest release {current}.", file=sys.stderr) return 1 + commit = version_commit() + if manifest_version(_git("show", f"{commit}:plugin.yaml")) != version: + raise SystemExit(f"The commit that set the version doesn't say {version}") pulls = json.loads(_gh("api", f"repos/{repository}/commits/{commit}/pulls").stdout or "[]") pull = next((item for item in pulls if item.get("merged_at")), None) - message = subprocess.run(["git", "log", "-1", "--format=%B", commit], - check=True, capture_output=True, text=True).stdout with tempfile.NamedTemporaryFile("w", suffix=".md", delete=False, encoding="utf-8") as notes: - notes.write(release_notes(pull, message)) + notes.write(release_notes(pull, _git("log", "-1", "--format=%B", commit))) try: _gh("release", "create", tag, "--repo", repository, "--target", commit, "--title", f"bighelp plugin {version}", "--notes-file", notes.name, "--latest") diff --git a/tests/test_publish_release.py b/tests/test_publish_release.py index 7b0a91e..3c11e80 100644 --- a/tests/test_publish_release.py +++ b/tests/test_publish_release.py @@ -1,5 +1,6 @@ """The release workflow publishes exactly the version in plugin.yaml.""" from pathlib import Path +import subprocess import sys import tempfile import unittest @@ -21,13 +22,34 @@ def test_it_publishes_the_manifest_version(self): with self.assertRaises(SystemExit): publish_release.plugin_version(root) - def test_notes_come_from_the_merged_pull_request(self): + def test_notes_come_from_the_release_pull_request(self): notes = publish_release.release_notes({"title": "3.0.0: bighelp names", "body": "What changed."}, "commit") self.assertEqual(notes, "## 3.0.0: bighelp names\n\nWhat changed.") self.assertEqual(publish_release.release_notes(None, "Direct push\n"), "Direct push") self.assertLessEqual(len(publish_release.release_notes({"title": "t", "body": "x" * 200_000}, "")), publish_release.MAX_NOTES) + def test_the_release_is_the_commit_that_set_the_version(self): + # Later merges wait for the next release; so does the release PR's own description. + with tempfile.TemporaryDirectory() as directory: + root = Path(directory) + + def commit(path: str, text: str) -> str: + (root / path).write_text(text, encoding="utf-8") + subprocess.run(["git", "add", path], cwd=root, check=True) + subprocess.run(["git", "-c", "user.name=t", "-c", "user.email=t@example.com", + "commit", "-q", "-m", path], cwd=root, check=True) + return subprocess.run(["git", "rev-parse", "HEAD"], cwd=root, check=True, + capture_output=True, text=True).stdout.strip() + + subprocess.run(["git", "init", "-q"], cwd=root, check=True) + commit("plugin.yaml", "manifest_version: 1\nname: loopdy\nversion: 1.0.0\n") + commit("fix.py", "one\n") + release = commit("plugin.yaml", "manifest_version: 1\nname: loopdy\nversion: 1.1.0\n") + commit("fix.py", "two\n") + commit("plugin.yaml", "manifest_version: 2\nname: loopdy\nversion: 1.1.0\n") + self.assertEqual(publish_release.version_commit(root), release) + def test_versions_compare_numerically(self): self.assertGreater(publish_release.version_key("3.10.0"), publish_release.version_key("3.9.9")) self.assertEqual(publish_release.version_key("3.0"), publish_release.version_key("3.0.0"))