Skip to content

feat(versioning): Update extra version files during automatic bumps - #955

Merged
BYK merged 5 commits into
masterfrom
feat/versioning-files
Nov 2, 2026
Merged

BYK merged 5 commits into
masterfrom
feat/versioning-files

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Closes #948.

A release unit can now list extra files that automatic version bumping writes the new version into. Until now, the only option was a custom preReleaseCommand, which also turns off the automatic bump.

minVersion: '3.8.0'
workspaces:
  packages/cli:
    versioning:
      policy: auto
      files:
        - path: packages/mcp-server/package.json          # json, field: version
        - path: packages/cli/plugins/sentry-cli/.claude-plugin/plugin.json
          stripPrerelease: true
        - path: packages/cli/plugins/sentry-cli/skills/sentry-cli/**/*.md   # frontmatter
        - path: crates/*/Cargo.toml                       # toml, field: package.version
        - path: src/sdk/_version.py
          format: regex
          pattern: '/__version__ = "([^"]+)"/'

Formats

The formats cover every kind of file Craft's version-bumping targets edit, plus frontmatter, and regex as an escape hatch. Craft infers the format from the file name:

format Inferred for Updates Implementation
msbuild *.csproj, *.fsproj, *.vbproj, *.props, *.targets Version properties, and clears <VersionSuffix> when there's a <VersionPrefix> The nuget target's code
gem *.gemspec, version.rb spec.version = "…", VERSION = "…" The gem target's patterns
mix mix.exs version: "…", @version "…" The hex target's patterns
json *.json String at field (default version) New: jsonc-parser replaces only the value's characters
toml *.toml String at field. Default: package.version in Cargo.toml, project.version in pyproject.toml, otherwise version New: a table-aware line scanner that skips arrays of tables. Shared with the pypi target
yaml *.yaml, *.yml Scalar at field; skips sequences and block scalars New: an indentation-aware scanner. The result is parsed back with js-yaml to confirm the new version is at field. Shared with the pub-dev target
frontmatter *.md, *.mdx Same as yaml, inside the --- frontmatter Shares the yaml code
regex never inferred Capturing group of every match of a /source/flags string (same syntax as includeNames) New

The gem, hex and nuget patterns moved to src/utils/versionPatterns.ts, so those targets and versioning.files share one definition. NugetTarget.updateVersionInXml now calls the shared setMsBuildVersion. Behavior is unchanged.

The new TOML and YAML editors live in the same module, and the targets that direct-edit those files now use them:

  • pypi direct edit: replaced its regex, which rewrote the first version = line in any table, with the TOML editor on project.version. Hatch, poetry and setuptools_scm are unchanged.
  • pub-dev: edits version in place instead of loading and re-dumping the whole pubspec with js-yaml, which dropped comments and formatting. It falls back to the old rewrite only when there's no single top-level version to edit, so a pubspec without one still gets it added.

npm (npm version) and crates (cargo set-version) keep their CLIs: those also update package-lock.json, workspace members and dependent crates' version requirements, which a one-file edit doesn't cover. json has no target to share with, since only npm writes JSON.

Design decisions

  • Location: versioning.files, with stripPrerelease set on each entry. Workspaces replace versioning as a whole, like every other field except github, so a workspace that declares versioning also replaces the top-level files. The workspace docs say so.

  • Paths are relative to the repository root, same as changelog.includePaths. Absolute paths and .. are rejected using the same safety check as workspace globs. Glob matches that resolve outside the repository (symlinks) are dropped.

  • preReleaseCommand plus versioning.files is a config error. The check runs on the resolved config, so a workspace can't get files from one level and a preReleaseCommand from another. preReleaseCommand: '' counts as a conflict too. An empty files: [] is allowed.

  • minVersion: 3.8.0 is required (3.7.0 shipped without this feature). Older Crafts silently drop unknown keys. This gate makes those configs also set a minVersion that older Crafts refuse to run, instead of releasing without updating the files.

  • Strict, all-or-nothing: a path that matches no files, or a matched file with nothing to update, fails craft prepare before any file is written. Writes go through safeFs. In a dry run, the files are written to the temporary copy of the repo (the path comes from the isolated git client).

  • Updated files count as a bump: they trigger the --all commit, and a unit whose targets can't bump anything no longer gets the "nothing to bump" warning or error.

  • postReleaseBump writes them too. postReleaseBump (feat(publish): Add built-in development version bump after release #950) writes the development version with the same runPreReleaseCommand step, so it now passes versioning.files as well. With stripPrerelease, a 1.3.0-dev.0 development version is written as 1.3.0. A template that isn't semver, such as version: nightly, can't be stripped: the bump fails with a warning, and the release itself still succeeds.

Testing

  • src/utils/__tests__/versionFiles.test.ts (21 tests): every format, formatting preservation, default TOML fields, nested YAML keys that skip sequences and block scalars, globs, CRLF, symlink escape, writing nothing when a later entry fails, several entries for one file.
  • src/__tests__/config.test.ts: format inference, schema errors, the minVersion gate, unsafe paths, the preReleaseCommand conflict including the inherited case.
  • runPreReleaseCommand tests in src/commands/__tests__/prepare.test.ts, plus a postReleaseBump test in publish-main.test.ts. Existing gem, hex and nuget bump tests still pass with the shared patterns. New versionBump.test.ts cases cover the pypi edit staying in [project], pubspec comments surviving, and a pubspec without a version still getting one.
  • pnpm typecheck, pnpm lint and prettier --check . are clean.
  • Merged with master (3.7.1). pnpm test: 1883 passed. 19 failed, all in prepare-dry-run.e2e plus one git.test.ts case, the same tests that fail on unmodified master in my sandbox. They fail because the sandbox rejects test-repo commits with custom git identities. The PR's checks so far are CodeQL, Socket and Semgrep, with no test job, so those tests have only run locally.

via @BYK.

--

View Session in Sentry

Add versioning.files so a release unit can write the release version into
files its targets do not bump: JSON fields, YAML frontmatter keys, and regex
matches, with optional prerelease stripping. Paths are relative to the
repository root. Combining it with preReleaseCommand is a config error.

Closes #948

Co-Authored-By: BYK <[email protected]>
Comment thread src/schemas/project_config.ts Resolved
sentry-junior Bot and others added 2 commits November 2, 2026 22:06
Add toml, yaml, msbuild, gem, and mix formats to versioning.files, inferred
from the file name, next to json, frontmatter, and the regex escape hatch.
The gem, hex, and nuget targets now share their version patterns with
versioning.files through src/utils/versionPatterns.ts.
# Conflicts:
#	src/commands/__tests__/prepare.test.ts
#	src/commands/prepare.ts

Co-Authored-By: BYK <[email protected]>
@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-11-02 22:54 UTC

…b-dev targets

pub-dev no longer re-dumps pubspec.yaml (dropping comments and formatting)
when it has a single top-level version; it falls back to the old rewrite
only when there's no version to edit in place. pypi's direct edit now only
touches project.version instead of the first version = line in the file.

Co-Authored-By: BYK <[email protected]>
@BYK
BYK marked this pull request as ready for review November 2, 2026 22:38

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit e2afaf9. Configure here.

Comment thread src/config.ts Resolved
versioning.files reused the workspace path check, which limits segments to
[A-Za-z0-9_.-] and so rejected paths like packages/@scope/pkg/package.json.
These paths are only matched against files in the repository, so only reject
absolute paths, backslashes, and empty, . or .. segments (including in brace
alternatives).
@BYK
BYK merged commit b6d4d48 into master Nov 2, 2026
22 checks passed
@BYK
BYK deleted the feat/versioning-files branch November 2, 2026 22:54
BYK added a commit to getsentry/toolkit that referenced this pull request Nov 3, 2026
…1825)

Craft 3.8.0 adds `versioning.files` (getsentry/craft#955, which closes
getsentry/craft#948, filed with toolkit as the example). A release unit
can now list extra files for Craft's automatic version bump, and
`postReleaseBump` writes them too. The CLI workspace used a custom
`preReleaseCommand` only because that option didn't exist, and that
command turned off the automatic bump.

What moved where:

- `packages/cli/package.json`: Craft's npm target already bumps it once
the `preReleaseCommand` is gone.
- `packages/mcp-server/package.json`, the Claude plugin's `plugin.json`
(with `stripPrerelease: true`, so it stays `X.Y.Z` on `-dev` versions),
and the version frontmatter in the CLI skill's `SKILL.md` and
`references/*.md` are now `versioning.files` entries in `.craft.yml`.
- `packages/cli/script/bump-version.ts` and its test are gone. The
release docs and the comment in the mcp-server bundle script now point
at `.craft.yml`.

`minVersion` goes from 3.7.0 to 3.8.0. Craft requires that for
`versioning.files`, and Craft rejects a config that sets both
`versioning.files` and `preReleaseCommand`.

Craft's file matching is strict: it fails `craft prepare` if a path
matches nothing or a matched file has no version to update. Every file
in `references/` has exactly one `version:` frontmatter line, so the
glob is safe. The skill copies under
`apps/cli-docs/public/.well-known/skills/` and
`packages/cli/.cursor/skills/` are symlinks to the plugin skill, so they
need no entries.

I ran `craft prepare --dry-run --workspace packages/cli` with Craft
3.8.0 for `99.0.0` and `99.1.0-dev.0`. Both changed the same 45 files,
and only their version lines. `plugin.json` got `99.1.0` for the
prerelease.

<!-- junior-request-attribution:start -->
via @BYK.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:agent%3A2a1d56d4826388e37a7d9a96072b705b -->

--

[View Session in
Sentry](https://sentry.sentry.io/explore/conversations/agent%3A2a1d56d4826388e37a7d9a96072b705b/?project=4510944073809921)

<!-- junior-session-footer:end -->

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: BYK <[email protected]>

This branch was successfully deployed

1 active deployment
false — 31ae257d Deployed Nov 2, 2026 by sentry-junior[bot] via Build #3292
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sync the release version into extra files during a release

1 participant