It is best to let the build system insert the current version identifier into your distribution archive and / or file name.
First question: how do you get this version identifier. There are three ways:
- By providing the build server the
hg id
command to find out the build error. - Having a
version
file that is populated with the changegroup
hook configured in your Mercurial repository configuration. - Having a
version
file that is populated using the keyword extension. (Not recommended!)
The first approach directly pulls information from Mercurial, which for developers requires virtually no configuration. The disadvantage is that it tightly connects the build system with a specific version control system.
The second approach is independent of the repository system and will remain usable if, for example, you build from the source archive or if you want to manually specify the version label. The disadvantage is that it requires you to set the hook, however, since prefabricated machines are usually specially configured central servers, this should not be a big problem.
I mentioned the third approach in order to be complete, but I think I universally agree that you really want to avoid this mechanism.
Most likely, it is best to go for a hybrid approach 1 and 2, which will first try to approach 2 and go down to approach 1 when you can find the version
file. To better support hg archive
source export, you can also check the .hg_archival.txt
file.
Second question: what value do you use for the build number:
- Version identifier (from
hg id -i
). - Local version number (from
hg id -n
). - Identifier using
latesttag
and latesttagdistance
, see Martins answer.
The advantage of the first is that it is quite simple and uniquely identifies the exact version that is built. This is not very clear to humans, although relative age cannot be obtained from a hash.
The second has an incremental number, however this number only refers to the build machine repository, so you must give developers the ability to loop this number to get the change set hash identifier, or it will be useless.
The third approach, which I personally particularly like, provides temporary information using a tag and distance very convenient for human perception, and additionally indicates the node identifier for an accurate revision. This is quite a long time.