module RubyBuildIos
ruby-build-ios.rb
Constants
- PROJECT_BUILD_NUMBER
Public Class Methods
build_project(project, scheme, configuration, build_number, archive_path)
click to toggle source
TODO allow flexibility in USER DEFINED build variables
# File lib/ruby_build_ios.rb, line 156 def self.build_project(project, scheme, configuration, build_number, archive_path) command = "xcodebuild -project #{project} -scheme #{scheme} -configuration #{configuration} -destination 'generic/platform=iOS' PROJECT_BUILD_NUMBER=#{build_number} -archivePath #{archive_path} archive" print "#{command}\n" # status is a Process::Status result = 'OK' status = nil stderr_str = '' Open3.popen3(command) do |stdin, stdout, stderr, wait| t1 = Thread.new do while line = stdout.gets puts line end end t2 = Thread.new do while line = stderr.gets stderr_str << line end end status = wait.value t2.value t1.value end if status.success? print "#{result}\n" else raise stderr_str; end result end
build_workspace(workspace, scheme, configuration, build_number, archive_path)
click to toggle source
TODO allow flexibility in USER DEFINED build variables
# File lib/ruby_build_ios.rb, line 191 def self.build_workspace(workspace, scheme, configuration, build_number, archive_path) command = "xcodebuild -workspace #{workspace} -scheme #{scheme} -configuration #{configuration} -destination 'generic/platform=iOS' PROJECT_BUILD_NUMBER=#{build_number} -archivePath #{archive_path} archive" print "#{command}\n" # status is a Process::Status result = 'OK' status = nil stderr_str = '' Open3.popen3(command) do |stdin, stdout, stderr, wait| t1 = Thread.new do while line = stdout.gets puts line end end t2 = Thread.new do while line = stderr.gets stderr_str << line end end status = wait.value t2.value t1.value end if status.success? print "#{result}\n" else raise stderr_str; end result end
clean(path)
click to toggle source
# File lib/ruby_build_ios.rb, line 139 def self.clean(path) if path.chomp == '/' raise "Are you out of your mind?" end command = "rm -fr #{path}/*" print "#{command}\n" # status is a Process::Status stdout_str, stderr_str, status = Open3.capture3(command) if status.success? print "#{stdout_str}\n" else raise stderr_str; end result = stdout_str end
copy_provision_file(file_name, uuid)
click to toggle source
# File lib/ruby_build_ios.rb, line 100 def self.copy_provision_file(file_name, uuid) command = "cp #{file_name} ~/Library/MobileDevice/Provisioning\\ Profiles/#{uuid}.mobileprovision" print "#{command}\n" # status is a Process::Status stdout_str, stderr_str, status = Open3.capture3(command) if status.success? print "#{stdout_str}\n" else raise stderr_str; end result = stdout_str end
create_export_plist(file_name, key_string_pairs)
click to toggle source
# File lib/ruby_build_ios.rb, line 225 def self.create_export_plist(file_name, key_string_pairs) if !key_string_pairs.is_a? Hash raise "create_export_plist() key_string_pairs must be a Hash\n" end xml_prelude = <<EO1 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>provisioningProfiles</key> <dict> EO1 xml_postlude = <<EO2 </dict> <key>method</key> <string>app-store</string> </dict> </plist> EO2 xml_key_string_pairs = '' key_string_pairs.each_pair do |key, string| xml_key_string_pairs << " <key>#{key}</key>\n" xml_key_string_pairs << " <string>#{string}</string>\n" end print "Writing into #{file_name}\n" file = File.open(file_name, 'w+', 0666) file.puts("#{xml_prelude}#{xml_key_string_pairs}#{xml_postlude}") file.close() return true end
export_to_ipa(archive, plist, ipa_path)
click to toggle source
# File lib/ruby_build_ios.rb, line 272 def self.export_to_ipa(archive, plist, ipa_path) command = "xcodebuild -exportArchive -exportOptionsPlist #{plist} -archivePath #{archive} -exportPath #{ipa_path}" print "#{command}\n" # status is a Process::Status stdout_str, stderr_str, status = Open3.capture3(command) if status.success? print "#{stdout_str}\n" else raise stderr_str; end result = stdout_str end
get_uuid_from_file(file_name)
click to toggle source
# File lib/ruby_build_ios.rb, line 86 def self.get_uuid_from_file(file_name) command = "/usr/libexec/PlistBuddy -c \"Print UUID\" /dev/stdin <<< $(security cms -D -i #{file_name} 2> /dev/null)" print "#{command}\n" # status is a Process::Status stdout_str, stderr_str, status = Open3.capture3(command) if status.success? stdout_str = stdout_str.chomp print "#{stdout_str}\n" else raise stderr_str; end result = stdout_str end
install_provision_file(file_name)
click to toggle source
# File lib/ruby_build_ios.rb, line 113 def self.install_provision_file(file_name) uuid = get_uuid_from_file(file_name) copy_provision_file(file_name, uuid) end
install_provision_files(file_names_str)
click to toggle source
# File lib/ruby_build_ios.rb, line 118 def self.install_provision_files(file_names_str) file_names = file_name_str.gsub("\n",'').strip().split(',') file_names.each do |file_name| uuid = get_uuid_from_file(file_name) copy_provision_file(file_name, uuid) end end
latest_git_commit_comment(revision = '--all')
click to toggle source
# File lib/ruby_build_ios.rb, line 26 def self.latest_git_commit_comment(revision = '--all') command = "git log -1 --oneline #{revision}" print "#{command}\n" # status is a Process::Status stdout_str, stderr_str, status = Open3.capture3(command) if status.success? print "#{stdout_str}\n" else raise stderr_str; end result = stdout_str.chomp.chomp end
latest_git_commit_count(revision = '--all')
click to toggle source
ruby-doc.org/stdlib-2.0.0/libdoc/open3/rdoc/Open3.html#method-c-capture3 ruby-doc.org/core-2.2.0/Process/Status.html ruby-doc.org/core-2.0.0/IO.html#method-i-puts
# File lib/ruby_build_ios.rb, line 12 def self.latest_git_commit_count(revision = '--all') command = "git rev-list --count #{revision}" print "#{command}\n" # status is a Process::Status stdout_str, stderr_str, status = Open3.capture3(command) if status.success? print "#{stdout_str}\n" else raise stderr_str; end result = stdout_str.chomp.chomp result.to_i end
project_build_number(file_name = PROJECT_BUILD_NUMBER)
click to toggle source
# File lib/ruby_build_ios.rb, line 66 def self.project_build_number(file_name = PROJECT_BUILD_NUMBER) print "Reading from #{file_name} to get the last project build number\n" file = File.open(file_name, 'r') build_str = file.gets() file.close() build_int = build_str.chomp.to_i build_int += 1 build_str = build_int.to_s print "Writing into #{file_name} to set the next project build number\n" file = File.open(file_name, 'w+', 0666) file.puts(build_str) file.close() build_str end
tag_latest_git_commit(tag, message = 'Sorry, no tag message provided.')
click to toggle source
# File lib/ruby_build_ios.rb, line 39 def self.tag_latest_git_commit(tag, message = 'Sorry, no tag message provided.') command = "git tag -a #{tag} -m \"#{message}\"" print "#{command}\n" # status is a Process::Status # -a is annotate # -m is message # ex: git tag -a v1.4 -m "my version 1.4" stdout_str, stderr_str, status = Open3.capture3(command) if status.success? print "#{stdout_str}\n" else raise stderr_str; end result = stdout_str command = "git push origin #{tag}" print "#{command}\n" # ex: git push origin v1.4 stdout_str, stderr_str, status = Open3.capture3(command) if status.success? print "#{stdout_str}\n" else raise stderr_str; end result = "#{result}\n#{stdout_str}" end
upload_to_hockey(app_id, api_token, note, file_to_upload)
click to toggle source
# File lib/ruby_build_ios.rb, line 126 def self.upload_to_hockey(app_id, api_token, note, file_to_upload) command = "puck -app_id=#{app_id} -api_token=#{api_token} -submit=auto -download=true -notify=true -notes=\"#{note}\" #{file_to_upload}" print "#{command}\n" # status is a Process::Status stdout_str, stderr_str, status = Open3.capture3(command) if status.success? print "#{stdout_str}\n" else raise stderr_str; end result = stdout_str end
upload_to_itunes(user, password, ipa)
click to toggle source
May want to stream stderr to console too, because altool uses stderr instead of stdout
# File lib/ruby_build_ios.rb, line 324 def self.upload_to_itunes(user, password, ipa) # get altools path xcode_path = self.xcode_path altool = "#{xcode_path}/Applications/Application\\ Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Versions/A/Support/altool" command = "#{altool} --upload-app --type ios -u \"#{user}\" -p \"#{password}\" -f #{ipa}" print "#{command}\n" result = 'OK' status = nil stderr_str = '' Open3.popen3(command) do |stdin, stdout, stderr, wait| t1 = Thread.new do while line = stdout.gets puts line end end t2 = Thread.new do while line = stderr.gets puts line stderr_str << line end end status = wait.value t2.value t1.value end if status.success? print "#{result}\n" else raise stderr_str; end result end
validate_with_itunes(user, password, ipa)
click to toggle source
May want to stream stderr to console too, because altool uses stderr instead of stdout
# File lib/ruby_build_ios.rb, line 286 def self.validate_with_itunes(user, password, ipa) # get altools path xcode_path = self.xcode_path altool = "#{xcode_path}/Applications/Application\\ Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Versions/A/Support/altool" command = "#{altool} --validate-app --type ios -u \"#{user}\" -p \"#{password}\" -f #{ipa}" print "#{command}\n" result = 'OK' status = nil stderr_str = '' Open3.popen3(command) do |stdin, stdout, stderr, wait| t1 = Thread.new do while line = stdout.gets puts line end end t2 = Thread.new do while line = stderr.gets puts line stderr_str << line end end status = wait.value t2.value t1.value end if status.success? print "#{result}\n" else raise stderr_str; end result end
xcode_path()
click to toggle source
# File lib/ruby_build_ios.rb, line 259 def self.xcode_path() command = "dirname \"$(xcode-select -p)\"" print "#{command}\n" # status is a Process::Status stdout_str, stderr_str, status = Open3.capture3(command) if status.success? print "#{stdout_str}\n" else raise stderr_str; end result = stdout_str.chomp.chomp end