ThoughtWorks
  • 联系我们
  • Español
  • Português
  • Deutsch
  • English
概况
  • 工匠精神和科技思维

    采用现代的软件开发方法,更快地交付价值

    智能驱动的决策机制

    利用数据资产解锁新价值来源

  • 低摩擦的运营模式

    提升组织的变革响应力

    企业级平台战略

    创建与经营战略发展同步的灵活的技术平台

  • 客户洞察和数字化产品能力

    快速设计、交付及演进优质产品和卓越体验

    合作伙伴

    利用我们可靠的合作商网络来扩大我们为客户提供的成果

概况
  • 汽车企业
  • 清洁技术,能源与公用事业
  • 金融和保险企业
  • 医疗企业
  • 媒体和出版业
  • 非盈利性组织
  • 公共服务机构
  • 零售业和电商
  • 旅游业和运输业
概况

特色

  • 技术

    深入探索企业技术与卓越工程管理

  • 商业

    及时了解数字领导者的最新业务和行业见解

  • 文化

    分享职业发展心得,以及我们对社会公正和包容性的见解

数字出版物和工具

  • 技术雷达

    对前沿技术提供意见和指引

  • 视野

    服务数字读者的出版物

  • 数字化流畅度模型

    可以将应对不确定性所需的数字能力进行优先级划分的模型

  • 解码器

    业务主管的A-Z技术指南

所有洞见

  • 文章

    助力商业的专业洞见

  • 博客

    ThoughtWorks 全球员工的洞见及观点

  • 书籍

    浏览更多我们的书籍

  • 播客

    分析商业和技术最新趋势的精彩对话

概况
  • 申请流程

    面试准备

  • 毕业生和变换职业者

    正确开启技术生涯

  • 搜索工作

    在您所在的区域寻找正在招聘的岗位

  • 保持联系

    订阅我们的月度新闻简报

概况
  • 会议与活动
  • 多元与包容
  • 新闻
  • 开源
  • 领导层
  • 社会影响力
  • Español
  • Português
  • Deutsch
  • English
ThoughtWorks菜单
  • 关闭   ✕
  • 产品及服务
  • 合作伙伴
  • 洞见
  • 加入我们
  • 关于我们
  • 联系我们
  • 返回
  • 关闭   ✕
  • 概况
  • 工匠精神和科技思维

    采用现代的软件开发方法,更快地交付价值

  • 客户洞察和数字化产品能力

    快速设计、交付及演进优质产品和卓越体验

  • 低摩擦的运营模式

    提升组织的变革响应力

  • 智能驱动的决策机制

    利用数据资产解锁新价值来源

  • 合作伙伴

    利用我们可靠的合作商网络来扩大我们为客户提供的成果

  • 企业级平台战略

    创建与经营战略发展同步的灵活的技术平台

  • 返回
  • 关闭   ✕
  • 概况
  • 汽车企业
  • 清洁技术,能源与公用事业
  • 金融和保险企业
  • 医疗企业
  • 媒体和出版业
  • 非盈利性组织
  • 公共服务机构
  • 零售业和电商
  • 旅游业和运输业
  • 返回
  • 关闭   ✕
  • 概况
  • 特色

  • 技术

    深入探索企业技术与卓越工程管理

  • 商业

    及时了解数字领导者的最新业务和行业见解

  • 文化

    分享职业发展心得,以及我们对社会公正和包容性的见解

  • 数字出版物和工具

  • 技术雷达

    对前沿技术提供意见和指引

  • 视野

    服务数字读者的出版物

  • 数字化流畅度模型

    可以将应对不确定性所需的数字能力进行优先级划分的模型

  • 解码器

    业务主管的A-Z技术指南

  • 所有洞见

  • 文章

    助力商业的专业洞见

  • 博客

    ThoughtWorks 全球员工的洞见及观点

  • 书籍

    浏览更多我们的书籍

  • 播客

    分析商业和技术最新趋势的精彩对话

  • 返回
  • 关闭   ✕
  • 概况
  • 申请流程

    面试准备

  • 毕业生和变换职业者

    正确开启技术生涯

  • 搜索工作

    在您所在的区域寻找正在招聘的岗位

  • 保持联系

    订阅我们的月度新闻简报

  • 返回
  • 关闭   ✕
  • 概况
  • 会议与活动
  • 多元与包容
  • 新闻
  • 开源
  • 领导层
  • 社会影响力
