Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build numbers: major.minor.revision

How would you write a build.xml file, using neither custom code nor external dependencies (such as a shell script), that:

  • Generates a build number of the form major.minor.revision (e.g., 01.02.34).
  • Auto-increments the revision on each compile of the source code.
  • Auto-increments the minor version on each execution of a dist(ribution) task.

Additionally:

  • Provides an option to increment the major number.
  • Provides an option to increment the minor number.
  • Whenever the major number is incremented, the minor and revision numbers are set to 0.
  • Whenever the minor number is incremented, the revision number is set to 0.

Bonus:

  • Creates a variable based on the git revision number (like a subversion revision number).

Clarification:

  • Automatic checkout (or commit) is not required.
  • Integration with Subversion is not desired.

Thank you for any examples. Here are some related sites that describe how to perform similar tasks:

  • Create a Build Number with Ant.
  • Using the BuildNumber Ant task.
  • Ant and Build Version Numbers.
like image 947
Dave Jarvis Avatar asked Sep 16 '09 06:09

Dave Jarvis


People also ask

What is Major Minor build revision?

This “MAJOR. minor. revision-build” is the way PKP uses to name a version and is a variant of something called “Semantic versioning”. To make it clear, let's take some real examples and see how they look like: Version tag.

What is major version and minor version?

Reading version numbers For example: 1.2. 3 These numbers have names. The leftmost number (1) is called the major version. The middle number (2) is called the minor version. The rightmost number (3) is called the revision but it may also be referred to as a "point release" or "subminor version".

What do the version numbers mean?

A version number is a unique sequence of numbers which identifies the state of development of computer software.

When should I increase my major version?

There are simple rules that indicate when you must increment each of these versions: MAJOR is incremented when you make breaking API changes. MINOR is incremented when you add new functionality without breaking the existing API or functionality. PATCH is incremented when you make backwards-compatible bug fixes.


2 Answers

The build_info.properties file:

build.major.number=00 build.revision.number=00 build.minor.number=00 

The build.xml file:

<?xml version="1.0" encoding="UTF-8"?> <project name="project" default="current-number">  <property file="build_info.properties"/> <property name="build.number" value="${build.major.number}.${build.minor.number}.${build.revision.number}"/>  <target name="current-number">  <echo>Current build number:${build.number}</echo> </target>  <target name="compile">    <antcall target="revision"></antcall> </target>  <target name="dist">   <antcall target="minor"></antcall> </target>  <target name="revision">     <propertyfile  file="build_info.properties">             <entry key="build.revision.number" type="int" operation="+" value="1" pattern="00"/>     </propertyfile> </target>  <target name="minor">     <propertyfile  file="build_info.properties">             <entry key="build.minor.number" type="int" operation="+" value="1" pattern="00"/>             <entry key="build.revision.number" type="int" value="0" pattern="00"/>     </propertyfile> </target>  <target name="major">     <propertyfile  file="build_info.properties">             <entry key="build.major.number" type="int" operation="+" value="1" pattern="00"/>             <entry key="build.minor.number" type="int" value="0" pattern="00"/>             <entry key="build.revision.number" type="int" value="0" pattern="00"/>     </propertyfile> </target>  <target name="all">     <propertyfile  file="build_info.properties">             <entry key="build.major.number" type="int" operation="+" value="1" pattern="00"/>             <entry key="build.minor.number" type="int" operation="+" value="1" pattern="00"/>             <entry key="build.revision.number" type="int" operation="+" value="1" pattern="00"/>     </propertyfile> </target>  </project> 
like image 88
rodrigoap Avatar answered Sep 23 '22 15:09

rodrigoap


This solution does increment minor or revision number automatically if a compile or a dist target has been selected. The incrementation can be switched off if one of the following properties has been set:

  • -Dno.increment.minor=true
  • -Dno.increment.revision=true

If the property inc.major has been set, then the major number will be incremented and the other both values will be set to zero. The SHA-1 checksum is being calculated by the textual representation of the version file.

By the way: If would have been allowed, you could create your own ant task in java script, which is included in JDK 6.

Now here's the ant file

<?xml version="1.0" encoding="UTF-8"?> <project name="Numbers" default="dist" basedir=".">      <property name="version.file" location="${basedir}/version.properties"/>      <target name="inc.revision.properties" unless="no.increment.revision">         <propertyfile file="${version.file}">             <entry key="minor.number" default="00" operation="=" pattern="00" type="int"/>             <entry key="major.number" default="00" operation="=" pattern="00" type="int"/>             <entry key="build.number" default="00" operation="+" pattern="00" type="int"/>         </propertyfile>     </target>      <target name="inc.minor.properties" unless="no.increment.minor">         <propertyfile file="${version.file}">             <entry key="minor.number" default="00" operation="+" pattern="00" type="int"/>             <entry key="major.number" default="00" operation="=" pattern="00" type="int"/>             <entry key="build.number" value="00" operation="="  type="int"/>         </propertyfile>     </target>      <target name="inc.major" if="inc.major">         <property name="no.increment.minor" value="true" />         <property name="no.increment.revision" value="true" />         <propertyfile file="${version.file}">             <entry key="minor.number" value="00" operation="=" pattern="00" type="int"/>             <entry key="major.number" default="00" operation="+" pattern="00" type="int"/>             <entry key="build.number" value="00" operation="=" pattern="00" type="int"/>         </propertyfile>         <load.version.info/>     </target>      <target name="inc.minor" depends="inc.major,inc.minor.properties">         <property name="no.increment.revision" value="true"/>         <load.version.info/>     </target>      <target name="inc.revision" depends="inc.major,inc.revision.properties">         <load.version.info/>     </target>      <macrodef name="load.version.info">         <sequential>             <property file="${version.file}"/>             <checksum file="${version.file}" property="sha1.number" algorithm="SHA" format="CHECKSUM"/>             <echo>Version: ${major.number}.${minor.number}.${build.number}</echo>             <echo>SHA1: ${sha1.number}</echo>         </sequential>     </macrodef>      <target name="compile" depends="inc.revision" description="Compile Task"/>      <target name="dist" depends="inc.minor, compile" description="Dest Task"/>  </project> 
like image 23
dz. Avatar answered Sep 22 '22 15:09

dz.