Auto Increment Version Number?

916 views
Skip to first unread message

Ketan Anjaria

unread,
May 9, 2013, 9:26:01 AM5/9/13
to rubym...@googlegroups.com
Is there a way to get my app version number to autoincrement based on git commits?
Something is simple as a count so I can display it in the UI for testing.


Colin T.A. Gray

unread,
May 9, 2013, 9:37:30 AM5/9/13
to rubym...@googlegroups.com
You could script this in your Rakefile, i think it would look something like this:

the most recent git commit: `git log -n 1 --pretty=format:'%h'`
the last recorded git commit: File.read('version-git.txt') rescue ''
the current patch: File.read('version-patch.txt').to_i rescue 0

if the current git commit and last recorded commit don't match, bump the version-patch number.  Then add this to your version (app.version = "X.Y.#{patch}").

or, a simpler way to do this, just tack the git commit hash onto the version number:

app.version = "1.2.3-#{`git log -n 1 --pretty=format:'%h'`}"



On May 9, 2013, at 7:26 AM, Ketan Anjaria wrote:

Is there a way to get my app version number to autoincrement based on git commits?
Something is simple as a count so I can display it in the UI for testing.



--
 
---
You received this message because you are subscribed to the Google Groups "RubyMotion - Ruby for iOS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubymotion+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Websembly

unread,
May 9, 2013, 11:20:49 AM5/9/13
to rubym...@googlegroups.com
Really clever approach!!!

I posted it in the Wiki for others.

Thom

Ketan Anjaria

unread,
May 10, 2013, 11:54:28 AM5/10/13
to rubym...@googlegroups.com
Thanks Colin,
So I have to manually create the version-git.txt and version-patch files?
I tried the simpler approach in my Rakefile but didn't see the version increment.
app.version = app.info_plist['CFBundleShortVersionString'] = "1.0.0-#{`git log -n 1 --pretty=format:'%h'`}"

Thomas Kadauke

unread,
May 10, 2013, 12:33:07 PM5/10/13
to rubym...@googlegroups.com
Ketan,

Internally, git doesn't use version numbers of the form X.Y.Z. This is why what you want can never be fully automated if you want guaranteed good results.

Here's what you can do so you only have do change the version in one place. Get into the habit of tagging every release with the version schema X.Y.Z and then find the current git tag in your Rakefile. You can even create a rake task or a similar script to make the tagging easier.

Alternatively, create a file version.rb which defines a version constant. Require this file from your Rakefile and use the constant for configuration. This is how most ruby gems do it. It has the additional advantage that the file can be part of the app so the version number is accessible from the code.

Also, I suggest you take a look at http://semver.org. It features a very interesting discussion about version numbers.

--Thomas

Von meinem iPhone gesendet

Michael nietzold

unread,
May 10, 2013, 6:59:45 PM5/10/13
to rubym...@googlegroups.com
Instead of hash you can add the count of commits:


Von meinem iDingens gesendet...
Reply all
Reply to author
Forward
0 new messages