Created
August 10, 2010 09:18
-
-
Save pjaspers/516970 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# update_version.rb | |
# | |
# Created by Piet Jaspers on 23/07/10. | |
# Copyright 2010 10to1. All rights reserved. | |
require "rubygems" | |
require "Plist" | |
# Change this to your git path | |
GIT_PATH = '/usr/local/bin/git' | |
plist_filename = "#{ENV['PROJECT_DIR']}/#{ENV['INFOPLIST_FILE']}" | |
pl = Plist::parse_xml(plist_filename) | |
def check_if_git_installed | |
File.exists?(GIT_PATH) | |
end | |
if check_if_git_installed | |
old_hash = pl["CFBundleVersion"].strip() | |
git_hash = `#{GIT_PATH} rev-parse HEAD`.to_s[0..7].strip() | |
if git_hash && git_hash != old_hash | |
# Updating the long version number | |
pl["CFBundleVersion"] = git_hash | |
# If git-describe is available, use it to fill in the short | |
# version number | |
git_described_version = `#{GIT_PATH} describe`.gsub(/\n/,"") | |
pl["CFBundleShortVersionString"] = git_described_version unless git_described_version.empty? | |
# Some info for the Build Results window | |
if git_described_version.empty? | |
puts "Updating version: (long) #{pl["CFBundleVersion"]}" | |
else | |
puts "Updating version: (short) #{pl["CFBundleShortVersionString"]} (long) #{pl["CFBundleVersion"]}" | |
end | |
pl.save_plist(plist_filename) | |
end | |
else | |
puts "Git not found, skipping versioning." | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment