forked from CocoaPods/Specs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
400 lines (354 loc) · 9.76 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
require 'pathname'
require 'cocoapods'
require 'colored'
# Configuration
#-----------------------------------------------------------------------------#
Pod::Config.instance.repos_dir = Pathname.pwd.dirname
# Pod::Config.instance.verbose = true
# TODO temporary
#
PODS_ALLOWED_TO_FAIL = {
"Git sources should specify a tag." => [
'Appirater',
'AQGridView',
'ARCHelper',
'ARCMacro',
'AWSiOSSDK',
'AZAppearanceKit',
'cocos2d',
'CustomBadge',
'DCIntrospect',
'DDProgressView',
'DYRateView',
'EGOCache',
'EGOTableViewPullRefresh',
'Evernote-SDK-Mac',
'Flash2Cocos2D',
'GMGridView',
'IBAForms',
'iOSInstalledApps',
'JASidePanels',
'JBKenBurnsView',
'JSONKit',
'KeychainItemWrapper',
'Kiwi',
'KKGridView',
'libgit2',
'MACalendarUI',
'MAKVONotificationCenter',
'MGSplitViewController',
'MPFlipViewController',
'NSLogger-CocoaLumberjack-connector',
'ODRefreshControl',
'OHAttributedLabel',
'pubnub-api',
'RestKit',
'SBJson',
'ShareKit',
'SocketRocket',
'SPTabBarController',
'StackMob',
'TBXML',
'Three20Lite',
'TwUI',
'UIImage-Resize',
'UIResponder+KeyboardCache',
'Underscore.m',
'vfrReader',
],
"The post install hook has been deprecated, use the `resource_bundles` or the `prepare_command` attributes." => [
'AppPaoPaoSDK',
'ARCHelper',
'ARCMacro',
'CocoaLibSpotify',
'CoconutKit',
'DTCoreText',
'Facebook-iOS-SDK',
'GrannySmith',
'HockeySDK',
'LibComponentLogging-Core',
'LibComponentLogging-Crashlytics',
'LibComponentLogging-LogFile',
'LibComponentLogging-NSLog',
'LibComponentLogging-NSLogger',
'LibComponentLogging-pods',
'LibComponentLogging-qlog',
'LibComponentLogging-SystemLog',
'LibComponentLogging-UserDefaults',
'MagicalRecord',
'MapBox',
'MKStoreKit',
'PLDatabase',
'QuickDialog',
'SSToolkit',
'SYCache',
'TICoreDataSync',
'TouchDB',
'unoffical-twitter-sdk',
'XingSDK',
],
"The pre install hook has been deprecated, use the `resource_bundles` or the `prepare_command` attributes." => [
'ARAnalytics',
'CocoaLibSpotify',
'CoconutKit',
'CorePlot',
'ctemplate',
'DTCoreText',
'expat',
'Facebook-iOS-SDK',
'freexl',
'geos',
'HockeySDK',
'icu4c',
'jsoncpp',
'lambert-objc',
'LevelDB-ObjC',
'libetpan',
'libsasl2',
'LibYAML',
'MapBox',
'proj4',
'ReactiveCocoa',
'SinglySDK',
'spatialite',
'Three20',
'yajl',
],
"Github repositories should use `https` link." => [
'ARCHelper',
'ARCMacro',
],
}
#-----------------------------------------------------------------------------#
# TODO pass old spec
# TODO catch spec eval raise
desc "Run `pod spec lint` on all specs"
task :validate do
require 'cocoapods-core'
exit if ENV['skip-lint']
title('Most Recently Commited Specs ')
puts "Thanks for contributing to the master repo!"
puts "The Master repo will not accept specifications with warnings."
puts "The specifications from the most recent commit are linted with the most strict settings."
puts "For more information see: http://docs.cocoapods.org/guides/contributing_to_the_master_repo.html"
has_commit_failures = false
last_commit_specs.each do |spec_path|
spec = Pod::Spec.from_file(spec_path)
if last_commit_specs.count <= 3
puts "\n#{spec_path} [Full]"
lints = lint(spec)
else
puts "\n#{spec_path} [Quick]"
lints = quick_lint(spec)
end
acceptable = check_if_can_be_accepted(spec, spec_path)
if acceptable && lints
puts green(" -> The spec can be accepted.")
else
puts red(" -> The spec cannot be accepted.")
has_commit_failures = true
end
end
report = generate_health_report
puts "\n\n\n"
print_health_report(report)
if has_commit_failures || !report_acceptable(report)
puts red("Validation failed!")
exit 1
else
puts green("Validation passed")
end
end
#-----------------------------------------------------------------------------#
desc "Checks the repo for errors or warnings"
task :health_report do
require 'cocoapods-core'
report = generate_health_report
puts "\n\n\n"
print_health_report(report)
end
#-----------------------------------------------------------------------------#
desc "Deprecated task which was used by git pre-commit hook"
task :lint do
puts
puts yellow("The pre-commit hook of the master repo has been deprecated.")
puts "You can remove it by running:"
puts
puts " $ rm -i ~/.cocoapods/master/.git/hooks/pre-commit"
puts
puts "Please lint you specifications manually before submitting the to the"
puts "specs repo. To do so you can either use:"
puts
puts " $ pod push [ REPO ] [NAME.podspec]"
puts " $ pod spec lint [ NAME.podspec | DIRECTORY | http://PATH/NAME.podspec, ... ]"
end
#-----------------------------------------------------------------------------#
desc "Converts the specifications to JSON"
task :convert_specs_to_json do
require 'cocoapods-core'
require 'json'
puts "Adopting Specs folder"
Dir.mkdir("Specs") unless File.exist?("Specs")
Dir.glob('*/') do |dir|
unless dir == "Specs/"
FileUtils.mv(dir, "Specs/#{dir}")
end
end
puts "Converting to JSON"
skipped_specs = []
Dir.glob('**/*.podspec') do |spec_path|
spec = Pod::Spec.from_file(spec_path)
if spec.safe_to_hash?
spec_json_path = "#{spec_path}.json"
print "."
File.open(spec_json_path, 'w') { |file| file.write(JSON.pretty_generate(spec)) }
File.delete(spec_path)
else
skipped_specs << spec_path
end
end
puts yellow("\n\n[!] #{skipped_specs.count} weren't converted.")
puts "- #{skipped_specs.join("\n- ")}"
end
#-----------------------------------------------------------------------------#
task :default => :validate
# group Analysis helpers
#-----------------------------------------------------------------------------#
# @return [Bool] If the spec can be accepted
#
def check_if_can_be_accepted(spec, spec_path)
previous_spec_contents = previous_version_of_spec(spec_path)
if previous_spec_contents
previous_spec = Pod::Specification.from_string(previous_spec_contents, spec_path)
end
errors = Pod::Source::Acceptor.new('.').analyze(spec, previous_spec)
errors.each do |error|
puts red(" - ERROR | #{error}")
end
errors.count.zero?
end
# @return [Bool] Whether the spec lints
#
def lint(spec)
validator = Pod::Validator.new(spec)
validator.validate
end
# @return [Bool] Whether the spec lints
#
def quick_lint(spec)
linter = Pod::Spec::Linter.new(spec)
linter.lint
linter.results.each do |result|
puts red("- #{result}")
end
linter.results.count.zero?
end
# @return [Pod::Source::HealthReport] Returns the health report of the repo.
#
def generate_health_report
title('Health Report')
reporter = Pod::Source::HealthReporter.new('.')
count = 0
reporter.pre_check do |name, version|
count += 1
if (count % 40) == 0
print '.'
end
end
reporter.analyze
end
def report_acceptable(report)
acceptable = true
pods_by_message = report.pods_by_error.merge(report.pods_by_warning)
pods_by_message.each do |message, pods|
pods.each do |name, version|
unless PODS_ALLOWED_TO_FAIL[message] && PODS_ALLOWED_TO_FAIL[message].include?(name)
acceptable = false
end
end
end
acceptable
end
# group Git helpers
#-----------------------------------------------------------------------------#
# @return [Array<String>] Returns the relative path of the podspecs affected by
# the last commit.
#
def last_commit_specs
specs = `git diff-index --name-only HEAD | grep '.podspec$'`.strip.split("\n")
specs = ['.'] if specs.empty?
`git diff --diff-filter=ACMRTUXB --name-only HEAD~1..HEAD | grep '.podspec$'`.strip.split("\n")
end
# @return [String] The contents of the given specification before the last
# commit.
#
def previous_version_of_spec(spec_path)
contents = `git show HEAD~1:#{spec_path} 2>/dev/null`
contents if $?.to_i.zero?
end
# group UI helpers
#-----------------------------------------------------------------------------#
# Prints a title.
#
def title(title)
cyan_title = "\033[0;36m#{title}\033[0m"
puts
puts "-" * 80
puts cyan_title
puts "-" * 80
puts
end
# Colorizes a string to green.
#
def green(string)
"\033[0;32m#{string}\e[0m"
end
# Colorizes a string to yellow.
#
def yellow(string)
"\033[0;33m#{string}\e[0m"
end
# Colorizes a string to red.
#
def red(string)
"\033[0;31m#{string}\e[0m"
end
def colorize(message, color)
case color
when :red then red(message)
when :yellow then yellow(message)
when :green then green(message)
end
end
# @return [void] Prints the given health report. It colors errors in red and
# warnings in yellow. If a Pod is white listed it is indicated.
#
def print_health_report(report)
messages_by_color = {
:red => report.pods_by_error,
:yellow => report.pods_by_warning,
}
messages_by_color.each do |color, pods_by_message|
pods_by_message.keys.sort.each do |message|
versions_by_name = pods_by_message[message]
puts colorize("-> #{message}", color)
versions_by_name.each do |name, versions|
if PODS_ALLOWED_TO_FAIL[message] && PODS_ALLOWED_TO_FAIL[message].include?(name)
puts " - [WHITELISTED] #{name} (#{versions * ', '})"
else
puts " - #{name} (#{versions * ', '})"
end
end
puts
end
end
puts "Analyzed #{report.analyzed_paths.count} podspecs files."
end
#-----------------------------------------------------------------------------#
module Pod
# Suppress the warnings because they make too much noise at this stage.
module CoreUI
def self.warn(message)
end
end
end