Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Added the /release command for cutting Spree releases (#15070)

Damian Legawiecd3a142213245
diff --git a/.changeset/README.md b/.changeset/README.md
index d302629d5e..9ed164d7c4 100644
--- a/.changeset/README.md
+++ b/.changeset/README.md
@@ -17,6 +17,10 @@ API, so they keep their own versions and release on their own tags.
## Releasing
+`/release <version>` runs the process below with the audit and release notes a
+release needs, publishing a patch release itself and leaving a minor, major or
+prerelease to a human; this section records the mechanics.
+
Every release is published by `.github/workflows/release.yml` from a tag
pushed on a commit already on `main`. The workflow checks the tag against the
versions in the repository first, and skips any version already published, so
@@ -31,10 +35,11 @@ a failed release can be re-run.
**A Spree release:**
1. Bump `Spree::VERSION` in `spree/core/lib/spree/core/version.rb`.
-2. Run `pnpm version:packages`. It runs `changeset version`, then moves every
- package in the group to the Spree version. A package with no changes still
- gets the new version and a changelog entry saying so. Pending changesets
- for the tools are versioned too.
+2. Run `GITHUB_TOKEN=$(gh auth token) pnpm version:packages` — the changelog
+ writer needs the token to link pull requests. It runs `changeset version`,
+ then moves every package in the group to the Spree version. A package with
+ no changes still gets the new version and a changelog entry saying so.
+ Pending changesets for the tools are versioned too.
3. Merge, then push the Spree tag, plus a tag for each tool whose version
changed: `git push origin v6.0.0.rc7 @spree/[email protected]`.
diff --git a/.claude/commands/release.md b/.claude/commands/release.md
new file mode 100644
index 0000000000..5a6d0aa357
--- /dev/null
+++ b/.claude/commands/release.md
@@ -0,0 +1,351 @@
+---
+description: Cut a Spree release — audit, version bump, release notes, pull request, then tags and the GitHub release (automatic for a patch, printed for a human otherwise), the spree-starter bump and the storefront SDK bump.
+---
+
+Cut the Spree release named in the arguments: `6.0.2`, `6.1.0` or a
+prerelease such as `6.1.0.rc1` (gem spelling). With no argument, propose the
+next patch of `Spree::VERSION` and confirm it.
+
+Version: $ARGUMENTS
+
+Releases are published by `.github/workflows/release.yml` from tags pushed on a
+commit already on `main`; `.changeset/README.md` has the mechanics. This command
+wraps them with the review a release needs. Run the phases in order. Phase 5
+pushes the tags and creates the GitHub release itself for a patch release
+(`X.Y.Z` with `Z` above zero and no prerelease label); for a minor, major or
+prerelease it only prints the commands, and a human runs them. Phases 6 and 7
+bump spree-starter and the storefront once the gems and packages are
+published. All three need the pull request merged, so the command usually
+stops after phase 4 and is run again to publish.
+
+Work on a branch named `chore/release-<version>` with the workspace installed
+(`node_modules` present), never on `main`.
+
+## 1. Audit what ships
+
+Run `git fetch origin --tags` first. The last Spree tag is `git describe
+--tags --abbrev=0 --match 'v*' origin/main` and its date is `git log -1
+--format=%cI <tag>`. List the commits since it with `git log --format='%h %an
+%s' <tag>..origin/main`. A commit merged through a pull request ends in
+`(#1234)`; fetch all of those in one call, `gh pr list --state merged --base
+main --search "merged:>=<tag date>" --limit 200 --json
+number,title,author,body`, and keep the numbers the log names. Fetch any
+number the log names but the list misses (the list stops at 200) with `gh pr
+view <n> --repo spree/spree --json number,title,author,body`. A commit with
+no number was pushed straight to `main`: it stays in the list with its author
+and is linked by commit instead. Strip CodeRabbit and "Generated by" trailers
+from the bodies. These feed the release notes in phase 3.
+
+Then check the diff since the tag for anything that does not fit the release
+type, and list each item for the user before bumping:
+
+- **Migrations**: new files under `spree/*/db/migrate/`, and any edit to a
+ migration that has already shipped (apps that ran it will not run it again).
+- **Gemspec and `package.json` dependency changes**: a major bump or a removed
+ runtime dependency breaks apps that relied on it. `bundle update
+ --conservative` cannot follow a dependency major.
+- **Public API and component changes** marked as `patch` in `.changeset/`:
+ removed props, renamed fields, anything a plugin or SDK user could call.
+- **Generated artifacts left behind**: a serializer change without its
+ `docs/api-reference/*.yaml` regeneration, SDK types out of date.
+- **Open pull requests by the user** that are green and could ride along.
+
+A patch release carries only patch changesets for the packages in the
+`fixed` group. If one of those names `minor` or `major`, either downgrade it
+with the user's agreement (6.0.1 did this) or stop and propose a minor release
+instead. `@spree/cli` and `create-spree-app` keep their own versions, so their
+changesets may name any bump.
+
+Decide the tool releases: `@spree/cli` and `create-spree-app` ship only when
+`git log <their last tag>..origin/main -- packages/<dir>` names a change to
+what the package publishes (its source, binaries, templates or dependencies;
+not tests, lint or repository files), where the tag is `git describe --tags
+--abbrev=0 --match '@spree/cli@*' origin/main` (or `create-spree-app@*`).
+Every such change needs a changeset; add one if a commit forgot it. A tool
+with no such change keeps its version and gets no tag.
+
+Confirm CI is green on `origin/main` HEAD: `gh run list --branch main --limit 6`.
+
+## 2. Bump
+
+1. Set `Spree::VERSION` in `spree/core/lib/spree/core/version.rb`.
+2. `GITHUB_TOKEN=$(gh auth token) pnpm version:packages` — the changelog
+ writer needs the token to link pull requests. Never run plain
+ `changeset version`.
+3. Read every `packages/*/CHANGELOG.md` entry it wrote. A changeset shared by
+ several packages lands word for word in each; rewrite an entry that describes
+ another package (the CLI's entry must talk about the CLI). The entry for a
+ package with no changes of its own is "Released with Spree <version>, with no
+ changes of its own."
+4. Verify: `node scripts/publish-packages.mjs verify v<version>` and, for each
+ tool that moved, `verify @spree/cli@<version>` or
+ `verify create-spree-app@<version>`. `pnpm install --frozen-lockfile
+ --offline` must still pass; a version bump never changes the lockfile.
+5. For a minor or major release, add the entry to `docs/changelog.mdx` (the
+ 6.0.0 release commit shows the shape) and make sure the upgrade guide under
+ `docs/developer/upgrades/` exists. Patch releases skip this.
+6. Commit as `Released Spree <version>`. The body says which tools moved and
+ which stayed, and why. Amend the fixes from the reviews that run before the
+ pull request opens into it; once it is open, `/open-pr` pushes each round
+ as its own commit and the pull request is squash-merged.
+
+## 3. Write the release notes
+
+Write `tmp/release-notes-<version>.md` in the repository (`mkdir -p tmp`
+first; it is ignored by git and absent from a fresh checkout) in exactly this
+shape. It becomes the GitHub release body, and the
+dashboard's notifications panel renders that body in every merchant's admin, so
+keep it plain GitHub markdown.
+
+````markdown
+# Spree <version>
+
+<Two or three sentences: what kind of release this is and the three or four things a merchant or developer will notice.>
+
+```bash
+npx spree upgrade
+```
+
+---
+
+## ✨ New features
+
+- **<Feature in a few words>.** <One or two sentences on what it does for the merchant or developer.> [#1234](https://github.com/spree/spree/pull/1234)
+
+## 🧭 Admin dashboard improvements
+
+- **<Improvement>.** <Sentence.> [#1234](https://github.com/spree/spree/pull/1234)
+
+## 🐛 Bug fixes
+
+- <What works now, as a plain sentence; no bold lead.> [#1234](https://github.com/spree/spree/pull/1234) by @handle
+
+## ⬆️ Upgrading from <previous minor>
+
+- <Fixes and steps for stores still coming from the previous minor.> [#1234](https://github.com/spree/spree/pull/1234)
+
+## 🛠 Developer experience
+
+- <Dependency changes, removed gems or packages, CLI and template changes, with what an app owner must do.> [#1234](https://github.com/spree/spree/pull/1234)
+
+## 📚 Documentation
+
+- <Guide rewrites and new pages.> [#1234](https://github.com/spree/spree/pull/1234) by @handle
+
+---
+
+## 📦 Package versions
+
+| Package | Version |
+| --- | --- |
+| Spree gems | `<version>` |
+| `@spree/sdk`, `@spree/admin-sdk`, `@spree/seller-sdk`, `@spree/core` | `<npm version>` |
+| `@spree/dashboard`, `@spree/dashboard-core`, `@spree/dashboard-ui`, `@spree/seller-dashboard` | `<npm version>` |
+| `@spree/cli` | `<version>` |
+| `create-spree-app` | `<version>` (unchanged) |
+
+**Full Changelog:** https://github.com/spree/spree/compare/v<previous>...v<version>
+````
+
+Rules:
+
+- Keep only the sections that have entries, in this order. "Upgrading from"
+ appears when a change fixes the upgrade path from the previous minor.
+- One bullet per pull request, or one bullet for a group of pull requests that
+ make one change (list every number). Every bullet links its pull request.
+- Write for the reader of the section: merchants in features, dashboard and
+ bug fixes; developers in upgrading, developer experience and documentation.
+ Say what works now, not what was broken or how it was fixed. No class names,
+ file paths or internal terms in the merchant sections.
+- Credit every author other than the person cutting the release with
+ `by @handle` after the link.
+- Breaking or action-needed items (a dependency major, a removed gem, a removed
+ prop, a rake task to re-run) go in "Developer experience" or "Upgrading from"
+ with the action spelled out.
+- Internal work (test helpers, CI, repository tooling nobody installs) is left
+ out.
+- The npm spelling of a prerelease is `6.1.0-rc.1`; the table shows it.
+
+Show the notes to the user in the final report of this phase.
+
+## 4. Open the pull request
+
+Run `/open-pr`. The pull request description is the release summary (which
+tools moved and that the tags and GitHub release follow the merge), a `---`
+line, then the notes from phase 3 verbatim. A release pull request is the
+exception to the short-description rule: reviewers review the notes there, and
+phase 5 reads them back from it. Only collaborators can edit a pull request
+description, so never post the notes as a comment, which anyone can write.
+Stop when `/open-pr` reports: the merge needs a human review.
+
+## 5. Publish (after the merge)
+
+Run from a checkout of `main` at the merge commit (`git pull`). Check
+`Spree::VERSION` is the target, no `v<version>` tag exists yet, and every
+workflow that ran on the merge commit succeeded: `gh run list --commit <merge
+sha> --json name,conclusion`. Tests must be among them: every release commit
+changes `Spree::VERSION` under `spree/`, so a missing Tests run means CI never
+covered the merge commit. Stop on a missing, failed or cancelled run.
+
+Decide who publishes. A **patch release** (`X.Y.Z`, `Z` above zero, no
+prerelease label) is published by this command: run the commands below in
+order. A **minor, major or prerelease** is published by a human: print the
+same commands and the notes, run none of them, and stop.
+
+1. Recover the notes first, before anything is pushed, so a problem with them
+ stops the release while nothing has happened yet. They are in the pull
+ request description, from the `# Spree <version>` heading to the end; `<n>`
+ is the number in the merge commit subject:
+
+ ```bash
+ mkdir -p tmp
+ gh pr view <n> --repo spree/spree --json body --jq .body | tr -d '\r' | sed -n '/^# Spree <version>$/,$p' > tmp/release-notes-<version>.md
+ ```
+
+ The `tr` matters: a description edited on github.com comes back with CRLF
+ line endings, and the heading match would otherwise find nothing. The file
+ must start with the heading and end with the **Full Changelog** line; an
+ empty or truncated file stops the release. Print it in full as a markdown
+ block, so the user sees what is published and can paste it by hand.
+
+2. Tag the merge commit, with a tag for each tool that moved, and push at most
+ three tags in one push (GitHub starts no workflow beyond that):
+
+ ```bash
+ git tag v<version> <merge sha>
+ git tag '@spree/cli@<version>' <merge sha> # only tools that moved
+ git push origin v<version> '@spree/cli@<version>'
+ ```
+
+ The push starts one `release.yml` run per tag. Find each run by its tag,
+ not by its place in the recent list, and wait for every one of them:
+
+ ```bash
+ gh run list --workflow release.yml --branch v<version> --json databaseId,conclusion
+ gh run watch <id>
+ ```
+
+ (`--branch` takes the tag name for tag pushes; repeat for each tool tag.)
+ Every job skips versions already on its registry, so a failed run is re-run
+ with `gh run rerun <id> --failed`, never with a new tag. Stop before the
+ next step unless every tag's run concluded `success`.
+
+3. Create the GitHub release:
+
+ ```bash
+ gh release create v<version> --title v<version> --notes-file tmp/release-notes-<version>.md --latest
+ ```
+
+ `--latest` only when this is the newest stable release; a patch for an older
+ minor takes `--latest=false`. A prerelease takes `--prerelease` and not
+ `--latest`.
+
+4. Wait until the registries serve the exact version. A green release
+ workflow means the upload finished, not that the version is installable:
+ RubyGems' API, Bundler's compact index and npm's replicated metadata each
+ lag the publish by anything from seconds to several minutes. Poll both
+ (a prerelease publishes under npm's `beta` tag and RubyGems hides
+ prereleases by default, so the checks name the version):
+
+ ```bash
+ until gem info spree_core --remote --prerelease -v <version> | grep -q "spree_core (<version>)"; do sleep 30; done
+ until npm view @spree/sdk@<npm version> version >/dev/null 2>&1; do sleep 30; done
+ ```
+
+ Give up and report after 30 minutes. Then `gh release view v<version>`
+ shows the release. Phases 6 and 7 start only after this step passes, and
+ each still retries its own install, because the index a resolver reads can
+ trail the API the checks above hit.
+
+## 6. Bump spree-starter
+
+New projects come from [spree/spree-starter](https://github.com/spree/spree-starter),
+whose lockfile pins the Spree gems and whose `db/migrate` holds a copy of every
+gem migration. Run this once the gems are on RubyGems (phase 5 step 4), from
+the repository root of a worktree, whose Postgres the scratch database below
+uses.
+
+```bash
+rm -rf tmp/spree-starter
+git clone --quiet https://github.com/spree/spree-starter.git tmp/spree-starter
+cd tmp/spree-starter
+git switch -c chore/spree-<version with dots as dashes>
+bundle update $(ls ../../spree/*.gemspec ../../spree/*/*.gemspec ../../spree/providers/*/*.gemspec | xargs -n1 basename | sed 's/\.gemspec$//')
+grep -E "^ spree[a-z_]* \(" Gemfile.lock
+DATABASE_NAME=spree_starter_release bin/rails db:create spree:install:migrations db:migrate
+DATABASE_NAME=spree_starter_release bin/rails db:drop
+```
+
+- `bundle update` resolves from Bundler's compact index, which can trail the
+ RubyGems API phase 5 polled by several minutes. A failure naming `Could not
+ find gem 'spree'` or a version other than `<version>` in the `grep` means
+ the index has not caught up: wait a minute and run the `bundle update` line
+ again, up to ten times, before treating it as an error.
+- `bundle update` on the gems this repository releases (the `spree` meta gem
+ and the gemspecs under `spree/*/` and `spree/providers/*/`), never a bare
+ `bundle update` and not every
+ `spree*` gem: `spree_dev_tools` has its own version. The starter's `Gemfile`
+ already allows the new version (`~> 6.0`), so this moves the lockfile and the
+ dependencies the gems require (6.0.2 moved Alba to 4) and nothing else. The
+ `grep` must then show `<version>` for every one of those gems; another
+ version means the gems are not on RubyGems yet or the `Gemfile` constraint
+ excludes them. Stop in that case. The Ruby in `.ruby-version` must be
+ installed; the worktree's Rails runs on it.
+- `spree:install:migrations` copies the gem migrations the starter lacks into
+ `db/migrate`; `db:migrate` runs them on the scratch database so
+ `db/schema.rb` is regenerated. The starter's `config/database.yml` reads
+ `DATABASE_NAME` (and `DATABASE_HOST`, `DATABASE_USERNAME`, `DATABASE_PORT`
+ when the worktree's Postgres is not the default local one) in development;
+ `DATABASE_URL` applies only in production. The scratch database is dropped
+ afterwards.
+- The diff must touch only `Gemfile.lock`, `db/migrate/` and `db/schema.rb`.
+ Anything else means a step ran against the wrong app; stop and look.
+- Commit as `Bump Spree to <version>`, with the copied migrations named in the
+ body, push, and open the pull request with `gh pr create --repo
+ spree/spree-starter --base main`. Its description lists the new migrations
+ and says what each one does. Its CI builds the Docker image and runs the
+ specs; watch it with `gh pr checks --watch --repo spree/spree-starter`. A
+ human merges it.
+
+## 7. Bump the storefront's SDK
+
+The Next.js storefront at [spree/storefront](https://github.com/spree/storefront)
+depends on `@spree/sdk` by caret range, so new installs already get the new
+version; the lockfile and the range still move so the repository builds and
+tests against it. Run once `@spree/sdk@<npm version>` is on npm (phase 5
+step 4). Clone fresh rather than using a worktree's `storefront/`: that
+clone's lockfile points at the worktree's own SDK build and must never be
+committed.
+
+```bash
+rm -rf tmp/storefront
+git clone --quiet https://github.com/spree/storefront.git tmp/storefront
+cd tmp/storefront
+git switch -c chore/sdk-<version with dots as dashes>
+pnpm add @spree/sdk@^<npm version>
+pnpm exec tsc --noEmit && pnpm run check && pnpm run test
+```
+
+- `pnpm add` with the caret spec rewrites the range in `package.json` and
+ resolves the lockfile to the new version; nothing else moves. An
+ `ERR_PNPM_NO_MATCHING_VERSION` for `@spree/sdk` means npm's metadata has
+ not replicated to the mirror pnpm hit: wait a minute and run it again, up
+ to ten times. After it succeeds, the lockfile must name
+ `@spree/sdk@<npm version>`; an older version resolved means the range was
+ satisfied by stale metadata, so run `pnpm update @spree/sdk` once more. The diff must
+ touch only `package.json` and `pnpm-lock.yaml`. A type error here means the
+ Store API changed shape in this release; stop and report it rather than
+ patching the storefront inside the release.
+- Commit as `Updated @spree/sdk to ^<npm version>` with a one-sentence body
+ naming the Spree release, push, and open the pull request with `gh pr create
+ --repo spree/storefront --base main`. Its CI runs lint, type check, unit
+ tests and the Playwright suite against a Spree server; watch it with `gh pr
+ checks --watch --repo spree/storefront`. A human merges it.
+
+## Final report
+
+The pull request URL, the audit items the user accepted or deferred, the tool
+versions bumped or kept, the follow-ups the audit produced (regenerated docs, a
+changeset a commit forgot, an upgrade note) and, after the merge, the release
+URL (or the tag and release commands for a human), the registry checks and the
+spree-starter and storefront pull requests.
diff --git a/AGENTS.md b/AGENTS.md
index b7d7c529b6..96c61b7c7d 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -76,6 +76,7 @@ pnpm wt:template # rebuild the template DB after schema-changing pulls
- No co-author or "generated with" trailers.
- Open every pull request with `/open-pr` (code review, security review, open, monitor). A hook blocks a bare `gh pr create` until both reviews have run on `HEAD`.
- Pull request descriptions are public: no credentials, personal data or local URLs. Keep them short; bullets for larger changes.
+- Cut releases with `/release <version>` (audit, version bump, release notes, pull request, then tags, GitHub release, and the spree-starter and storefront bumps). A patch release publishes itself; a minor, major or prerelease prints the tag commands for a human.
## Testing