Version Bumper
A VS Code extension that asks on every commit how to bump the project version. It also keeps the changelog and release tags in step.
On every commit, a dialog asks:
| Choice |
Example (from 1.4.7) |
What happens |
| Build |
1.4.8 |
The version files and a new CHANGELOG.md entry go into the same commit. |
| Minor |
1.5.7 |
Same as Build, and the commit is tagged v1.5.7. |
| Major |
2.0.7 |
Same as Minor. Minor resets to 0. |
| No version change |
1.4.7 |
The commit goes through unchanged. |
| Cancel |
|
The commit is stopped. |
Nothing goes up on its own. On push, release tags you haven't pushed yet go along automatically.
The build number keeps counting across releases. To reset it to 0 on every minor or major, turn on versionBumper.resetBuildOnRelease.
The status bar shows the current version; click it for all actions. When it shows a yellow hooks off, click it to install the git hooks for that repo.
Where the version lives
The extension finds the version file on its own:
- Each
package.json, composer.json, config/version.php or version.php that already has a version is updated. package-lock.json is updated together with package.json.
- If none has a version:
- Laravel app (has
artisan): creates config/version.php. Read it with config('version.version').
- Composer package: adds
"version" to composer.json.
- Node package: adds
"version" to package.json.
- Anything else: creates
version.php, which returns ['version' => '0.1.0'].
To choose the file yourself, set versionBumper.versionFile.
Changelog
Every version change adds an entry to the top of the changelog. Each entry lists the commits since the previous version change, including the commit you're making. The last commit that touched the changelog marks the previous version change.
When the changelog is missing or has no entries yet, the first version change fills it in from git history. Every past commit that changed the version in your version file (e.g. package.json) gets its own entry, holding the commits since the version before it. If the version file has no history, v* tags are used instead. Regenerate CHANGELOG from Git History does the same at any time, but it overwrites the file. Commits are grouped by Conventional Commits type: feat → Features, fix → Bug Fixes, type!: → Breaking Changes, chore/ci/test → Maintenance, everything else → Other Changes. Regenerate CHANGELOG from Git History rebuilds the whole file from your v* tags.
How it works
The extension adds a small block to the pre-commit, post-commit and pre-push hooks in .git/hooks. If you use husky, the block goes into .husky/. Hooks you already have are kept.
- pre-commit calls back into VS Code over
127.0.0.1, using a per-repository token stored in .git/version-bumper.port. VS Code shows the dialog, writes the new version, and the hook stages it.
- post-commit adds the changelog entry to the commit you just made, using
--amend so the entry can include that commit's own message. For minor and major, it also creates the tag.
- pre-push pushes the release tags listed in
.git/version-bumper.tags.
This means:
- Commits from the terminal also show the dialog in VS Code while VS Code has the repo open.
- With VS Code closed, the hooks do nothing and git works as normal.
- Rebases and cherry-picks don't ask.
- The hooks need
curl. Git for Windows, macOS and most Linux distributions include it.
- Set
VERSION_BUMPER_SKIP=1 to skip the hooks for one command.
Settings
| Setting |
Default |
|
versionBumper.enabled |
true |
Master switch |
versionBumper.installHooks |
ask |
ask / always / never when a repo opens |
versionBumper.askOnCommit |
true |
Show the bump dialog on each commit |
versionBumper.resetBuildOnRelease |
false |
Reset the build number to 0 on minor/major |
versionBumper.versionFile |
"" |
Overrides detection |
versionBumper.changelog.enabled |
true |
|
versionBumper.changelog.file |
CHANGELOG.md |
|
versionBumper.createTag |
true |
Annotated tag per minor/major release |
versionBumper.tagPrefix |
v |
|
Known limitations
git commit --amend asks again.
- If a version file has unstaged edits of yours when you commit, those edits are staged together with the bump.
Development
npm install
npm run compile
node test/smoke.js
To debug, press F5 in VS Code. To build an installable .vsix, run npm run package, then install it with Extensions: Install from VSIX….