博客
选择主题
查看所有话题关闭
技术 
敏捷项目管理 云 持续交付 数据科学与工程 捍卫网络自由 演进式架构 体验设计 物联网 语言、工具与框架 遗留资产现代化 Machine Learning & Artificial Intelligence 微服务 平台 安全 软件测试 技术策略 
商业 
金融服务 全球医疗 创新 零售行业 转型 
招聘 
职业心得 多元与融合 社会改变 
博客

话题

选择主题
  • 技术
    技术
  • 技术 概观
  • 敏捷项目管理
  • 云
  • 持续交付
  • 数据科学与工程
  • 捍卫网络自由
  • 演进式架构
  • 体验设计
  • 物联网
  • 语言、工具与框架
  • 遗留资产现代化
  • Machine Learning & Artificial Intelligence
  • 微服务
  • 平台
  • 安全
  • 软件测试
  • 技术策略
  • 商业
    商业
  • 商业 概观
  • 金融服务
  • 全球医疗
  • 创新
  • 零售行业
  • 转型
  • 招聘
    招聘
  • 招聘 概观
  • 职业心得
  • 多元与融合
  • 社会改变
持续交付技术

Automating semantic versioning model in mobile releases

Guilherme Cherubini Guilherme Cherubini
Vanessa Medeiros Vanessa Medeiros

Published: Feb 4, 2020

Mobile applications have become increasingly important in business, transforming both the business and software development practices. 

In this new dynamic and agile reality it’s vital that development teams obtain constant customer feedback so that they can operate effectively. The practice of continuous delivery can help because software releases are made frequently and with minor changes — this helps derisk deployment. With this approach, the software is tested constantly and issues can be detected and fixed quickly.

One example of this type of automation was in a critical project that we worked on for a client. It was a mobile framework that was used by a large application to allow the end user to make in-app purchases. That had a very fragile architecture, with no defined code standards, with non-effective unit tests (since they do not guarantee the main business logic of the application) and without any automated processes.

In this post we will demonstrate how we automated the distribution process using semantic versioning (SemVer) model. The initiative bought the team more time to invest in other improvements actions, such as: architecture evolution, bug fixes and unit testing.

Starting out with SemVer

The SemVer specification is a versioning model for software development projects, authored by Tom Preston, co-founder of GitHub. Using its set of rules makes it possible to distribute a project code in different stages and the relevant dev teams can choose the version that best suits them (this is what most of the libraries and frameworks do). Breaking changes, bug fixes or new features can be easily identified just by looking at the increased version number.

"Under this scheme, version numbers and the way they change convey meaning about the underlying code and what has been modified from one version to the next." 

In order to standardize the customer project infrastructure, we chose the GitLab CI system as a continuous integration and delivery platform, because it made it possible to automate the application distribution to  framework consumers, also known as: developers.

The GitLab CI pipeline was configured to have four stages: build, lint, test and release. Once the first three stages are successfully executed, the fourth stage, 'release', is made available to be launched. The following image displays the project pipeline screen:

Figure 1: Part of the GitLab CI interface, displaying the pipeline and the release jobs that can be executed manually

In a perfect world, we would have only one job that would receive the release type as a parameter that we’d like to perform. Unfortunately, the GitLab CI tool doesn’t allow parameters to be passed when executing a specific job. That said, at the time of writing, there’s an open ticket to add this feature at some point. 

For this reason we had to configure three different types of jobs (a flow of tasks to be executed), one for each type of distribution. Following the specification of SemVer: 

releaseAndBumpMajor: increments the 'major' value of the version (x.0.0) and reset the 'minor' and 'patch';
releaseAndBumpMinor: increments the 'minor' value of the version (5.x.0) and clears the 'patch';
releaseAndBumpPatch: increments the version 's patch value (5.0.x);

In order to define the three distribution jobs through GitLab CI, it was needed to configure the ".gitlab-ci.yml" file, which is responsible for defining the pipeline settings.
 
releaseAndBumpPatch:
 when: manual
 stage: release
 script:
   - fastlane release semverBumpType:patch
 only:
   - master
 
releaseAndBumpMinor:
 when: manual
 stage: release
 script:
   - fastlane release semverBumpType:minor
 only:
   - master
eleaseAndBumpMajor:
 when: manual
 stage: release
 script:
   - fastlane release semverBumpType:major only:
   - master
 
