Tigraine
Daniel Hoelbling talks about .NET

Simplifying releases through git

October 27th, 2009 . by Daniel Hölbling

I confess: I love writing build scripts. They are usually insanely easy to write, and provide you with a disproportional amount of value over time that it’s almost tragic not to have them. And, I love git.
So, what’s better than to see git simplifying my buildfiles :) .

Imagine the usual: Your assembly version is encoded in your buildfile, so whenever you want to release you do the following:

  1. Increment version number in buildfile
  2. Run buildfile
  3. Create a tag in your SCM for the released version

Now, thanks to the smart people at the castle mailing list I found out about the git describe command. By using git-describe you can simplify the above to just:

    1. Create a tag in your SCM
    2. Run buildfile

The function for that is quite simple:

function Get-Git-Commit
{
    return git describe
}

function Get-Git-Version
{
    $v = git describe --abbrev=0
    return $v -replace "v", ""
}

Get-Git-Commit is returning the full name of the build, giving me a string like: v0.1.0.2-2-gd19ce0f.

And Get-Git-Version will output the tag-name without the leading v so it can be used as the product version inside the assembly info.

My buildscript then uses this version information from git to write my AssemblyInfo.cs files and build numbers have started to magically change!

This technique helps me to avoid all the hassle of incrementing build numbers, but instead allows me to focus on my work more. Once I feel the release is done, I simply hit:

git tag –a v1.0.0.1

(don’t forget to use git push –tags to get them to your server)

Hey, that’s awesome! There has to be a catch right? Indeed, there is:

If git is not installed, you can’t compile. Bummer I know, especially since the unwashed masses are in the process of slowly grasping the concept of SVN, who would want to throw a DVCS like git at them?

This is why all of my build script have a step called release that packs everything together in one nice zip file and I can then upload it to some server. In case someone has no git, he’s stuck with my binary files.

You can see this in action by looking at these open-source buildfiles I wrote lately: dotless, elms-connector.


  • ChrisJOwen
    Ahhh, I understand what you were banging on about now. Skype chat isn't the best way of explaining a coding solution (either that or I wasn't paying attention). Great work on the build script anyway.
  • How are you handling the commit hash? The CLR only admits 16-bit numbers for each version component...
  • We don't use the hash in the version attribute but only in title and description.
    The version is just straight from the git tag (like v1.1.0)

    But Ayende adds the hash to the version number in Rhino-Mocks. But he has to disable some compiler warning for that.
blog comments powered by Disqus