Created
August 2, 2013 12:27
-
-
Save hfossli/6139513 to your computer and use it in GitHub Desktop.
Run script for Xcode to run after build / archive - updates CFBundleVersion in Info.plist file with short git commit hash
This file contains 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 | |
# xcode-git-commit-hash-cfbundleversion.rb | |
# Run script for Xcode to run after build / archive | |
# Updates CFBundleVersion in Info.plist file with short git commit hash | |
# | |
# This is based on | |
# http://github.com/guicocoa/xcode-git-cfbundleversion/ | |
# http://github.com/digdog/xcode-git-cfbundleversion/ | |
# http://github.com/jsallis/xcode-git-versioner | |
# http://github.com/juretta/iphone-project-tools/tree/v1.0.3 | |
require 'rubygems' | |
begin | |
require 'Plist' | |
rescue LoadError => e | |
puts "You need to install the 'Plist' gem: [sudo] gem install plist" | |
exit 1 | |
end | |
raise "Must be run from Xcode" unless ENV['XCODE_VERSION_ACTUAL'] | |
GIT = "/usr/bin/env git" | |
PRODUCT_PLIST = File.join(ENV['BUILT_PRODUCTS_DIR'], ENV['INFOPLIST_PATH']) | |
HASH = `#{GIT} log -1 --pretty=format:%h` | |
BUNDLE_VERSION = "CFBundleVersion" | |
if File.file?(PRODUCT_PLIST) and HASH | |
# update product plist | |
`/usr/bin/plutil -convert xml1 \"#{PRODUCT_PLIST}\"` | |
info = Plist::parse_xml(PRODUCT_PLIST) | |
if info | |
info[BUNDLE_VERSION] = HASH | |
info["GCGitCommitHash"] = HASH | |
info.save_plist(PRODUCT_PLIST) | |
end | |
`/usr/bin/plutil -convert binary1 \"#{PRODUCT_PLIST}\"` | |
# log | |
puts "updated #{BUNDLE_VERSION} to #{HASH}" | |
puts "HEAD: #{HASH}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment