Class: Testflight::Builder
- Inherits:
-
Object
- Object
- Testflight::Builder
- Includes:
- Appscript
- Defined in:
- lib/testflight/builder.rb
Constant Summary collapse
- XCODE_BUILDER =
"/usr/bin/xcodebuild"
- XCODE_PACKAGER =
"/usr/bin/xcrun"
- TESTFLIGHT_ENDPOINT =
"http://testflightapp.com/api/builds.json"
Instance Method Summary collapse
-
#append_log_entry(opts) ⇒ Object
FlightLog Support.
- #build_project(opts = {}) ⇒ Object
-
#build_workspace(opts = {}) ⇒ Object
Building Project.
-
#commit_changes(opts = {}) ⇒ Object
Git Support.
-
#execute(cmd, opts = {}) ⇒ Object
Command Support.
-
#increment_bundle_version(opts = {}) ⇒ Object
Project Versioning.
-
#initialize(opts = {}) ⇒ Builder
constructor
A new instance of Builder.
- #package_project(opts = {}) ⇒ Object
-
#package_workspace(opts = {}) ⇒ Object
Packaging Project.
- #tag_build(opts = {}) ⇒ Object
-
#upload_to_testflightapp(opts = {}) ⇒ Object
Uploading Project.
Constructor Details
#initialize(opts = {}) ⇒ Builder
Returns a new instance of Builder.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/testflight/builder.rb', line 36 def initialize(opts = {}) t0 = Time.now if Testflight::Config.commit_changes? commit_changes(opts) end if Testflight::Config.tag_build? tag_build(opts) end if Testflight::Config.workspace? build_workspace(opts) package_workspace(opts) else build_project(opts) package_project(opts) end upload_to_testflightapp(opts) append_log_entry(opts) if Testflight::Config.increment_bundle? increment_bundle_version(opts) if Testflight::Config.commit_changes? commit_changes(opts.merge(:message => "Incrementing build number to #{Testflight::Config.project_version}")) end end t1 = Time.now puts("Build took #{t1-t0} seconds.") end |
Instance Method Details
#append_log_entry(opts) ⇒ Object
FlightLog Support
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/testflight/builder.rb', line 165 def append_log_entry(opts) lines = [] lines << "#{Testflight::Config.application_name} #{Testflight::Config.project_version}" lines << "Deplyed On: #{Time.now}" lines << "Distributed To: #{opts[:teams].join(", ")}" lines << "Notified By Email: #{opts[:notify]}" lines << "Notes: #{opts[:message]}" lines << "---------------------------------------------------------------------------" log = "FLIGHTLOG" tmp = log + "~" File.open(tmp, "w") do |newfile| lines.each do |line| newfile.puts(line) end if File.exist?(log) File.open(log, "r+") do |oldfile| oldfile.each_line do |line| newfile.puts(line) end end end end File.delete(log) if File.exist?(log) File.rename(tmp, log) end |
#build_project(opts = {}) ⇒ Object
85 86 87 88 89 90 |
# File 'lib/testflight/builder.rb', line 85 def build_project(opts = {}) cmd = "#{XCODE_BUILDER} -target '#{Testflight::Config.application_name}' " cmd << "-sdk 'iphoneos6.0' " cmd << "-configuration 'AdHoc' " execute(cmd, opts) end |
#build_workspace(opts = {}) ⇒ Object
Building Project
75 76 77 78 79 80 81 82 83 |
# File 'lib/testflight/builder.rb', line 75 def build_workspace(opts = {}) cmd = "#{XCODE_BUILDER} -workspace '#{Testflight::Config.workspace_name}' " cmd << "-scheme '#{Testflight::Config.application_name}' " cmd << "-sdk '#{Testflight::Config.sdk_version}' " cmd << "-configuration 'AdHoc' " cmd << "-arch 'armv6 armv7' " cmd << "CONFIGURATION_BUILD_DIR='#{Testflight::Config.build_dir}' " execute(cmd, opts) end |
#commit_changes(opts = {}) ⇒ Object
Git Support
151 152 153 154 155 156 |
# File 'lib/testflight/builder.rb', line 151 def commit_changes(opts = {}) execute("git add .", opts.merge(:ignore_result => true)) execute("git add . --update", opts.merge(:ignore_result => true)) execute("git commit -m '#{opts[:message]}'", opts.merge(:ignore_result => true)) execute("git push", opts.merge(:ignore_result => true)) end |
#execute(cmd, opts = {}) ⇒ Object
Command Support
198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/testflight/builder.rb', line 198 def execute(cmd, opts = {}) puts("\r\n$ " + cmd) return if opts[:cold] result = system(cmd) return if opts[:ignore_result] unless result puts("Build failed.") exit 1 end end |
#increment_bundle_version(opts = {}) ⇒ Object
Project Versioning
133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/testflight/builder.rb', line 133 def increment_bundle_version(opts = {}) # Check if build numbers are numeric build_number = Testflight::Config.build_number.to_i build_number += 1 puts("\r\nIncrementing build number to #{build_number}...") return if opts[:cold] Testflight::Config.project_info["CFBundleVersion"] = build_number.to_s File.open(Testflight::Config.project_info_path, "w") do |f| f.write(Testflight::Config.project_info.to_plist) end end |
#package_project(opts = {}) ⇒ Object
105 106 107 108 109 110 111 112 |
# File 'lib/testflight/builder.rb', line 105 def package_project(opts = {}) cmd = "#{XCODE_PACKAGER} -sdk iphoneos PackageApplication " cmd << "-v '#{Testflight::Config.build_dir}/AdHoc-iphoneos/#{Testflight::Config.application_name}.app' " cmd << "-o '#{Testflight::Config.distribution_file}' " cmd << "--sign '#{Testflight::Config.developer_name}' " cmd << "--embed '#{Testflight::Config.provisioning_dir}/#{Testflight::Config.ad_hoc_provisioning_name}'" execute(cmd, opts) end |
#package_workspace(opts = {}) ⇒ Object
Packaging Project
96 97 98 99 100 101 102 103 |
# File 'lib/testflight/builder.rb', line 96 def package_workspace(opts = {}) cmd = "#{XCODE_PACKAGER} -sdk iphoneos PackageApplication " cmd << "-v '#{Testflight::Config.build_dir}/#{Testflight::Config.application_name}.app' " cmd << "-o '#{Testflight::Config.distribution_file}' " cmd << "--sign '#{Testflight::Config.developer_name}' " cmd << "--embed '#{Testflight::Config.provisioning_dir}/#{Testflight::Config.ad_hoc_provisioning_name}'" execute(cmd, opts) end |
#tag_build(opts = {}) ⇒ Object
158 159 160 |
# File 'lib/testflight/builder.rb', line 158 def tag_build(opts = {}) execute("git tag -a #{Testflight::Config.project_version_short} -m 'Release #{Testflight::Config.project_version}'", opts.merge(:ignore_result => true)) end |
#upload_to_testflightapp(opts = {}) ⇒ Object
Uploading Project
118 119 120 121 122 123 124 125 126 127 |
# File 'lib/testflight/builder.rb', line 118 def upload_to_testflightapp(opts = {}) cmd = "curl #{TESTFLIGHT_ENDPOINT} " cmd << "-F file=@#{Testflight::Config.distribution_file} " cmd << "-F api_token=#{Testflight::Config.api_token} " cmd << "-F team_token=#{Testflight::Config.team_token} " cmd << "-F notify=#{opts[:notify]} " cmd << "-F distribution_lists=#{opts[:teams].join(",")} " cmd << "-F notes='#{opts[:message]}'" execute(cmd, opts) end |