Last active
September 18, 2015 01:45
-
-
Save lemonkey/e841572deb2526ae4750 to your computer and use it in GitHub Desktop.
Increment BUILD_VERSION property in an xcconfig file (useful when you have multiple targets that all need to have the same build version, such as with a watchOS 2 app and your continuous deployment system needs to increment the build version)
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
# Assumes build version in xcconfig is defined as the following, where no spaces, spaces and/or tabs are allowed: | |
# BUILD_VERSION = 1.2.3.4 | |
filename = "sample.xcconfig" | |
build_version_property = "BUILD_VERSION" | |
new_version_string = "" | |
lines = IO.readlines(filename) | |
for line in lines | |
arr = line.gsub(/\s+/m, '').strip.split("=") | |
if arr.count == 2 && arr[0] == build_version_property | |
# Extract the build number from this string, increment its last value, and then rewrite line | |
# Remove all whitespace from current line and split on '=' | |
version_string = arr[1] | |
version_arr = version_string.split(".") | |
if version_arr.count == 4 | |
# Get build number string, increment build number and recompose overall build version string | |
build_version = version_arr[3] | |
numeric_build_version = build_version.to_i | |
numeric_build_version += 1 | |
new_version_string = "#{version_arr[0]}.#{version_arr[1]}.#{version_arr[2]}.#{numeric_build_version}" | |
else | |
#put "Error: BUILD_VERSION must contain 4 values: major.minor.patch.build!" | |
end | |
break | |
end | |
end | |
# Output the new version string to be used in the archive filename, etc. | |
if new_version_string == "" | |
puts "" | |
else | |
puts "#{new_version_string}" | |
# Update xcconfig file | |
f = File.open(filename, "w") | |
for line in lines | |
arr = line.gsub(/\s+/m, '').strip.split("=") | |
if arr.count == 2 && arr[0] == build_version_property | |
# Note that when we update this line in the xcconfig, it will lose any additional white spacing it might have had. | |
f.puts("#{build_version_property} = #{new_version_string}") | |
else | |
f.puts(line) | |
end | |
end | |
f.close | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment