Skip to content

Two-Stage Release ​

By default, one Versu run does everything: it computes the new versions, writes them to your build files, generates changelogs and release notes, then commits, pushes and tags. That's the simplest setup, but it leaves no room to update files that depend on the new version before the release commit is made.

Common examples:

  • Source files generated from the version (a version.ts, a BuildConfig constant, an OpenAPI spec)
  • Lockfiles or manifests that a tool has to regenerate
  • Docs, badges or Helm charts that embed the version
  • A build or test of the bumped tree that should pass before anything is tagged

A two-stage release splits the run in two so your own steps can run in between:

StageWhat it doesGit
prepareComputes versions; writes version files, changelogs and release notes; saves a release stateNone
your stepsAnything: code generation, builds, tests, other actions-
finalizeChecks the tree still matches the prepared release, then commits, pushes and tagsAll of it

Everything changed between the two stages goes into the same release commit, and the tags point at that commit.

GitHub Action ​

Run both stages in the same job, so they share the checkout:

yaml
name: Release

on:
  workflow_dispatch:

jobs:
  release:
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v7
        with:
          fetch-depth: 0

      - uses: actions/setup-node@v6
        with:
          node-version: 24

      - run: npm i -g @versu/plugin-node

      - name: Prepare release
        id: versu
        uses: versuhq/versu@v4
        with:
          mode: prepare
          tag-version-prefix: v

      - name: Regenerate files that embed the version
        if: steps.versu.outputs.bumped == 'true'
        run: |
          npm ci
          npm run codegen
          npm test

      - name: Finalize release
        uses: versuhq/versu@v4
        with:
          mode: finalize

The finalize step doesn't need an if:. When prepare finds nothing to release, finalize does nothing and succeeds.

CLI ​

bash
versu run prepare --tag-version-prefix v
npm run codegen
versu run finalize

Library ​

In code, prepare() returns a PreparedRelease, and its only method is finalize(). So a release can't be finalized unless it was prepared:

typescript
import { Versu } from "@versu/core";

const versu = new Versu({ repoRoot: "." });

const prepared = await versu.prepare({ tagVersionPrefix: "v" });

if (prepared.bumped) {
  await regenerateSources(prepared.changedModules);
}

const finalized = await prepared.finalize({ pushChanges: true });
console.log(finalized.createdTags);

prepare() also saves the state to a file, so the release can be finalized in a different process. There, resume() picks it up:

typescript
const prepared = await new Versu({ repoRoot: "." }).resume(); // reads the state file
await prepared.finalize();

release() is the same two stages with nothing in between: prepare(), then finalize(), with the state kept in memory and never written to a file.

A failed finalize() leaves the release prepared, so you can fix the problem and call it again. Once it succeeds, calling it again throws.

Which options go where ​

Options fall into two groups.

Set these on prepare only. They decide what prepare writes, such as the tag names used in changelog links and the release notes file. Prepare saves them in the release state, and finalize always uses the saved values, so the tags can never disagree with the files. The library's finalize() and the CLI's versu run finalize don't accept them at all. The GitHub Action accepts every input in every mode, and simply ignores these when finalizing.

  • tag-version-prefix, strip-module-prefix
  • release-notes-filename
  • prerelease-mode, append-snapshot (temporary versions are never tagged)
  • Everything else that affects version calculation or file contents: prerelease-id, bump-unchanged, add-build-metadata, timestamp-versions, generate-changelog, generate-release-notes, changelog-filename, adapter, from-ref

Set these on finalize. Prepare does no git work, so these only matter in finalize:

  • push-changes, create-tags, sequential-tag-push, commit-release-notes

dry-run and state-file apply to both stages.

What finalize checks ​

Before it commits anything, finalize checks the following and stops with an error if any check fails. Nothing is committed or tagged in that case.

  1. A release state exists. Run prepare first.
  2. HEAD hasn't moved. A commit made between the stages could change which versions are right. Discard the prepared changes and run prepare again.
  3. The versions on disk still match the plan. Finalize reads the versions back through the adapter (for example from package.json or gradle.properties) and compares them with what prepare planned. This catches a step that rewrote a version by mistake, for example by running npm version. Because the check goes through the adapter, the plugins need to be available in the finalize step as well. In a single job they already are.

When a check fails, the release state is kept, so you can fix the problem and run finalize again.

The same applies if the release commit can't be pushed, for example to a protected branch. Finalize fails before creating any tags and keeps the state. The commit stays local, so undo it with git reset --soft HEAD~1, fix the problem and run finalize again.

The release state file ​

By default, prepare saves the state to .git/versu/release-state.json. That location is inside the git directory, so the file is never committed and never makes the working tree look dirty. Finalize deletes it once it finishes.

You can choose another location with state-file (Action) or --state-file (CLI). Relative paths are resolved against the repository root. If you put the file inside the working tree, finalize leaves it out of the release commit.

The file records what prepare found and planned: the HEAD commit, the adapter, the changed and discovered modules, the changelog and release notes paths, each changed module's tag name, and the release notes filename. Treat it as internal to Versu, and run both stages with the same Versu version.

Dry run ​

  • prepare with dry-run computes everything and returns the result, but writes no files and saves no state.
  • finalize with dry-run runs the checks and logs what it would commit and tag, without changing anything.
  • A state prepared in dry-run mode can only be finalized in dry-run mode, because nothing was written to disk.

Prepare requires a clean working tree ​

Prepare refuses to run if the working tree has uncommitted changes, because finalize commits the whole tree (git add .). Anything that was already dirty would end up in the release commit.

Released under the MIT License.