setver: Package (semver) version management for bash/PHP/Node31 Jul 2020
When you’re creating software packages that will be used by other people, you need to get your versioning in order. For PHP libraries, this means: both the version number in
composer.json as well as the
git tag for Github/Bitbucket. For node.js projects, the version is kept by npm in
package.json. It was always too easy to make small mistakes. So I decided to make a bash script
<strong>semver.sh</strong> to manage it for me.
This works for PHP/Composer projects, Node/NPM projects and Bash projects. At the least it will get/set your git tags (and push them to Github/Bitbucket), but if present, it will also first set versions on
package.json . There’s also the option to use a
VERSION.md file, that will always contain the version number.
For PHP packages: creating and pushing the
git tag will also trigger Packagist (the PHP package manager repository) to update the package version. It’s also important that the composer.json version and the git tag version are always the same.
Semver.sh allows you to do:
setver.sh new major: derive new major version and set it everywhere
setver.sh new minor: derive new minor version and set it everywhere
setver.sh new patch: derive new patch version and set it everywhere
setver.sh set 2.0.0: set new version number
The semver.sh then executes:
➜ setver.sh new minor
> version 1.0.3 -> 1.1.0
> set version in composer.json
> commit and push changed files
[master 1261456] semver.sh: set version to 1.1.0
> set git version tag
> push tags to firstname.lastname@example.org:<username/package>.git
* [new tag] v1.1.0 -> v1.1.0
Next to that, semver.sh also allows to
setver.sh check: show the version numbers used in all possible places (and detect e.g. that your
composer.jsonversion are no longer in sync),
setver.sh get: get the current version of your package, and
setver.sh push: an easy way to push your latest changes to Github/Bitbucket (a shortcut for
git commit -a && git push).
What is Semver?
Semver -or Sematic Versioning- is a version labeling convention that requires software to have a version number of the type
<major>.<minor>.<patch> (e.g. 1.4.15). This is how you increment versions in semver:
- if you just fixed a problem/bug:
- If you added new functionality:
- If you made big breaking changes (so that the component might not be backwards compatible):
There are the option in semver to use alpha/beta/pre-release versions, but I’m not using that for now.
In order to keep the script small, I just used a subset of library functions from bashew.