ios-box 0.2.1 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,35 @@
1
+ require 'rest_client'
2
+
3
+ module IOSBox
4
+ module Deploy
5
+ class Testflight < Deployer
6
+ def deploy(opts)
7
+ puts opts.to_yaml
8
+
9
+ response = RestClient.post 'http://testflightapp.com/api/builds.plist',
10
+ :api_token => opts[:apitoken],
11
+ :team_token => opts[:teamtoken],
12
+ :file => File.new(opts[:file], 'rb'),
13
+ :notes => opts[:notes],
14
+ :dsym => (File.exists?(opts[:dsym]) ? File.new(opts[:dsym], 'rb') : nil),
15
+ :distribution_lists => opts[:distribution],
16
+ :notify => opts[:notify],
17
+ :replace => opts[:replace]
18
+
19
+ if response.code == 200
20
+ pl = Plist::parse_xml(response.to_str)
21
+
22
+ puts "Build Deployed."
23
+ puts "See it at: #{pl['config_url']}"
24
+
25
+ notify(
26
+ :name => "Build Deployed",
27
+ :title => "Build Deployed",
28
+ :text => "Build Deployed to Testflight.\nSee build at #{pl['config_url']}")
29
+ end
30
+
31
+ puts "Complete build at #{pl['config_url']}"
32
+ end
33
+ end
34
+ end
35
+ end
@@ -4,16 +4,59 @@ require 'yaml'
4
4
  require 'grit'
5
5
  require 'plist'
6
6
 
7
- module Ios::Box
7
+ module IOSBox
8
8
  class IOSBox
9
9
  attr_reader :config, :cache, :version
10
10
 
11
11
  def initialize
12
- @config = Config.load
12
+ # @config = Config.load
13
+ @config = Config.load ".iosbox"
14
+
13
15
  @cache = Cache.load
14
16
  @version = Version.new(self)
15
17
  end
16
18
 
19
+ def project_dir(default = nil)
20
+ if ENV['XCODE_VERSION_ACTUAL']
21
+ pdir = ENV['PROJECT_DIR']
22
+ else
23
+ # Do we have buildcache?
24
+ if cache[:latest]
25
+ configuration = cache[:latest]
26
+ pdir = cache[configuration][:project_dir]
27
+ else
28
+ if default.nil?
29
+ raise "Build cache has not been filled, please build project."
30
+ else
31
+ pdir = default
32
+ end
33
+ end
34
+ end
35
+
36
+ pdir
37
+ end
38
+
39
+ def plist
40
+ if ENV['XCODE_VERSION_ACTUAL']
41
+ file = File.join(ENV['PROJECT_DIR'], ENV['INFOPLIST_FILE'])
42
+ else
43
+ # Do we have buildcache?
44
+ if cache[:latest]
45
+ configuration = cache[:latest]
46
+ file = File.join(cache[configuration][:project_dir], cache[configuration][:infoplist_file])
47
+ else
48
+ raise "Build cache has not been filled, please build project."
49
+ end
50
+ end
51
+
52
+ file
53
+ end
54
+
55
+ def git
56
+ @git ||= Grit::Repo.new(project_dir)
57
+ end
58
+
59
+
17
60
  class Version
18
61
  attr_reader :iosbox
19
62
 
@@ -24,52 +67,27 @@ module Ios::Box
24
67
  def load
25
68
  # Return cached version
26
69
  return @version if @version
27
-
28
- # iOS code
29
- # XCode environment?
30
- # Load buildcache if exists
31
- if ENV['XCODE_VERSION_ACTUAL']
32
- plist_file = File.join(ENV['PROJECT_DIR'], ENV['INFOPLIST_FILE'])
33
- project_dir = ENV['PROJECT_DIR']
34
- else
35
- # Do we have buildcache?
36
- if iosbox.cache[:latest]
37
- configuration = iosbox.cache[:latest]
38
- plist_file = File.join(iosbox.cache[configuration][:project_dir], iosbox.cache[configuration][:infoplist_file])
39
- project_dir = iosbox.cache[configuration][:project_dir]
40
- else
41
- raise "Build cache has not been filled, please build project."
42
- end
43
- end
44
70
 
45
71
  # Detect our commit hash
46
- git = Grit::Repo.new("#{project_dir}")
47
-
48
- plist = Plist::parse_xml(plist_file)
72
+ # git = Grit::Repo.new(iosbox.project_dir)
73
+ pl = Plist::parse_xml(iosbox.plist)
49
74
 
50
75
  # Build normal version hash
