commit-and-tag-version is a utility for incrementing (or "bumping") the semantic version number of your software. When run, it looks at your git history and decides whether the next version should be a major, minor or patch increment (or you can override this manually). By default, it is able to modify package.json (for JS/npm modules) and several other common file formats to contain the updated version number, rather than having to do it manually.
But if your version number is stored in files that commit-and-tag version doesn't support, you may need a script like this. In my case, I had some source code which printed out the version number within the program, for example:
$VERSION = "1.2.3-beta"
commit-and-tag-version doesn't come with a search-and-replace module for situations like this, but the following short script adds that ability.
-
Make sure you've installed commit-and-tag-version
-
Download the JS file below to your project. Tweak the search string to match the format that you need.
-
Update your commit-and-tag version configuration to point to the JS script, and specify which files you want updated.
In my case, I'm using
package.jsonto configure commit-and-tag version (but there are other methods too), and I'd also like to keep the default behaviour of bumping the version number insidepackage.jsonandpackage-lock.jsonso I've ensured those are specified, too:{ ... "commit-and-tag-version": { "bumpFiles": [ {"filename": "package.json", "type": "json"}, {"filename": "package-lock.json", "type": "json"}, {"filename": "file-to-update.txt", "updater": "search-replace-version.js"} ] } }
-
Commit any outstanding changes to git before running the following tests, so that you can easily backtrack if something goes wrong.
-
Run
commit-and-tag-version --skip.commit --skip.tag. This will "bump" (increment) the version number in your given files, but not perform agit commitorgit tag-- useful while testing. You should see a line like this in the console, which indicates that your file was updated:√ bumping version in path/to/file-to-update.txt from 1.0.0 to 1.0.1 -
Check that the file was updated correctly.
If not, undo the changes, tweak the search string or
bumpFilessetting, then repeat step 2. -
Commit
search-replace-version.jsto your repo so that other users can use it to bump the version number -
Run the full
commit-and-tag-versioncommand next time you're ready to release a new version