Given: Bitbucket repo, and 2 developers, Steve and Bob who are working on 2 branches, feature/alpha & feature/beta. On master branch and feature branches we have a properties file with version - let say 8.3.0.
How to... ensure that after Bob or Steve merges their pull request to the master the patch version on the master is incremented? I.e.:
Looking for the less painful solution. Thx in advance!
UPDATE 2020-12-07:
mnestorov's answer with some modifications led to the desired result. The difference was that I had no rights to add pre-merge hooks on the server. In case someone is strugling with the same issue - here is a hackish recepie:
In this way you will ensure your incrementation script will run any time your teammates push without begging devops for help :)
One way is to create a pre-merge-commit hook and place it on your bitbucket server.
The hook can test a bunch of things, like check into what branch you are merging in, but it can also create or append files that specify the version. Basically, it can be as simple as:
Let's say that your version.txt looks like this:
version = 8.3.0
Then you can have something like:
#!/bin/sh
#
# An example hook script to verify what is about to be committed.
# Called by "git merge" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message to
# stderr if it wants to stop the merge commit.
#
# To enable this hook, rename this file to "pre-merge-commit".
echo "Bumping Service version"
OLD_VERSION=$(cat version.txt | grep -o "=.*" | tr -d '= ')
NEW_NUM=$(( $(echo $OLD_VERSION | grep -o "\.[0-9]*$" | tr -d ".") + 1 ))
LAST_NUM=$(echo $OLD_VERSION | grep -o "\.[0-9]*$" | tr -d ".")
NEW_VERSION=$(echo $OLD_VERSION | tr $LAST_NUM $NEW_NUM)
# More conversions to bump the version if needed
# more code code code
# ...
sed -i 's/\(^version = \).*/\1'"$NEW_VERSION"'/' ~/service/version/file/txt
Of course, I'm just guessing what it might be and how it can possible be automated to bump the sub-sub version that you have. But it can definitely be automated and calculated how to bump a number up, whatever it is.
Note: that this hook does not take in any arguments, so you can't pass a version number to it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With