The 'when: manual' configuration allows us to launch the job with just one click through the GitLab CI interface (image 01). The 'only: master' setting defines that the job will be available when a commit is coming from the master branch, and the 'script: fastlane release ...' setting is responsible for incrementing and distributing the new version to the consumers.

We chose to use Fastlane in our project to make test automation and deploy easier. It also has an action called increment_version_number, which can pass the key 'bump_type' with the values of 'major', 'minor' or 'patch'. This action is already based on the SemVer model and makes it very simple to increment the version of your project. But, it’s also possible to use any other type of technique or even write a custom script that does this same type of work.

The Fastlane versioning action is only available for the iOS platform. However, this operation can be implemented with a shell script or even a Gradle task for Android applications. As you can see in the Gradle script below:
 
import java.util.regex.Pattern

task bumpSemver << {
  if (type != "major" && type != "minor" && type != "patch") {
    println "SemVer type param should be passed. (major, minor or patch)"
    return
  }

  def propsFile = file("sdk/build.gradle")
  def propsText = propsFile.getText()
  def patternVersionNumber = Pattern.compile(versionPropertyKey + "(\\s?)=(\\s?)\"(\\d+)\\.(\\d+)\\.(\\d+)\"")
  def matcherVersionNumber = patternVersionNumber.matcher(propsText)
  matcherVersionNumber.find()

  def major = Integer.parseInt(matcherVersionNumber.group(3))
  def minor = Integer.parseInt(matcherVersionNumber.group(4))
  def patch = Integer.parseInt(matcherVersionNumber.group(5))

  println "VERSION=" + major + "." + minor + "." + patch

  switch (type) {
    case "major":
      major++
      minor = 0
      patch = 0
      break
    case "minor":
      minor++
      patch = 0
      break
    case "patch":
      patch++
      break
    default:
      println "SemVer type should be passed: major, minor or patch"
      break
  }

  propsText = matcherVersionNumber.replaceAll(versionPropertyKey + " = \"" + major + "." + minor + "." + patch + "\"")
  propsFile.write(propsText)

  println "BUMPED VERSION=" + major + "." + minor + "." + patch
}

You must also change the build settings file by adding the current APP_VERSION extra property of the application:
 
  APP_VERSION = "1.0.1"
}

android {
  buildToolsVersion APP_VERSION

  defaultConfig {
    versionName APP_VERSION
  }
}

When executed the script gets the current version of the project through the APP_VERSION property and increment it according to the selected SemVer specification.

Part of the Fastfile file is presented below where the release lane (distribution action) is defined, which is executed by the previous defined jobs in the file ".gitlab-ci.yml" (Image 01). It receives the type of version (major / minor / patch) that we want to increment and distribute.
 
lane :release do |options|
   
# Increments the version according the passed type (major, minor or patch)

# iOS release
increment_version_number(bump_type: options[:semverBumpType])

# Android release
sh "../gradlew bumpSemver -Ptype=#{options[:senverBumpType]} -PversionPropertyKey=APP_VERSION"

# Gets the version number for possible automations
version = get_version_number(xcodeproj: "SDK.xcodeproj")

# Other automated operations

end

Also, you can align with your team other actions that need to be automated in your release process and add them to the location pointed out by the comment: "Other automated operations." Some interesting examples are: updating the changelog file, creating a Git tag for the commit, updating the project .podspec file, updating the remote repository with these new changes, etc. 

But don't forget to automate the most important operation, that’s the one responsible for distributing your software to Google Play or App Store.

Through this article, we have shown how it is possible to generate three different types of automated and versioned distributions. We hope this tip may have been useful for you and would allow for a more frequent distribution of software, with the benefits of versioning the SemVer model covers.

Technology Radar

Don't miss our opinionated guide to technology frontiers.

Subscribe
相关博客
语言、工具与框架

Write quality mobile apps in any architecture

Leandro Alonso
了解更多
Pune

Building Better Behavior Tests for Mobile Apps

Priyank Gupta
了解更多
体验设计

Designing for Mobile

Jonny Schneider
了解更多
  • 产品及服务
  • 合作伙伴
  • 洞见
  • 加入我们
  • 关于我们
  • 联系我们

WeChat

×
QR code to ThoughtWorks China WeChat subscription account

媒体与第三方机构垂询 | 政策声明 | Modern Slavery statement ThoughtWorks| 辅助功能 | © 2021 ThoughtWorks, Inc.