/
Rakefile
194 lines (161 loc) · 4.78 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
require 'pathname'
require 'cocoapods-core'
require 'cocoapods'
# Configuration
#-----------------------------------------------------------------------------#
Pod::Config.instance.repos_dir = Pathname.pwd.dirname
Pod::Config.instance.verbose = true
#-----------------------------------------------------------------------------#
# TODO pass old spec
# TODO catch spec eval raise
desc "Run `pod spec lint` on all specs"
task :lint do
exit if ENV['skip-lint']
title('Most Recently Commited Specs ')
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|
puts "\n#{spec_path}"
spec = Pod::Spec.from_file(spec_path)
acceptable = check_if_can_be_accepted(spec, spec_path)
if ENV['TRAVIS_PULL_REQUEST'] && ENV['TRAVIS_PULL_REQUEST'] != 'false'
lints = lint(spec)
else
lints = quick_lint(spec)
end
if acceptable && lints
puts green("- The spec can be accepted.")
else
has_commit_failures = true
end
end
report = generate_health_report
puts "\n\n\n"
print_health_report(report)
if has_commit_failures || !report.pods_by_error.empty?
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
report = generate_health_report
puts "\n\n\n"
print_health_report(report)
end
#-----------------------------------------------------------------------------#
task :default => :lint
# 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)
acceptor = Pod::Source::Acceptor.new('.')
errors = acceptor.analyze(spec)
errors.each do |error|
puts red("- #{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')
validator = Pod::Source::HealthReporter.new('.')
count = 0
validator.pre_check do |name, version|
count += 1
if (count % 20) == 0
print '.'
end
end
validator.analyze
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)
`git show HEAD~1:#{spec_path}`
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
# @return [void] Prints the given health report.
#
def print_health_report(report)
report.pods_by_warning.keys.sort.each do |message|
versions_by_name = report.pods_by_warning[message]
puts yellow("-> #{message}")
versions_by_name.each { |name, versions| puts " - #{name} (#{versions * ', '})" }
puts
end
report.pods_by_error.keys.sort.each do |message|
versions_by_name = report.pods_by_error[message]
puts red("-> #{message}")
versions_by_name.each { |name, versions| puts " - #{name} (#{versions * ', '})" }
puts
end
puts "Analyzed #{report.analyzed_paths.count} podspecs files."
end
#-----------------------------------------------------------------------------#
module Pod
# Suppress the warnings because they make too much noise at this stage.
def CoreUI.warn(message)
end
end