-
-
Save MSch/989548 to your computer and use it in GitHub Desktop.
Xcode Auto-Versioning: Updates your Info.plist's CFBundleVersion with the current git tag and/or sha.
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
# Xcode Auto-Versioning | |
# | |
# Updates your Info.plist's CFBundleVersion with the current git tag and/or sha. | |
# | |
# based on https://github.com/elliottcable/xcode-git-versioner | |
# | |
# Usage: | |
# 1. Right-click the target you want to add the versioning phase to (usually the target that builds your app) | |
# 2. Select: Add -> New Build Phase -> New Run Script Build Phase | |
# 3. Specify /usr/bin/env ruby as the shell for the script | |
# 4. Paste the script body into the Script text area | |
# 5. Ensure that the build phase is at the end of the target's list of build phases | |
plist_path = File.join(ENV['BUILT_PRODUCTS_DIR'], ENV['INFOPLIST_PATH']) | |
raise "Info.plist missing, or path error" unless File.file?(plist_path) | |
# get our version info from git | |
git = `which git`.chomp | |
tag, age, sha = `#{git} describe --tags --always --long`.chomp.match(/(?:(.*)-(\d+)-)?([0-9a-g]+)/i)[1..3] | |
branch = `#{git} name-rev HEAD --name-only --always`.chomp | |
# "v1.0", "v1.0.20" | |
version = tag ? (age.to_i.zero? ? "#{tag}" : "#{tag}.#{age}") | |
version += " (on #{branch})" if branch and branch != 'master' | |
# do the insert the version into the plist and write it out | |
plist = File.read(plist_path) | |
plist.sub!(/(<key>CFBundleVersion<\/key>.*?<string>).*?<\/string>/m, "\\1#{version}</string>") | |
File.open(plist_path, 'w') {|f| f.write(plist)} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi I tried the script but gives error on build: Build/Revision.rb:22: syntax error, unexpected tIDENTIFIER, expecting ':'
version += " (on #{branch})" if bran...
^~~~~~~
Command PhaseScriptExecution failed with a nonzero exit code