51
- @version = {
52
- :short => plist["CFBundleShortVersionString"],
53
- :bundle => plist["CFBundleVersion"],
54
- :commit => git.commit("HEAD").id_abbrev,
76
+ @version = {
77
+ :short => pl["CFBundleShortVersionString"],
78
+ :bundle => pl["CFBundleVersion"],
79
+ :commit => iosbox.git.commit("HEAD").id_abbrev,
80
+ :build => pl["IBBuildNumber"],
55
81
  }
56
82
 
57
83
  # Build technical version number
58
- if (m = plist["CFBundleShortVersionString"].match(/(\d+)\.(\d+)(\.(\d+))?/))
84
+ if (m = pl["CFBundleShortVersionString"].match(/(\d+)\.(\d+)(\.(\d+))?/))
59
85
  @version[:major] = Integer(m[1]) if m[1]
60
86
  @version[:minor] = Integer(m[2]) if m[2]
61
87
  @version[:patch] = Integer(m[4]) if m[4]
62
- @version[:technical] = @version[:major] + ((@version[:minor] * 100) / 1000.0)
63
- if @version[:patch]
64
- @version[:technical] += ((@version[:patch] > 10) ? @version[:patch] : @version[:patch] * 10) / 1000.0
65
- end
88
+ @version[:technical] = @version[:major] + @version[:minor] / 100.0 + (@version[:patch] || 0) / 10000.0
66
89
  end
67
90
 
68
- # Fetch current build number (project version)
69
- # Check if we have build number in cache
70
-
71
- @version[:build_number] = fetch_build_number
72
-
73
91
  @version
74
92
  end
75
93
 
@@ -82,34 +100,87 @@ module Ios::Box
82
100
  @version ||= load
83
101
  @version[v] = s
84
102
  end
85
-
103
+
104
+ def to_a
105
+ (@version ||= load).to_a
106
+ end
107
+
86
108
  def marketing_version
109
+ load unless @version
87
110
  "%d.%d%s" % [ @version[:major], @version[:minor], @version[:patch] ? ".#{@version[:patch]}" : "" ]
88
111
  end
89
-
112
+
113
+ def bundle_version
114
+ load unless @version
115
+
116
+ # Build our components
117
+ comp = {
118
+ "M" => @version[:major],
119
+ "m" => @version[:minor],
120
+ "p" => @version[:patch],
121
+ "P" => @version[:patch] ? ".#{@version[:patch]}" : "",
122
+ "b" => @version[:build],
123
+ "S" => marketing_version,
124
+ "V" => @version[:major] * 10 + @version[:minor],
125
+ "v" => @version[:major] * 100 + @version[:minor] * 10 + (@version[:patch] ? @version[:patch] : 0),
126
+ "x" => begin
127
+ prj_begin = Time.now
128
+ if (iosbox.config.first_revision)
129
+ prj_begin = iosbox.git.commit(iosbox.config.first_revision).authored_date
130
+ elsif (iosbox.config.first_date)
131
+ prj_begin = iosbox.config.first_date
132
+ else
133
+ prj_begin = iosbox.git.log.last.authored_date
134
+ end
135
+
136
+ months = ((Time.now.month + 12 * Time.now.year) - (prj_begin.month + 12 * prj_begin.year))
137
+ "%d%02d" % [months, Time.now.day]
138
+ end,
139
+ }
140
+ compre = Regexp.new("[" + comp.keys.join("") + "]")
141
+
142
+ @version[:bundle] = (iosbox.config.bundle_version_style || "x").gsub(compre) do |s|
143
+ comp[s]
144
+ end
145
+ end
146
+
90
147
  def bump_build(buildnum = nil)
91
148
  # Fetch current build number (project version)
92
- # Check if we have build number in cache
149
+ pl = Plist::parse_xml(iosbox.plist)
150
+ # pl["CFBundleShortVersionString"] = verstr
151
+ # pl.save_plist(plist)
152
+
93
153
  if buildnum.nil?
94
- build = (fetch_build_number || 0) + 1
154
+ build = (pl["IBBuildNumber"] || 0) + 1
95
155
  else
96
156
  build = buildnum
97
157
  end
98
158
 
99
- store_build_number(build)
100
-
101
- puts "Build number increased to #{iosbox.cache[:build_number]}"
159
+ pl["IBBuildNumber"] = build
160
+ pl["CFBundleVersion"] = bundle_version
161
+ pl.save_plist(iosbox.plist)
162
+
163
+ # Commit plist
164
+ if iosbox.config['autocommit']
165
+ iosbox.git.add iosbox.plist
166
+ iosbox.git.commit "Bumped build number"
167
+ end
168
+
169
+
170
+ puts "Build number increased to #{build}"
102
171
  end
103
172
 
104
173
  def set_marketing(verstr)
105
- pl = Plist::parse_xml(plist)
174
+ pl = Plist::parse_xml(iosbox.plist)
106
175
  pl["CFBundleShortVersionString"] = verstr
107
- pl.save_plist(plist)
176
+ pl.save_plist(iosbox.plist)
177
+
178
+ puts "New marketing version #{marketing_version}"
108
179
  end
109
-
180
+
110
181
  def bump_marketing(type = :patch)
111
182
  load
112
-
183
+
113
184
  if type == :major
114
185
  @version[:patch] = nil
115
186
  @version[:minor] = 0
@@ -120,84 +191,13 @@ module Ios::Box
120
191
  elsif type == :patch
121
192
  @version[:patch] = (@version[:patch] || 0) + 1
122
193
  end
123
-
124
- pl = Plist::parse_xml(plist)
194
+
195
+ pl = Plist::parse_xml(iosbox.plist)
125
196
  pl["CFBundleShortVersionString"] = marketing_version
126
- pl.save_plist(plist)
127
-
197
+ pl.save_plist(iosbox.plist)
198
+
128
199
  puts "New marketing version #{marketing_version}"
129
200
  end
130
-
131
- private
132
- def fetch_build_number
133
- unless iosbox.cache[:build_number]
134
- puts "Project: #{iosbox.config.project}"
135
- pbx = PBXProject::PBXProject.new :file => File.join(iosbox.config.project, "project.pbxproj")
136
- pbx.parse
137
-
138
- iosbox.config.targets.each do |target|
139
- target = pbx.find_item :name => target, :type => PBXProject::PBXTypes::PBXNativeTarget
140
- cl = pbx.find_item :guid => target.buildConfigurationList.value, :type => PBXProject::PBXTypes::XCConfigurationList
141
- cl.buildConfigurations.each do |bc|
142
- bc = pbx.find_item :guid => bc.value, :type => PBXProject::PBXTypes::XCBuildConfiguration
143
-
144
- if bc.buildSettings["CURRENT_PROJECT_VERSION"]
145
- iosbox.cache[:build_number] = bc.buildSettings["CURRENT_PROJECT_VERSION"].value
146
- break
147
- end
148
- end
149
-
150
- break if iosbox.cache[:build_number]
151
- end
152
-
153
- # Save build number to cache
154
- iosbox.cache.save
155
- end
156
-
157
- Integer(iosbox.cache[:build_number] || 0)
158
- end
159
-
160
- def store_build_number(build)
161
- puts "Project: #{iosbox.config.project}"
162
- pbx = PBXProject::PBXProject.new :file => File.join(iosbox.config.project, "project.pbxproj")
163
- pbx.parse
164
-
165
- iosbox.config.targets.each do |target|
166
- target = pbx.find_item :name => target, :type => PBXProject::PBXTypes::PBXNativeTarget
167
- cl = pbx.find_item :guid => target.buildConfigurationList.value, :type => PBXProject::PBXTypes::XCConfigurationList
168
- cl.buildConfigurations.each do |bc|
169
- bc = pbx.find_item :guid => bc.value, :type => PBXProject::PBXTypes::XCBuildConfiguration
170
-
171
- if bc.buildSettings["CURRENT_PROJECT_VERSION"]
172
- bc.buildSettings["CURRENT_PROJECT_VERSION"].value = "\"#{build}\""
173
- else
174
- bc.buildSettings["CURRENT_PROJECT_VERSION"] = PBXProject::PBXTypes::BasicValue.new :value => "\"#{build}\""
175
- end
176
- end
177
- end
178
-
179
- # Save build number to pbxproject and to cache
180
- pbx.write_to :file => File.join(iosbox.config.project, "project.pbxproj")
181
- iosbox.cache[:build_number] = build
182
- iosbox.cache.save
183
- end
184
-
185
- # Return plist file name
186
- def plist
187
- if ENV['XCODE_VERSION_ACTUAL']
188
- file = File.join(ENV['PROJECT_DIR'], ENV['INFOPLIST_FILE'])
189
- else
190
- # Do we have buildcache?
191
- if iosbox.cache[:latest]
192
- configuration = iosbox.cache[:latest]
193
- file = File.join(iosbox.cache[configuration][:project_dir], iosbox.cache[configuration][:infoplist_file])
194
- else
195
- raise "Build cache has not been filled, please build project."
196
- end
197
- end
198
-
199
- file
200
- end
201
201
  end
202
202
  end
203
203
 
data/lib/ios-box/tools.rb CHANGED
@@ -1,11 +1,11 @@
1
1
  require 'ios-box/iosbox'
2
2
  require 'thor'
3
3
 
4
- module Ios
5
- module Box
6
- module Tools
7
- autoload :Version, 'ios-box/tools/version'
8
- autoload :Build, 'ios-box/tools/build'
9
- end
4
+ module IOSBox
5
+ module Tools
6
+ autoload :Version, 'ios-box/tools/version'
7
+ autoload :Build, 'ios-box/tools/build'
8
+ autoload :Config, 'ios-box/tools/config'
9
+ autoload :Deploy, 'ios-box/tools/deploy'
10
10
  end
11
11
  end
@@ -1,62 +1,61 @@
1
- module Ios
2
- module Box
3
- module Tools
4
- class Build < Thor
5
-
6
- desc "prepare", "Prepare build environment from XCode"
7
- def prepare
8
- # Make sure we are in XCode environment
9
- require_xcode
10
-
11
- # Update build cache
12
- update_cache
13
-
14
- version = IOSBox.new.version
15
-
16
- # Calculate build number (displayed)
17
- puts "TODO: build number"
18
-
19
- # Inject information to Info.plist
20
- product_plist = File.join(ENV['BUILT_PRODUCTS_DIR'], ENV['INFOPLIST_PATH'])
21
-
22
- # Convert PList to XML
23
- `/usr/bin/plutil -convert xml1 \"#{product_plist}\"`
24
- pl = Plist::parse_xml(product_plist)
25
- if (pl)
26
- # pl["CFBundleVersion"] = @config._bundle_version
27
- pl["IBBuildNum"] = version[:build_number]
28
- pl["IBBuildDate"] = Time.new.strftime("%a %e %b %Y %H:%M:%S %Z %z")
29
- pl["IBBuildType"] = ENV['CONFIGURATION']
30
- pl["GCGitCommitHash"] = version[:commit] # for hoptoadapp
31
- pl.save_plist(product_plist)
32
- end
33
- # Convert PList back to binary
34
- `/usr/bin/plutil -convert binary1 \"#{product_plist}\"`
1
+ module IOSBox
2
+ module Tools
3
+ class Build < Thor
4
+
5
+ desc "prepare", "Prepare build environment from XCode"
6
+ def prepare
7
+ # Make sure we are in XCode environment
8
+ require_xcode
9
+
10
+ # Update build cache
11
+ update_cache
12
+
13
+ version = IOSBox.new.version
14
+
15
+ puts "Bundle Version: #{version[:bundle]}"
16
+ puts " Short Version: #{version[:short]}"
17
+ puts " Build: #{version[:build]}"
18
+
19
+ # Inject information to Info.plist
20
+ product_plist = File.join(ENV['BUILT_PRODUCTS_DIR'], ENV['INFOPLIST_PATH'])
21
+
22
+ # Convert PList to XML
23
+ `/usr/bin/plutil -convert xml1 \"#{product_plist}\"`
24
+ pl = Plist::parse_xml(product_plist)
25
+ if (pl)
26
+ # pl["CFBundleVersion"] = @config._bundle_version
27
+ pl["IBBuildNum"] = version[:build]
28
+ pl["IBBuildDate"] = Time.new.strftime("%a %e %b %Y %H:%M:%S %Z %z")
29
+ pl["IBBuildType"] = ENV['CONFIGURATION']
30
+ pl["GCGitCommitHash"] = version[:commit] # for airbrake
31
+ pl.save_plist(product_plist)
35
32
  end
36
-
37
- private
38
-
33
+ # Convert PList back to binary
34
+ `/usr/bin/plutil -convert binary1 \"#{product_plist}\"`
35
+ end
36
+
37
+ private
38
+
39
39
  def update_cache
40
40
  cache = IOSBox.new.cache
41
-
41
+
42
42
  # Save our environment variables
43
43
  if ENV["CONFIGURATION"]
44
44
  configuration = ENV["CONFIGURATION"].downcase.to_sym
45
45
  cache[configuration] ||= {}
46
46
  cache[:latest] = configuration
47
47
  ["BUILT_PRODUCTS_DIR", "BUILD_DIR", "CONFIGURATION", "CONFIGURATION_BUILD_DIR",
48
- "PROJECT_DIR", "INFOPLIST_FILE", "TARGET_NAME"].each do |v|
48
+ "PROJECT_DIR", "INFOPLIST_FILE", "TARGET_NAME"].each do |v|
49
49
  cache[configuration][v.downcase.to_sym] = ENV[v]
50
50
  end
51
51
  end
52
-
52
+
53
53
  cache.save
54
54
  end
55
-
55
+
56
56
  def require_xcode
57
57
  raise "This task must be run in XCode Environment" unless ENV['XCODE_VERSION_ACTUAL']
58
58
  end
59
- end
60
59
  end
61
60
  end
62
61
  end