Semantic Versioning with Bitrise CI


Leveraging semantic versioning in conjunction with automation tools like Bitrise can significantly enhance project management and deployment processes. Let's explores an automated approach to semantic versioning using a custom bash script and Bitrise workflows, designed to simplify version management.

Semantic Versioning Automation with bump_version.sh

Semantic versioning is a universal system for versioning software, which tracks changes through version numbers in the format of MAJOR.MINOR.PATCH. Each segment serves a specific purpose:

  • MAJOR version when you make incompatible API changes

  • MINOR version when you add functionality in a backward-compatible manner, and

  • PATCH version when you make backward-compatible bug fixes.

To automate the versioning process in line with semantic versioning principles, we introduced a bash script, bump_version.sh. This script automates the increment of version numbers based on the nature of changes committed to the project. Here's how it operates:

  • The script examines the latest commit message in the working branch.

  • If the commit message starts with feat, indicating a new feature, it bumps the MINOR version.

  • If the commit message begins with fix, indicating a bug fix, it bumps the PATCH version.

This automation streamlines the versioning process, ensuring that version numbers are consistently and accurately updated in accordance with the changes made to the project.

Versioning by Bitrise Workflow

Bitrise offers an excellent platform for automating versioning and deployment processes. By setting up a trigger on the develop branch for push events, automation can be further enhanced. Here's a strategy to ensure version numbers are correctly bumped:

  1. Trigger Setup: Configure a trigger for the develop branch to activate on push events.

  2. Merge Strategy: Use either Squash or Fast-forward merge strategies when merging feature branches into the develop branch.

  3. Commit Naming: Ensure the last commit message starts with feat or fix to trigger the appropriate version bump.

This setup guarantees that each time a feature branch is merged into the develop branch, the version number is automatically adjusted in line with the changes.

Bitrise Building Workflow

Deploy Workflow

This workflow is triggered only on the develop branch when a new tag is created. It facilitates the deployment process, ensuring that only fully vetted and versioned code is deployed.

Staging Workflow

In addition to being triggered by tag events on the develop branch, the staging workflow also activates for branches prefixed with feature/, bugfix/, and hotfix/. This allows for continuous testing and validation of new features, bug fixes, and hotfixes before they are merged into the develop branch.

Streamlining the Branching Workflow

With this approach, the traditional release/* branch becomes obsolete. All development activities are conducted between the develop branch and feature-specific branches (such as feature/*, bugfix/*, and hotfix/*). Once the development team is satisfied with the changes, they can tag a version. This tagging triggers a build on Bitrise, leading to the creation of a staging or deployment build.