1

We are trying to implement automatic version bumping based on the semver spec... Ideally, we would just merge into master and produce a new version update on the CI.

    --------------development branch----
   /                                    \
--/--base branch------------------------v1.1.0------

We are not there yet, due to some release cycle's constrains, we are using a gitflow approach:

    --------------release branch/v1.1.x----
   /                                    
--/--base branch----v1.2+.x------

every time we cut a release branch, and, let's say, we publish a minor/major update, we have to keep that release open to allow for hot fixes (only patches will eventually go on the current release branch)...

Now, we want to get semver to play well with this flow (which we cannot change at the moment).

how can we make sure that:

  1. once we cut a release then the following commit on the base branch will have at least a minor bump?
  2. how can we bring the hotfixes on the release branch back into master?
Hitmands
  • 13,491
  • 4
  • 34
  • 69

2 Answers2

0

if you use conventional commits, you can setup automated semver version bumping, releases, and release notes generation with semantic-release, (Optional) commitizen, (Optional) commitlint, (Optional) husky

Basically master branch can be your release branch, so any commits that land to master will trigger semantic-release, semantic-release will look at all the commits since the last version and see if they require a release/version bump, if they do it will create the release for you.

See for an explanation on how to set this up https://medium.com/faun/automate-your-releases-versioning-and-release-notes-with-semantic-release-d5575b73d986

Khaled Osman
  • 1,251
  • 12
  • 17
  • we use conventional commits too, the question is not about `how to generate releases or changelogs`, the question is **how to use semver with gitflow?** – Hitmands Sep 04 '19 at 09:36
  • @Hitmands you just ensure that you have one release branch, feature branches get merged in --> You trigger the release and bump the version --> Hotfixes ? --> New patch release. – Khaled Osman Sep 04 '19 at 09:38
0

The best solution I have found is to use a post-commit prompt script via husky. This has a ton of flexibility while reminding your team to keep your versions current.

Below is the script I use.

# .husky/_/post-commit
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

echo "Bump that version!"

exec < /dev/tty

PS3='Please enter your bump choice: '
options=("skip" "patch" "minor" "major")
select opt in "${options[@]}"
do
    case $opt in
        "skip")
            break
            ;;
        "patch")
            break
            ;;
        "minor")
            break
            ;;
        "major")
            break
            ;;
        *) echo "invalid option $REPLY";;
    esac
done

if [[ "$opt" == "skip" ]];
then
    echo "✓ Skipping..."
else
    echo " ✓ Bumping version by $opt"
    yarn standard-version -r $opt
    git push --no-verify --follow-tags origin main
fi
Carter
  • 1,184
  • 11
  • 5