diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 400bc7d..1e67a77 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,13 +1,13 @@ # Tests, type check and version consistency on every push and PR. # -# The job names are what the `main` ruleset requires before a PR can merge -# (the release PR included), so renaming one means updating the ruleset too. +# The job names are what the `main` ruleset requires before a PR can merge, +# so renaming one means updating the ruleset too. name: CI on: - # Branches only: the tag release-please pushes for a release is the commit - # that was just tested on main. + # Branches only: a release tag marks a commit that was already tested on + # its way to main. push: branches: ["**"] pull_request: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0162da8..43eb533 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,23 +1,32 @@ -# Release PR → draft release → all-platform builds → publish. See RELEASING.md. +# Push to main → next version → draft release → all-platform builds → publish. +# See RELEASING.md. # -# release-please keeps a release PR open with the next version bump and its -# CHANGELOG.md section. Merging it creates a *draft* release (and its tag), and -# the build jobs below then run in this same workflow: a release created with -# the default GITHUB_TOKEN never triggers another workflow. The draft is -# published only once every platform has uploaded its bundles, signatures and -# latest.json entries, so installs never see a "latest" release without files. +# Every push to main runs scripts/next-version.mjs over the conventional +# commits since the last stable vX.Y.Z tag. If they call for a release, it tags +# the pushed commit and opens a *draft* release with the notes, and the build +# jobs below stamp that version into the build and upload to the draft. The +# draft is published only once every platform has uploaded its bundles, +# signatures and latest.json entries, so installs never see a "latest" release +# without files. A push with nothing releasable (docs:, chore:, ...) stops +# after the first job. name: Release on: push: branches: [main] + # Pre-releases, and a manual retry of a normal release. See RELEASING.md. + workflow_dispatch: + inputs: + prerelease: + description: >- + Pre-release identifier, like rc, for a vX.Y.Z-rc.N pre-release. Works + on any branch. Leave empty for a normal release, which only main makes. + required: false + default: "" permissions: contents: write - pull-requests: write - # release-please labels its PRs, and labels go through the issues API. - issues: write # Never cancel a run that may be halfway through uploading to a draft. concurrency: @@ -25,30 +34,57 @@ concurrency: cancel-in-progress: false jobs: - release-please: - name: Release PR + version: + name: Next version runs-on: ubuntu-latest outputs: - created: ${{ steps.release.outputs.release_created }} - id: ${{ steps.release.outputs.id }} - tag: ${{ steps.release.outputs.tag_name }} - body: ${{ steps.release.outputs.body }} + created: ${{ steps.draft.outputs.created }} + id: ${{ steps.draft.outputs.id }} + tag: ${{ steps.next.outputs.tag }} + version: ${{ steps.next.outputs.version }} + notes: ${{ steps.next.outputs.notes }} steps: - - uses: googleapis/release-please-action@v5 - id: release + - uses: actions/checkout@v7 + with: + # Every commit and tag: the version comes from the history since the + # last release tag. + fetch-depth: 0 + - uses: actions/setup-node@v7 with: - # A release PR pushed with the default GITHUB_TOKEN triggers no - # workflows, so CI would never report on it and the ruleset could - # never let it merge. The PAT makes it an ordinary PR. Without the - # secret, everything else still works, but CI skips the release PR. - token: ${{ secrets.RELEASE_PLEASE_TOKEN || secrets.GITHUB_TOKEN }} - config-file: release-please-config.json - manifest-file: .release-please-manifest.json + node-version: 22 + - name: Work out the next version from the commits + id: next + env: + PRERELEASE: ${{ inputs.prerelease }} + run: | + if [ -z "$PRERELEASE" ] && [ "$GITHUB_REF" != refs/heads/main ]; then + echo "::error::Only main makes normal releases. To release $GITHUB_REF_NAME, give a pre-release identifier such as rc." + exit 1 + fi + node scripts/next-version.mjs --prerelease "$PRERELEASE" --notes-file "$RUNNER_TEMP/notes.md" + # The tag goes up now, not when the draft is published: a release whose + # build fails keeps its version, and the next push moves past it + # (RELEASING.md, When a build fails). + - name: Tag the commit and open a draft release + id: draft + if: steps.next.outputs.version != '' + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + TAG: ${{ steps.next.outputs.tag }} + PRERELEASE: ${{ steps.next.outputs.prerelease }} + run: | + gh api "repos/$GITHUB_REPOSITORY/git/refs" -f ref="refs/tags/$TAG" -f sha="$GITHUB_SHA" > /dev/null + id=$(jq -n --arg tag "$TAG" --rawfile body "$RUNNER_TEMP/notes.md" --argjson prerelease "$PRERELEASE" \ + '{tag_name: $tag, name: $tag, body: $body, draft: true, prerelease: $prerelease}' \ + | gh api "repos/$GITHUB_REPOSITORY/releases" --input - --jq .id) + echo "id=$id" >> "$GITHUB_OUTPUT" + echo "created=true" >> "$GITHUB_OUTPUT" + { echo "Draft release **$TAG** opened."; echo; cat "$RUNNER_TEMP/notes.md"; } >> "$GITHUB_STEP_SUMMARY" signing-key: name: Check signing key - needs: release-please - if: needs.release-please.outputs.created == 'true' + needs: version + if: needs.version.outputs.created == 'true' runs-on: ubuntu-latest steps: - uses: actions/checkout@v7 @@ -71,7 +107,7 @@ jobs: build: name: Build (${{ matrix.platform }}) - needs: [release-please, signing-key] + needs: [version, signing-key] strategy: fail-fast: false matrix: @@ -92,6 +128,14 @@ jobs: runs-on: ${{ matrix.runner }} steps: - uses: actions/checkout@v7 + # The repository holds the placeholder 0.0.0; the release's version is + # only in its tag. Write it into every file that carries the version + # before anything builds, and check none was missed. + - name: Stamp the release version + shell: bash + env: + VERSION: ${{ needs.version.outputs.version }} + run: node scripts/set-version.mjs "$VERSION" && node scripts/check-versions.mjs - name: Install Linux system dependencies if: runner.os == 'Linux' # As in CI, plus what the AppImage bundler shells out to. @@ -116,7 +160,7 @@ jobs: # RELEASING.md (Pre-releases) says when to remove this. - name: Build a Tauri CLI that can bundle a pre-release rpm id: tauri-cli - if: runner.os == 'Linux' && contains(needs.release-please.outputs.tag, '-') + if: runner.os == 'Linux' && contains(needs.version.outputs.tag, '-') env: # It only has to bundle, not be small: skip the slow LTO build. CARGO_PROFILE_RELEASE_LTO: "false" @@ -141,11 +185,11 @@ jobs: TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }} TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD }} with: - # Upload to the draft release-please created rather than a new one. - releaseId: ${{ needs.release-please.outputs.id }} - # Becomes `notes` in latest.json: the release's CHANGELOG.md section, - # which the app shows before installing. - releaseBody: ${{ needs.release-please.outputs.body }} + # Upload to the draft the version job opened rather than a new one. + releaseId: ${{ needs.version.outputs.id }} + # Becomes `notes` in latest.json: the release notes, which the app + # shows before installing. + releaseBody: ${{ needs.version.outputs.notes }} updaterJsonPreferNsis: true args: ${{ matrix.args }} # The patched CLI from the step above, if it ran. Empty means npm's. @@ -155,11 +199,11 @@ jobs: name: Publish release # Skipped unless every build succeeded: a failed platform leaves the draft # for a re-run, and existing installs keep seeing the previous release. - needs: [release-please, build] + needs: [version, build] runs-on: ubuntu-latest env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - RELEASE_ID: ${{ needs.release-please.outputs.id }} + RELEASE_ID: ${{ needs.version.outputs.id }} steps: # Each build merges its platforms into latest.json, so a lost update # between two of them would leave a platform out. Check before going live. diff --git a/.release-please-manifest.json b/.release-please-manifest.json deleted file mode 100644 index 37fcefa..0000000 --- a/.release-please-manifest.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - ".": "1.0.0" -} diff --git a/CHANGELOG.md b/CHANGELOG.md index 96563eb..04737c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,8 @@ # Changelog -## [1.0.0](https://github.com/ZortexSenpai/Reverb/compare/v1.0.0...v1.0.0) (2026-11-10) - - -### Bug Fixes - -* fixed playerbar parametric eq button link ([e5a5d1e](https://github.com/ZortexSenpai/Reverb/commit/e5a5d1ebf50c9fd69372be55e6675e061eab24d2)) -* fixed playerbar parametric eq button link ([a55ad19](https://github.com/ZortexSenpai/Reverb/commit/a55ad19a17c7aa22dd9ff06c4297f12e5411bb9c)) +Releases after 1.0.0 are listed with their notes on +[GitHub Releases](https://github.com/ZortexSenpai/Reverb/releases). This +file is no longer updated; see RELEASING.md. ## [1.0.0](https://github.com/ZortexSenpai/Reverb/compare/v1.0.0-rc.2...v1.0.0) (2026-10-22) diff --git a/Cargo.lock b/Cargo.lock index c5f5054..e3e0217 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3673,7 +3673,7 @@ dependencies = [ [[package]] name = "reverb" -version = "1.0.0" +version = "0.0.0" dependencies = [ "chrono", "crossbeam-channel", @@ -3698,7 +3698,7 @@ dependencies = [ [[package]] name = "reverb-core" -version = "1.0.0" +version = "0.0.0" dependencies = [ "coreaudio-rs", "cpal", diff --git a/Cargo.toml b/Cargo.toml index be6a1d2..a9da9fe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ resolver = "2" members = ["src-tauri", "crates/reverb-core"] [workspace.package] -version = "1.0.0" +version = "0.0.0" edition = "2021" authors = ["ZortexSenpai"] license = "GPL-3.0-only" diff --git a/RELEASING.md b/RELEASING.md index 3cc9d6e..f3eb21e 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -1,43 +1,43 @@ # Releasing Reverb -Releases are cut by merging a pull request. Nobody edits a version number by -hand, builds on their own machine, or uploads files. This page covers how -that works, what it depends on, and what to do when it goes wrong. +Releases are cut by merging to `main`. Nobody picks a version number, edits +one by hand, builds on their own machine, or uploads files. This page covers +how that works, what it depends on, and what to do when it goes wrong. ## How a release happens -1. **Commit to `main` with conventional commit messages.** `feat: …` and - `fix: …` (optionally scoped, `fix(queue): …`) go into the changelog. +1. **Commit with conventional commit messages.** `feat: …`, `fix: …` and + `perf: …` (optionally scoped, `fix(queue): …`) go into the release notes. Other types (`chore:`, `ci:`, `build:`, `docs:`, `refactor:`, `test:`) are - left out of it. So are messages that don't follow the convention at all; - they never block anything. -2. **release-please keeps a release PR open** ("chore(main): release X.Y.Z"). - It holds the next version bump and its `CHANGELOG.md` section, and every - push to `main` updates it. The bump touches `package.json`, - `package-lock.json`, the Cargo workspace version in `Cargo.toml`, and the - `reverb` and `reverb-core` entries in `Cargo.lock`. `tauri.conf.json` has - no version of its own; it inherits the Cargo one. -3. **CI runs on the release PR like on any other.** That only happens - because release-please opens it with `RELEASE_PLEASE_TOKEN` (see - [Secrets](#secrets)). The `main` ruleset won't let it merge until these + left out of them. So are messages that don't follow the convention at all; + they never block anything. Merge commits are skipped, and the commits they + bring in are the ones counted. A squash merge's message is the PR title, + so give such a PR a conventional title. +2. **Merge to `main`.** The `main` ruleset only lets a commit in once these checks pass: - Frontend tests and type check - Version consistency - Rust tests (linux) - Rust tests (macos) - Rust tests (windows) - - The version consistency check (`npm run check:versions`) fails if the - bump missed any of the files above. -4. **Merging the release PR** makes release-please create a **draft** - release for `vX.Y.Z`, tag included. The release body is that version's - `CHANGELOG.md` section. -5. **In the same workflow run** (`.github/workflows/release.yml`): +3. **Every push to `main` runs the release workflow** + (`.github/workflows/release.yml`). Its first job, *Next version*, runs + `scripts/next-version.mjs`. It reads the commits since the newest stable + `vX.Y.Z` tag that `main` descends from, and picks the version by the + [versioning rule](#versioning-rule). If none of them calls for a release + (a push of only `docs:` or `chore:` commits, say), the run stops there. +4. **Otherwise it tags the pushed commit `vX.Y.Z`** and opens a **draft** + release for it. The release notes list the breaking changes, features, + bug fixes and performance improvements since the last release, each + linked to its commit. +5. **In the same workflow run:** 1. *Check signing key* signs a probe file with the signing secret and checks it against the public key in `tauri.conf.json`. A mismatch stops the release before any build starts. - 2. *Build* runs three jobs, each uploading its bundles, `.sig` files and - its entries in `latest.json` to the draft: + 2. *Build* runs three jobs. Each one first writes the version into the + files that hold it (`scripts/set-version.mjs`, then + `npm run check:versions` to prove none was missed), then uploads its + bundles, `.sig` files and its entries in `latest.json` to the draft: | Job | Runner | Uploads | |---|---|---| @@ -62,11 +62,30 @@ them itself. `latest.json` points each platform at its file through the GitHub API (`api.github.com/repos/…/releases/assets/`), and the app checks every download's signature before installing it. +### Where the version lives + +Only in the release's tag. In the repository, `package.json`, +`package-lock.json`, the Cargo workspace version in `Cargo.toml` and the +`reverb` and `reverb-core` entries in `Cargo.lock` all hold the placeholder +**0.0.0**, and nothing commits a version back to `main`. Leave them at +0.0.0. The *Version consistency* check fails if they disagree, because +`set-version.mjs` relies on all of them being there. `tauri.conf.json` has +no version of its own; it inherits the Cargo one. The reasons are in +`docs/adr/0002-release-version-lives-in-the-tag.md`. + +### Release notes + +The notes live on the GitHub release, and the app shows them before it +installs an update. The app reads them from `latest.json`, which copied them +at build time, so editing a published release's notes on GitHub doesn't +change what installs show. `CHANGELOG.md` stops at 1.0.0. + ## Versioning rule -Versions are SemVer and tags are `vX.Y.Z`. +Versions are SemVer and tags are `vX.Y.Z`. The release takes the biggest +bump that any commit since the last release calls for. -- `fix:` → **patch** (1.4.2 → 1.4.3) +- `fix:` or `perf:` → **patch** (1.4.2 → 1.4.3) - `feat:` → **minor** (1.4.2 → 1.5.0) - **Major** (1.4.2 → 2.0.0) only for changes that break something *for listeners*: @@ -74,8 +93,11 @@ Versions are SemVer and tags are `vX.Y.Z`. - raising the minimum Navidrome version - resetting user settings - Mark these with `!` (`feat!: …`) or a `BREAKING CHANGE:` footer. - Breaking changes to internal code don't count. + Mark these with `!` (`feat!: …`) or a `BREAKING CHANGE:` footer. Either + one makes a major release whatever the type, so don't use them for + breaking changes to internal code. +- Anything else → **no release**. The commits wait and go out with the next + release that has a `feat:`, `fix:` or `perf:`. Settings must stay readable across updates: new versions only add fields, each with a default. Changing an existing field's type needs a deliberate @@ -90,21 +112,10 @@ gone until they restore it. |---|---|---| | `TAURI_SIGNING_PRIVATE_KEY` | The updater signing key (from `tauri signer generate`) | Check signing key, Build | | `TAURI_SIGNING_PRIVATE_KEY_PASSWORD` | Its password | Check signing key, Build | -| `RELEASE_PLEASE_TOKEN` | A fine-grained personal access token for this repository only, with read/write access to Contents, Pull requests and Issues | Release PR | -`GITHUB_TOKEN` is provided by Actions and needs no setup. - -**Why `RELEASE_PLEASE_TOKEN`:** GitHub runs no workflows for a pull request -pushed with `GITHUB_TOKEN`. Without the PAT, CI never reports on the release -PR, and the ruleset's required checks would block it forever. - -- If the secret is missing, release-please falls back to `GITHUB_TOKEN`. - Releases still work, but merging the release PR then needs the admin - bypass, with no checks run. -- The fallback also needs **Settings → Actions → General → Allow GitHub - Actions to create and approve pull requests** turned on. -- Fine-grained tokens expire. When this one does, the *Release PR* job fails - with "Bad credentials". Generate a new token and replace the secret. +`GITHUB_TOKEN` is provided by Actions and needs no setup. It creates the +tag and the draft. (`RELEASE_PLEASE_TOKEN`, from when release-please cut +releases, is no longer used and can be deleted.) The **public** key is not a secret. It lives in `src-tauri/tauri.conf.json` under `plugins.updater.pubkey`, and every install checks downloads against @@ -143,28 +154,31 @@ installs keep seeing the previous release. To recover: jobs**. tauri-action replaces any files the failed attempt uploaded, and *Publish release* runs again once all three builds are green. A job that failed with "The job was not acquired by Runner" never ran at all - (GitHub had no runner free), so a re-run is all it needs. + (GitHub had no runner free), so a re-run is all it needs. Don't use + *Re-run all jobs*: *Next version* would find the commit already tagged + and release nothing. 2. If *Publish release* says `latest.json` is missing a platform, re-run that platform's build job. Each build merges its entries into `latest.json`, so the re-run puts the missing ones back. 3. If the failure needs a code change, a re-run can't help: it builds the release commit again. Skip the version instead: 1. Leave the draft unpublished. - 2. Land the fix on `main`, and merge the next release PR (vX.Y.Z+1). - release-please only opens one once a `feat:` or `fix:` commit has - landed since the last release, `release-as` or not, so give the fix - one of those types. For a pre-release, also bump `release-as` (say - to `1.3.0-rc.2`). + 2. Land the fix on `main` as a `fix:`. Its push releases vX.Y.Z+1 on its + own: the failed version's tag already exists, so the next release + counts from it. 3. Once that release is out, delete the stale draft with - `gh release delete vX.Y.Z`. Keep its tag, because release-please's - history counts on it. + `gh release delete vX.Y.Z`. Keep its tag, because the next version is + worked out from it. +4. If *Next version* failed after pushing the tag but before opening the + draft, there's nothing to skip. Delete the tag + (`git push origin :refs/tags/vX.Y.Z`) and re-run the job. ## Fixing a bad release Fix forward. There is no rollback or downgrade in the app. -1. Land the fix (`fix: …`) and merge the release PR. Installs on the bad - version update to the fix like any other update. +1. Land the fix (`fix: …`) on `main`. It releases on its own, and installs + on the bad version update to the fix like any other update. 2. Optionally, mark the bad release as a **pre-release**: ```sh @@ -182,16 +196,18 @@ Pre-releases are for installing by hand, to try a build before it reaches anyone. The updater never offers them, because GitHub's "latest" skips pre-releases. -To cut one through the same pipeline, set these in -`release-please-config.json` for one release PR, then remove them again: +To cut one, open **Actions → Release → Run workflow**, pick the branch, and +enter a pre-release identifier such as `rc`. The version is the one the +branch's commits call for, plus `-rc.N`, with N one past the `rc` tags that +version already has. A branch with a `feat:` since v1.2.0 gives +`v1.3.0-rc.1`, and running it again after more commits gives `v1.3.0-rc.2`. +When the branch merges, the push to `main` releases `v1.3.0` as usual, with +notes covering everything since v1.2.0. -```json -"release-as": "1.3.0-rc.1", -"prerelease": true -``` - -(`release-as` is deprecated upstream in favour of a `Release-As: 1.3.0-rc.1` -commit footer. Either works.) +Run it on the branch before merging. `main` releases every releasable push +straight away, so there's no unreleased work left on `main` to pre-release. +Left empty on `main`, the identifier retries a normal release (for a run +that was cancelled, say). Left empty on any other branch, the run refuses. The Linux build of a pre-release takes about 5 minutes longer. Tauri can't bundle an `.rpm` for a version with a `-` in it yet @@ -209,30 +225,11 @@ The `.deb` gets it the other way round: dpkg reads `1.3.0-rc.1` as still installs 1.3.0 over it (it runs `dpkg -i`, which only warns), but apt treats installing 1.3.0 by hand as a downgrade. -## First release - -The pipeline is proved with a release candidate before 1.0.0 ships. -`release-please-config.json` starts out set up for it. - -1. Generate the signing key and store the secrets (#4). Paste the public key - into `plugins.updater.pubkey` in `tauri.conf.json`, replacing the - placeholder. Until then, *Check signing key* fails on purpose. Also create - `RELEASE_PLEASE_TOKEN`, so CI runs on the release PR. -2. Merge the release PR for **v1.0.0-rc.2** (`release-as: 1.0.0-rc.2`, - `prerelease: true`). Check that the pre-release has every bundle with its - `.sig` and a complete `latest.json`. Then install it by hand on each OS - (#5). - - v1.0.0-rc.1 never got past a draft. Its Linux build failed on the rpm - (see [Pre-releases](#pre-releases)), so it was skipped as in - [When a build fails](#when-a-build-fails). Once rc.2 is out, delete - that draft with `gh release delete v1.0.0-rc.1` and keep its tag. -3. Delete the old local tag that was never pushed (`git tag -d v1.0.0`). - Set `release-as` to `1.0.0` and remove `prerelease`. The release PR - shows up once a `feat:` or `fix:` has landed since the release - candidate. Merge it, and check that **v1.0.0** is GitHub's latest - release (#10). -4. Remove `release-as` from the config. From here on, versions follow the - commits. +## Before 1.0.1 + +Up to 1.0.0, release-please cut releases from a release PR, and kept +`CHANGELOG.md`. The v1.0.0-rc.1 tag has no release: its Linux build failed, +and the version was skipped. 1.0.0 is the first build with the updater. Anything installed before it, including locally built 0.1.0 packages, has to be replaced by hand once. @@ -246,7 +243,8 @@ glibc it was built against, and 22.04 sets that floor at **2.35**: Ubuntu GitHub will retire that runner. Moving to `ubuntu-24.04` raises the floor to **glibc 2.39**, which drops Debian 12 (and Ubuntu 22.04). Under the versioning rule that is a **major** release. Ship the runner change as -`feat!:` and say in the changelog which distros it leaves behind. +`feat!:`, with a `BREAKING CHANGE:` footer saying which distros it +leaves behind, so the release notes say it too. ## Local builds @@ -259,7 +257,8 @@ npm run tauri build -- --no-sign `scripts/install-local.sh` already does. A local build is only for the machine that built it: it carries that machine's glibc floor and can't -update itself. +update itself. It also says it is version 0.0.0, the repository's +placeholder ([Where the version lives](#where-the-version-lives)). ## Platform findings diff --git a/docs/adr/0002-release-version-lives-in-the-tag.md b/docs/adr/0002-release-version-lives-in-the-tag.md new file mode 100644 index 0000000..d929554 --- /dev/null +++ b/docs/adr/0002-release-version-lives-in-the-tag.md @@ -0,0 +1,11 @@ +--- +status: accepted +--- + +# A release's version lives in its tag, not in the repository + +Every push to `main` that carries a `feat:`, `fix:`, `perf:` or breaking commit releases straight away. The version is worked out from the conventional commits since the last stable `vX.Y.Z` tag, the pushed commit gets the tag, and the release builds stamp that version into `package.json`, `package-lock.json`, `Cargo.toml` and `Cargo.lock` before building. Nothing commits the version back to `main`, so those files hold the placeholder 0.0.0. This replaces release-please, whose release PR had to be merged by hand before anything shipped. Committing a bump straight to `main` from CI isn't possible either: the `main` ruleset requires CI checks on every commit and lets nobody bypass them. Weakening that rule, or keeping a bot PR that merges itself, would have been the price of an accurate version in the repository. + +## Consequences + +Local and dev builds report version 0.0.0. `CHANGELOG.md` stops at 1.0.0, and the notes on each GitHub release (which the app shows before updating) take its place. A release whose build fails keeps its tag, so the next release skips past that version. diff --git a/package-lock.json b/package-lock.json index 21b4684..5c71f9b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "reverb", - "version": "1.0.0", + "version": "0.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "reverb", - "version": "1.0.0", + "version": "0.0.0", "dependencies": { "@tanstack/react-query": "^5.101.4", "@tanstack/react-virtual": "^3.14.9", diff --git a/package.json b/package.json index 9a6fd7e..b7878bd 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "reverb", "private": true, - "version": "1.0.0", + "version": "0.0.0", "type": "module", "scripts": { "dev": "vite", diff --git a/release-please-config.json b/release-please-config.json deleted file mode 100644 index 4a7397f..0000000 --- a/release-please-config.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "//": [ - "release-please owns Reverb's version. See RELEASING.md.", - "The `node` release type is deliberate. The `rust` type can't bump a crate that inherits", - "`version.workspace = true`, or a root Cargo.toml without a [package] table", - "(googleapis/release-please#2111, still open), so don't 'fix' this to `rust`. `node` bumps", - "package.json and package-lock.json; the extra-files below bump the Cargo workspace version", - "and both workspace crates in Cargo.lock. (TOML strings come out of release-please's parser", - "as {value: ...} objects, hence `@.name.value`.) tauri.conf.json has no version: it inherits", - "the Cargo one. `scripts/check-versions.mjs` fails CI if any of these disagree.", - "`release-as` pins the first stable release to 1.0.0. Remove it once v1.0.0 is published." - ], - "packages": { - ".": { - "release-type": "node", - "include-component-in-tag": false, - "changelog-path": "CHANGELOG.md", - "draft": true, - "force-tag-creation": true, - "release-as": "1.0.0", - "extra-files": [ - { - "type": "toml", - "path": "Cargo.toml", - "jsonpath": "$.workspace.package.version" - }, - { - "type": "toml", - "path": "Cargo.lock", - "jsonpath": "$.package[?(@.name.value=='reverb' || @.name.value=='reverb-core')].version" - } - ] - } - } -} diff --git a/scripts/check-versions.mjs b/scripts/check-versions.mjs index d0aa8b3..c212215 100644 --- a/scripts/check-versions.mjs +++ b/scripts/check-versions.mjs @@ -1,13 +1,13 @@ #!/usr/bin/env node // Fail when the places Reverb's version is written down disagree. // -// release-please owns the version: its release PR bumps package.json and -// package-lock.json (the `node` release type), the Cargo workspace version -// (an `extra-files` entry) and both workspace crates in Cargo.lock. A bump -// that missed one of them would build a release whose parts disagree about -// what they are, so CI runs this on every push and PR, the release PR -// included. The Tauri config has no version of its own; it inherits the -// Cargo one. +// The version lives in package.json, package-lock.json, the Cargo workspace +// version and both workspace crates in Cargo.lock. In the repository they +// all hold the placeholder 0.0.0; each release build stamps its tag's +// version into all of them with set-version.mjs, then runs this. A file that +// was missed would build a release whose parts disagree about what they are, +// so CI also runs it on every push and PR. The Tauri config has no version +// of its own; it inherits the Cargo one. // // node scripts/check-versions.mjs @@ -62,8 +62,8 @@ if (process.argv[1] === fileURLToPath(import.meta.url)) { console.log(`${label.padEnd(width)} ${version ?? "(missing)"}`); } if (!ok) { - console.error("\nVersions disagree. release-please bumps all of these together;"); - console.error("a hand edit or a half-applied release PR leaves them out of step."); + console.error("\nVersions disagree. They hold the placeholder 0.0.0 and only a release"); + console.error("build changes them, all together (scripts/set-version.mjs). See RELEASING.md."); process.exit(1); } console.log("\nAll versions agree."); diff --git a/scripts/next-version.mjs b/scripts/next-version.mjs new file mode 100644 index 0000000..23b725a --- /dev/null +++ b/scripts/next-version.mjs @@ -0,0 +1,249 @@ +#!/usr/bin/env node +// Work out Reverb's next release from the conventional commits since the last. +// +// A release's version lives only in its git tag (docs/adr/0002). On every +// push to main, the release workflow runs this script. It reads the commits +// since the newest stable `vX.Y.Z` tag the commit descends from and decides +// whether they call for a release and what kind: +// +// breaking (`feat!:`, or a `BREAKING CHANGE:` footer) major +// feat minor +// fix, perf patch +// anything else (chore, ci, build, docs, refactor, ...) no release +// +// Merge commits are skipped. The commits they bring in are the ones counted. +// +// node scripts/next-version.mjs [--prerelease rc] [--notes-file notes.md] +// +// Prints the version and its release notes. Under GitHub Actions it also sets +// the step outputs `version`, `tag`, `prerelease` and `notes`. `version` is +// empty when there is nothing to release. + +import { execFileSync } from "node:child_process"; +import { randomUUID } from "node:crypto"; +import { appendFileSync, writeFileSync } from "node:fs"; +import { fileURLToPath } from "node:url"; +import { parseArgs } from "node:util"; + +const HEADER = /^(?[a-z]+)(?:\((?[^()\r\n]*)\))?(?!)?: (?.+)$/i; +const BREAKING_FOOTER = /^BREAKING[ -]CHANGE: *(.+)$/m; +const STABLE_TAG = /^v(\d+)\.(\d+)\.(\d+)$/; + +/** The changelog sections, in the order the notes list them. */ +const SECTIONS = [ + { type: "feat", title: "Features" }, + { type: "fix", title: "Bug Fixes" }, + { type: "perf", title: "Performance Improvements" }, +]; + +/** + * A commit's conventional-commit fields, or `null` when its message doesn't + * follow the convention. `breaking` holds what the commit says it breaks, or + * `null` when it doesn't break anything. + */ +export function parseCommit(hash, message) { + const [header = "", ...rest] = message.trim().split("\n"); + const match = HEADER.exec(header.trim()); + if (!match) return null; + const { type, scope, bang, subject } = match.groups; + const footer = BREAKING_FOOTER.exec(rest.join("\n")); + return { + hash, + type: type.toLowerCase(), + scope: scope?.trim() || null, + subject: subject.trim(), + breaking: footer ? footer[1].trim() : bang ? subject.trim() : null, + }; +} + +/** `major`, `minor` or `patch` for these commits, or `null` if they need no release. */ +export function bumpFor(commits) { + if (commits.some((commit) => commit.breaking)) return "major"; + if (commits.some((commit) => commit.type === "feat")) return "minor"; + if (commits.some((commit) => commit.type === "fix" || commit.type === "perf")) return "patch"; + return null; +} + +function parseStable(tag) { + const match = STABLE_TAG.exec(tag); + return match ? match.slice(1).map(Number) : null; +} + +/** Negative, zero or positive as `[major, minor, patch]` `a` is older than, equal to or newer than `b`. */ +function compareVersions(a, b) { + const i = a.findIndex((part, index) => part !== b[index]); + return i === -1 ? 0 : a[i] - b[i]; +} + +/** The highest stable `vX.Y.Z` tag among `tags`, or `null` if there is none. Pre-releases don't count. */ +export function latestStable(tags) { + let best = null; + for (const tag of tags) { + const version = parseStable(tag); + if (version && (!best || compareVersions(version, best.version) > 0)) best = { tag, version }; + } + return best?.tag ?? null; +} + +function increment([major, minor, patch], bump) { + if (bump === "major") return `${major + 1}.0.0`; + if (bump === "minor") return `${major}.${minor + 1}.0`; + return `${major}.${minor}.${patch + 1}`; +} + +/** + * What to release, given the newest stable tag the commit descends from + * (`base`), the conventional commits since it, every tag in the repository, + * and the tags already on this commit. With `prerelease` (say `rc`), the + * result is the next `-rc.N` of the version those commits call for. + * + * `version` is `null` when nothing should be released, and `reason` says why. + */ +export function planRelease({ base, commits, tags, headTags = [], prerelease = "" }) { + const bump = bumpFor(commits); + if (!bump) { + const since = base ? ` since ${base}` : ""; + return { version: null, reason: `Nothing to release: no feat, fix, perf or breaking commits${since}.` }; + } + + const next = increment(base ? parseStable(base) : [0, 0, 0], bump); + let version = next; + if (prerelease) { + if (!/^[0-9A-Za-z-]+$/.test(prerelease)) { + throw new Error(`"${prerelease}" can't be a pre-release identifier. Use letters, digits and "-", like "rc".`); + } + const prefix = `v${next}-${prerelease}.`; + const already = headTags.find((tag) => tag.startsWith(prefix)); + if (already) return { version: null, reason: `Nothing to release: this commit is already ${already}.` }; + const numbers = tags + .filter((tag) => tag.startsWith(prefix) && /^\d+$/.test(tag.slice(prefix.length))) + .map((tag) => Number(tag.slice(prefix.length))); + version = `${next}-${prerelease}.${Math.max(0, ...numbers) + 1}`; + } + + const tag = `v${version}`; + if (tags.includes(tag)) { + throw new Error(`${tag} already exists, but this commit doesn't descend from it. See RELEASING.md.`); + } + const since = base ? ` since ${base}` : ""; + return { + version, + tag, + previousTag: base, + prerelease: Boolean(prerelease), + reason: `Releasing ${tag}: a ${bump} bump for ${commits.length} commit(s)${since}.`, + }; +} + +/** `#12` in a commit subject, as a link to that issue or PR. */ +function linkIssues(text, repoUrl) { + if (!repoUrl) return text; + return text.replace(/(^|[\s(])#(\d+)\b/g, (_, before, number) => `${before}[#${number}](${repoUrl}/issues/${number})`); +} + +function entry(commit, text, repoUrl) { + const scope = commit.scope ? `**${commit.scope}:** ` : ""; + const short = commit.hash.slice(0, 7); + const link = repoUrl ? `[${short}](${repoUrl}/commit/${commit.hash})` : short; + return `* ${scope}${linkIssues(text, repoUrl)} (${link})`; +} + +/** + * The release notes: GitHub shows them on the release page, and the app + * shows them before it installs an update. The app drops the opening version + * heading (`ReleaseNotes.tsx`) because its panel already titles the version. + */ +export function releaseNotes({ version, tag, previousTag, commits, date, repoUrl }) { + const heading = + repoUrl && previousTag + ? `## [${version}](${repoUrl}/compare/${previousTag}...${tag}) (${date})` + : `## ${version} (${date})`; + const parts = [heading]; + + const breaking = commits.filter((commit) => commit.breaking); + if (breaking.length) { + const lines = breaking.map((commit) => entry(commit, commit.breaking, repoUrl)); + parts.push(`### ⚠ BREAKING CHANGES\n\n${lines.join("\n")}`); + } + for (const { type, title } of SECTIONS) { + const lines = commits.filter((commit) => commit.type === type).map((commit) => entry(commit, commit.subject, repoUrl)); + if (lines.length) parts.push(`### ${title}\n\n${lines.join("\n")}`); + } + return `${parts.join("\n\n")}\n`; +} + +function git(...args) { + return execFileSync("git", args, { encoding: "utf8" }); +} + +function lines(text) { + return text.split("\n").map((line) => line.trim()).filter(Boolean); +} + +/** The conventional commits after `base` up to HEAD, oldest first. */ +function commitsSince(base) { + const range = base ? `${base}..HEAD` : "HEAD"; + return git("log", "--no-merges", "--reverse", "--format=%H%x1f%B%x1e", range) + .split("\x1e") + .map((record) => record.trim()) + .filter(Boolean) + .map((record) => { + const [hash, message = ""] = record.split("\x1f"); + return parseCommit(hash, message); + }) + .filter(Boolean); +} + +function setOutputs(outputs) { + const file = process.env.GITHUB_OUTPUT; + if (!file) return; + for (const [name, value] of Object.entries(outputs)) { + if (value.includes("\n")) { + const delimiter = `EOF_${randomUUID()}`; + appendFileSync(file, `${name}<<${delimiter}\n${value}\n${delimiter}\n`); + } else { + appendFileSync(file, `${name}=${value}\n`); + } + } +} + +function main() { + const { values } = parseArgs({ + options: { prerelease: { type: "string", default: "" }, "notes-file": { type: "string" } }, + }); + const base = latestStable(lines(git("tag", "--merged", "HEAD", "--list", "v*"))); + const commits = commitsSince(base); + const plan = planRelease({ + base, + commits, + tags: lines(git("tag", "--list", "v*")), + headTags: lines(git("tag", "--points-at", "HEAD", "--list", "v*")), + prerelease: values.prerelease.trim(), + }); + + if (!plan.version) { + console.log(plan.reason); + setOutputs({ version: "", tag: "", prerelease: "false", notes: "" }); + return; + } + + const { GITHUB_SERVER_URL: server, GITHUB_REPOSITORY: repository } = process.env; + const notes = releaseNotes({ + ...plan, + commits, + date: new Date().toISOString().slice(0, 10), + repoUrl: server && repository ? `${server}/${repository}` : null, + }); + console.log(`${plan.reason}\n\n${notes}`); + if (values["notes-file"]) writeFileSync(values["notes-file"], notes); + setOutputs({ version: plan.version, tag: plan.tag, prerelease: String(plan.prerelease), notes }); +} + +if (process.argv[1] === fileURLToPath(import.meta.url)) { + try { + main(); + } catch (error) { + console.error(process.env.GITHUB_ACTIONS ? `::error::${error.message}` : error.message); + process.exit(1); + } +} diff --git a/scripts/next-version.test.mjs b/scripts/next-version.test.mjs new file mode 100644 index 0000000..dc7c36c --- /dev/null +++ b/scripts/next-version.test.mjs @@ -0,0 +1,190 @@ +import { describe, expect, it } from "vitest"; +import { bumpFor, latestStable, parseCommit, planRelease, releaseNotes } from "./next-version.mjs"; + +let counter = 0; +/** A parsed commit from a message, with a made-up 40-character hash. */ +function commit(message) { + counter += 1; + return parseCommit(String(counter).padStart(40, "a"), message); +} + +describe("parseCommit", () => { + it("reads the type, scope and subject", () => { + expect(parseCommit("abc", "fix(queue): stop the queue lagging\n\nLonger body.")).toEqual({ + hash: "abc", + type: "fix", + scope: "queue", + subject: "stop the queue lagging", + breaking: null, + }); + }); + + it("reads `!` as breaking", () => { + expect(parseCommit("abc", "feat!: drop Debian 12").breaking).toBe("drop Debian 12"); + }); + + it.each(["BREAKING CHANGE", "BREAKING-CHANGE"])("reads a %s footer as breaking", (footer) => { + const parsed = parseCommit("abc", `feat: newer runner\n\nBody.\n\n${footer}: glibc 2.39 or newer`); + expect(parsed.breaking).toBe("glibc 2.39 or newer"); + }); + + it.each(["Merge pull request #33 from someone/branch", "fixed the thing", "fix:no space", ""])( + "returns null for %j", + (message) => { + expect(parseCommit("abc", message)).toBeNull(); + }, + ); +}); + +describe("bumpFor", () => { + it.each([ + [["fix: a"], "patch"], + [["perf: a"], "patch"], + [["fix: a", "feat: b"], "minor"], + [["fix: a", "feat: b", "refactor!: c"], "major"], + [["chore: a\n\nBREAKING CHANGE: settings reset"], "major"], + [["docs: a", "chore: b", "ci: c", "build: d", "refactor: e", "test: f"], null], + [[], null], + ])("%j → %s", (messages, bump) => { + expect(bumpFor(messages.map(commit))).toBe(bump); + }); +}); + +describe("latestStable", () => { + it("picks the highest stable tag by version, not by name", () => { + expect(latestStable(["v1.9.0", "v1.10.0", "v1.2.3", "v2.0.0-rc.1"])).toBe("v1.10.0"); + }); + + it("ignores pre-releases and anything that isn't a version tag", () => { + expect(latestStable(["v1.0.0-rc.2", "vnext", "1.4.0"])).toBeNull(); + }); +}); + +describe("planRelease", () => { + const tags = ["v1.0.0-rc.1", "v1.0.0-rc.2", "v1.0.0"]; + + it.each([ + ["fix: a", "1.0.1"], + ["feat: a", "1.1.0"], + ["feat!: a", "2.0.0"], + ])("bumps v1.0.0 for %j to %s", (message, version) => { + const plan = planRelease({ base: "v1.0.0", commits: [commit(message)], tags }); + + expect(plan).toMatchObject({ version, tag: `v${version}`, previousTag: "v1.0.0", prerelease: false }); + }); + + it("releases nothing when no commit calls for it", () => { + const plan = planRelease({ base: "v1.0.0", commits: [commit("docs: a")], tags }); + + expect(plan.version).toBeNull(); + expect(plan.reason).toContain("since v1.0.0"); + }); + + it("numbers pre-releases after the ones already tagged", () => { + const plan = planRelease({ + base: "v1.0.0", + commits: [commit("feat: a")], + tags: [...tags, "v1.1.0-rc.1", "v1.1.0-rc.2", "v1.1.0-beta.7"], + prerelease: "rc", + }); + + expect(plan).toMatchObject({ version: "1.1.0-rc.3", tag: "v1.1.0-rc.3", prerelease: true }); + }); + + it("starts a pre-release at .1", () => { + const plan = planRelease({ base: "v1.0.0", commits: [commit("fix: a")], tags, prerelease: "rc" }); + + expect(plan.version).toBe("1.0.1-rc.1"); + }); + + it("doesn't tag the same commit as a second pre-release", () => { + const plan = planRelease({ + base: "v1.0.0", + commits: [commit("fix: a")], + tags: [...tags, "v1.0.1-rc.1"], + headTags: ["v1.0.1-rc.1"], + prerelease: "rc", + }); + + expect(plan.version).toBeNull(); + expect(plan.reason).toContain("already v1.0.1-rc.1"); + }); + + it("refuses a pre-release identifier that would break the version", () => { + expect(() => planRelease({ base: "v1.0.0", commits: [commit("fix: a")], tags, prerelease: "rc.1" })).toThrow( + /pre-release identifier/, + ); + }); + + it("refuses a tag that already exists elsewhere", () => { + expect(() => + planRelease({ base: "v1.0.0", commits: [commit("fix: a")], tags: [...tags, "v1.0.1"] }), + ).toThrow(/v1\.0\.1 already exists/); + }); + + it("starts from 0.0.0 without a stable tag", () => { + expect(planRelease({ base: null, commits: [commit("feat: a")], tags: [] }).version).toBe("0.1.0"); + }); +}); + +describe("releaseNotes", () => { + const repoUrl = "https://github.com/owner/repo"; + + it("lists breaking changes, then features, fixes and performance, with links", () => { + const commits = [ + commit("fix(queue): stop the queue lagging"), + commit("feat: recently played tab (#19)"), + commit("docs: glossary"), + commit("perf: faster scrolling"), + commit("feat!: newer Linux runner\n\nBREAKING CHANGE: needs glibc 2.39"), + ]; + const notes = releaseNotes({ + version: "2.0.0", + tag: "v2.0.0", + previousTag: "v1.0.0", + commits, + date: "2026-11-10", + repoUrl, + }); + const link = (c) => `[${c.hash.slice(0, 7)}](${repoUrl}/commit/${c.hash})`; + + expect(notes).toBe( + [ + `## [2.0.0](${repoUrl}/compare/v1.0.0...v2.0.0) (2026-11-10)`, + "", + "### ⚠ BREAKING CHANGES", + "", + `* needs glibc 2.39 (${link(commits[4])})`, + "", + "### Features", + "", + `* recently played tab ([#19](${repoUrl}/issues/19)) (${link(commits[1])})`, + `* newer Linux runner (${link(commits[4])})`, + "", + "### Bug Fixes", + "", + `* **queue:** stop the queue lagging (${link(commits[0])})`, + "", + "### Performance Improvements", + "", + `* faster scrolling (${link(commits[3])})`, + "", + ].join("\n"), + ); + }); + + it("opens with a heading the app's release notes panel strips", () => { + const notes = releaseNotes({ + version: "1.0.1", + tag: "v1.0.1", + previousTag: null, + commits: [commit("fix: a")], + date: "2026-11-10", + repoUrl: null, + }); + + expect(notes).toMatch(/^## 1\.0\.1 \(2026-11-10\)\n\n### Bug Fixes\n\n\* a \(\w{7}\)\n$/); + // The same pattern as withoutVersionHeading in src/components/update/ReleaseNotes.tsx. + expect(notes.replace(/^\s*#{1,6}\s*\[?v?\d+\.\d+\.\d+[^\n]*\n*/, "")).toMatch(/^### Bug Fixes/); + }); +}); diff --git a/scripts/set-version.mjs b/scripts/set-version.mjs new file mode 100644 index 0000000..0c2a209 --- /dev/null +++ b/scripts/set-version.mjs @@ -0,0 +1,90 @@ +#!/usr/bin/env node +// Write a release's version into every file that holds Reverb's version. +// +// In the repository these files all hold the placeholder 0.0.0, because a +// release's version lives only in its git tag (docs/adr/0002). Each release +// build runs this with the tag's version before it builds, so the app, its +// bundles and latest.json agree on what they are. The files are the ones +// check-versions.mjs reads: package.json, package-lock.json, the Cargo +// workspace version, and both workspace crates in Cargo.lock. The Tauri +// config has no version of its own; it inherits the Cargo one. +// +// node scripts/set-version.mjs 1.4.2 + +import { readFileSync, writeFileSync } from "node:fs"; +import { dirname, join } from "node:path"; +import { fileURLToPath } from "node:url"; + +const SEMVER = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/; +const CRATES = ["reverb", "reverb-core"]; + +/** npm writes its JSON files with two-space indents and a trailing newline. */ +function json(value) { + return `${JSON.stringify(value, null, 2)}\n`; +} + +/** `manifest` with the `version` in its `[workspace.package]` table set to `version`. */ +function withWorkspaceVersion(manifest, version) { + const table = /^\[workspace\.package\]\s*$([\s\S]*?)(?=^\[|(?![\s\S]))/m.exec(manifest); + const line = /^version\s*=\s*"[^"]*"/m; + if (!table || !line.test(table[1])) { + throw new Error("Cargo.toml has no version in [workspace.package]."); + } + const start = table.index + table[0].length - table[1].length; + const body = table[1].replace(line, `version = "${version}"`); + return manifest.slice(0, start) + body + manifest.slice(start + table[1].length); +} + +/** `lockfile` with the workspace crates' `[[package]]` entries at `version`. */ +function withLockedVersions(lockfile, version) { + const found = new Set(); + const entries = lockfile.split(/^(?=\[\[package\]\]\s*$)/m).map((entry) => { + const name = /^name = "([^"]+)"$/m.exec(entry)?.[1]; + if (!CRATES.includes(name)) return entry; + found.add(name); + return entry.replace(/^version = "[^"]*"$/m, `version = "${version}"`); + }); + const missing = CRATES.filter((name) => !found.has(name)); + if (missing.length) throw new Error(`Cargo.lock has no entry for ${missing.join(" or ")}.`); + return entries.join(""); +} + +/** + * Set every version to `version`, reading and writing through `read(path)` + * and `write(path, contents)` (paths relative to the repo root). + */ +export function setVersion(read, write, version) { + if (!SEMVER.test(version)) throw new Error(`"${version}" isn't a version like 1.4.2 or 1.5.0-rc.1.`); + + const pkg = JSON.parse(read("package.json")); + const lock = JSON.parse(read("package-lock.json")); + if (!lock.packages?.[""]) throw new Error('package-lock.json has no packages[""] entry.'); + pkg.version = version; + lock.version = version; + lock.packages[""].version = version; + + // Work everything out before writing anything, so a failure leaves no file half-done. + const files = { + "package.json": json(pkg), + "package-lock.json": json(lock), + "Cargo.toml": withWorkspaceVersion(read("Cargo.toml"), version), + "Cargo.lock": withLockedVersions(read("Cargo.lock"), version), + }; + for (const [path, contents] of Object.entries(files)) write(path, contents); +} + +if (process.argv[1] === fileURLToPath(import.meta.url)) { + const root = join(dirname(fileURLToPath(import.meta.url)), ".."); + const version = process.argv[2] ?? ""; + try { + setVersion( + (path) => readFileSync(join(root, path), "utf8"), + (path, contents) => writeFileSync(join(root, path), contents), + version, + ); + } catch (error) { + console.error(error.message); + process.exit(1); + } + console.log(`Set every version to ${version}.`); +} diff --git a/scripts/set-version.test.mjs b/scripts/set-version.test.mjs new file mode 100644 index 0000000..e179b91 --- /dev/null +++ b/scripts/set-version.test.mjs @@ -0,0 +1,98 @@ +import { describe, expect, it } from "vitest"; +import { checkVersions } from "./check-versions.mjs"; +import { setVersion } from "./set-version.mjs"; + +const CARGO_TOML = [ + "[workspace]", + 'members = ["src-tauri", "crates/reverb-core"]', + "", + "[workspace.package]", + 'version = "0.0.0"', + 'edition = "2021"', + "", + "[workspace.dependencies]", + 'serde = { version = "1", features = ["derive"] }', + "", +].join("\n"); + +const CARGO_LOCK = [ + "[[package]]", + 'name = "reqwest"', + 'version = "0.13.1"', + "", + "[[package]]", + 'name = "reverb"', + 'version = "0.0.0"', + "dependencies = [", + ' "reverb-core",', + "]", + "", + "[[package]]", + 'name = "reverb-core"', + 'version = "0.0.0"', + "", +].join("\n"); + +/** An in-memory copy of the version files, every one at 0.0.0, with `edit` applied on top. */ +function repo(edit = {}) { + const files = { + "package.json": `${JSON.stringify({ name: "reverb", private: true, version: "0.0.0" }, null, 2)}\n`, + "package-lock.json": `${JSON.stringify( + { name: "reverb", version: "0.0.0", lockfileVersion: 3, packages: { "": { name: "reverb", version: "0.0.0" } } }, + null, + 2, + )}\n`, + "Cargo.toml": CARGO_TOML, + "Cargo.lock": CARGO_LOCK, + ...edit, + }; + return { + files, + read: (path) => { + if (!(path in files)) throw new Error(`no such file: ${path}`); + return files[path]; + }, + write: (path, contents) => { + files[path] = contents; + }, + }; +} + +describe("setVersion", () => { + it.each(["1.4.2", "1.5.0-rc.1"])("sets every version check-versions reads to %s", (version) => { + const { read, write } = repo(); + + setVersion(read, write, version); + + const result = checkVersions(read); + expect(result.ok).toBe(true); + expect(new Set(result.versions.map(([, found]) => found))).toEqual(new Set([version])); + }); + + it("changes only the version lines", () => { + const { files, read, write } = repo(); + + setVersion(read, write, "1.4.2"); + + expect(files["Cargo.toml"]).toBe(CARGO_TOML.replace('version = "0.0.0"', 'version = "1.4.2"')); + expect(files["Cargo.lock"]).toBe(CARGO_LOCK.replaceAll('version = "0.0.0"', 'version = "1.4.2"')); + expect(files["Cargo.lock"]).toContain('name = "reqwest"\nversion = "0.13.1"'); + expect(files["package.json"]).toBe( + `${JSON.stringify({ name: "reverb", private: true, version: "1.4.2" }, null, 2)}\n`, + ); + }); + + it.each(["v1.4.2", "1.4", "", "1.4.2-"])("refuses %j", (version) => { + const { read, write } = repo(); + + expect(() => setVersion(read, write, version)).toThrow(/isn't a version/); + }); + + it("writes nothing when a file is missing its version", () => { + const { files, read, write } = repo({ "Cargo.lock": CARGO_LOCK.replace('name = "reverb-core"', 'name = "other"') }); + const before = { ...files }; + + expect(() => setVersion(read, write, "1.4.2")).toThrow(/reverb-core/); + expect(files).toEqual(before); + }); +}); diff --git a/src/components/update/ReleaseNotes.tsx b/src/components/update/ReleaseNotes.tsx index 9fc1598..98cf8d1 100644 --- a/src/components/update/ReleaseNotes.tsx +++ b/src/components/update/ReleaseNotes.tsx @@ -1,6 +1,6 @@ -// A release's CHANGELOG.md section, rendered as Markdown. The notes come from -// the release manifest on GitHub, so raw HTML is never rendered, only shown -// as text, and links leave the app for the browser. +// A release's notes, rendered as Markdown. The notes come from the release +// manifest on GitHub, so raw HTML is never rendered, only shown as text, and +// links leave the app for the browser. import Markdown from "markdown-to-jsx/react"; import type { ReactNode } from "react"; @@ -38,8 +38,9 @@ const OPTIONS = { }; /** - * release-please opens each section with its own "## [1.0.1](compare) (date)" - * heading. The panel already titles the version and date, so drop it. + * Release notes open with their own "## [1.0.1](compare) (date)" heading + * (scripts/next-version.mjs). The panel already titles the version and date, + * so drop it. */ function withoutVersionHeading(markdown: string): string { return markdown.replace(/^\s*#{1,6}\s*\[?v?\d+\.\d+\.\d+[^\n]*\n*/, ""); diff --git a/src/lib/updater/updateController.ts b/src/lib/updater/updateController.ts index e72e0f1..a298693 100644 --- a/src/lib/updater/updateController.ts +++ b/src/lib/updater/updateController.ts @@ -7,7 +7,7 @@ /** What the UI shows about a found update. */ export interface UpdateInfo { version: string; - /** Release notes, Markdown (the release's CHANGELOG.md section). */ + /** Release notes, Markdown (the GitHub release's body). */ notes: string; /** When the release was published, as the manifest gives it. */ date: string | null;