Skip to content

Instantly share code, notes, and snippets.

@enriquez
Created June 16, 2015 00:11
Show Gist options
  • Save enriquez/c4ce2004e9212c576627 to your computer and use it in GitHub Desktop.
Save enriquez/c4ce2004e9212c576627 to your computer and use it in GitHub Desktop.
Script for automatically versioning builds. Run this in a build phase.
#!/usr/bin/env ruby
built_products_dir = ENV['BUILT_PRODUCTS_DIR']
infoplist_path = ENV['INFOPLIST_PATH']
dsym_dir = ENV['DWARF_DSYM_FOLDER_PATH']
dsym_path = ENV['DWARF_DSYM_FILE_NAME']
info_plist = File.join(built_products_dir, infoplist_path)
dsym_info_plist = File.join(dsym_dir, dsym_path, "Contents", "Info.plist")
git_sha = `git rev-parse --short HEAD`.strip
commit_count = `git rev-list HEAD --count`.strip
update_git_version_command = "/usr/libexec/PlistBuddy -c \"Set :GITVersion #{git_sha}\" \"#{info_plist}\""
update_bundle_version_command = "/usr/libexec/PlistBuddy -c \"Set :CFBundleVersion #{commit_count}\" \"#{info_plist}\""
update_dsym_git_command = "/usr/libexec/PlistBuddy -c \"Add :GITVersion string #{git_sha}\" \"#{dsym_info_plist}\""
update_dsym_version_command = "/usr/libexec/PlistBuddy -c \"Set :CFBundleVersion #{commit_count}\" \"#{dsym_info_plist}\""
puts update_git_version_command
system(update_git_version_command)
puts update_bundle_version_command
system(update_bundle_version_command)
puts update_dsym_git_command
system(update_dsym_git_command)
puts update_dsym_version_command
system(update_dsym_version_command)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment