forked from CocoaPods/Core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
196 lines (159 loc) · 5.25 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
# Travis support
def rvm_ruby_dir
@rvm_ruby_dir ||= File.expand_path('../..', `which ruby`.strip)
end
namespace :travis do
task :setup do
sh "git submodule update --init"
sh "env CFLAGS='-I#{rvm_ruby_dir}/include' bundle install --without debugging documentation"
end
end
namespace :gem do
def gem_version
require File.expand_path('../lib/cocoapods-core/gem_version', __FILE__)
Pod::CORE_VERSION
end
def gem_filename
"cocoapods-core-#{gem_version}.gem"
end
desc "Build a gem for the current version"
task :build do
sh "gem build cocoapods-core.gemspec"
end
desc "Install a gem version of the current code"
task :install => :build do
sh "gem install #{gem_filename}"
end
def silent_sh(command)
output = `#{command} 2>&1`
unless $?.success?
puts output
exit 1
end
output
end
desc "Run all specs, build and install gem, commit version change, tag version change, and push everything"
task :release do
unless ENV['SKIP_CHECKS']
if `git symbolic-ref HEAD 2>/dev/null`.strip.split('/').last != 'master'
$stderr.puts "[!] You need to be on the `master' branch in order to be able to do a release."
exit 1
end
if `git tag`.strip.split("\n").include?(gem_version)
$stderr.puts "[!] A tag for version `#{gem_version}' already exists. Change the version in lib/cocoapods-core/.rb"
exit 1
end
puts "You are about to release `#{gem_version}', is that correct? [y/n]"
exit if $stdin.gets.strip.downcase != 'y'
diff_lines = `git diff --name-only`.strip.split("\n")
if diff_lines.size == 0
$stderr.puts "[!] Change the version number yourself in lib/cocoapods-core/gem_version.rb"
exit 1
end
diff_lines.delete('Gemfile.lock')
if diff_lines != ['lib/cocoapods-core/gem_version.rb']
$stderr.puts "[!] Only change the version number in a release commit!"
$stderr.puts diff_lines
exit 1
end
end
require 'date'
# Ensure that the branches are up to date with the remote
sh "git pull"
puts "* Updating Bundler"
silent_sh('bundle update')
puts "* Running specs"
silent_sh('rake spec:all')
# puts "* Checking compatibility with the master repo"
# silent_sh('rake spec:repo')
tmp = File.expand_path('../tmp', __FILE__)
tmp_gems = File.join(tmp, 'gems')
Rake::Task['gem:build'].invoke
puts "* Testing gem installation (tmp/gems)"
silent_sh "rm -rf '#{tmp}'"
silent_sh "gem install --install-dir='#{tmp_gems}' #{gem_filename}"
# Then release
sh "git commit lib/cocoapods-core/gem_version.rb -m 'Release #{gem_version}'"
sh "git tag -a #{gem_version} -m 'Release #{gem_version}'"
sh "git push origin master"
sh "git push origin --tags"
sh "gem push #{gem_filename}"
end
end
namespace :spec do
def specs(dir)
FileList["spec/#{dir}/*_spec.rb"].shuffle.join(' ')
end
desc "Automatically run specs for updated files"
task :kick do
exec "bundle exec kicker -c"
end
task :all do
ENV['GENERATE_COVERAGE'] = 'true'
sh "bundle exec bacon #{specs('**')}"
end
desc "Checks that the gem is campable of loading all the specs of the master repo."
task :repo do
puts "Checking compatibility with master repo"
require 'pathname'
root = Pathname.new(File.expand_path('../', __FILE__))
$:.unshift((root + 'lib').to_s)
require 'cocoapods-core'
master_repo_path = ENV['HOME'] + "/.cocoapods/master"
glob_pattern = (master_repo_path + "/**/*.podspec").to_s
total_count = 0
incompatible_count = 0
spec_with_errors_count = 0
specs = []
Dir.glob(glob_pattern).each do |filename|
Pathname(filename)
begin
total_count += 1
specs << Pod::Specification.from_file(Pathname(filename))
rescue Exception => e
incompatible_count += 1
puts "\n\e[1;33m"
puts e.class
puts "\e[0m\n"
puts e.message
puts
puts e.backtrace.reject { |l| !l.include?(Dir.pwd) || l.include?('/Rakefile')}
FALSE
end
end
puts "\n\n---\n"
specs.each do |s|
linter = Pod::Specification::Linter.new(s)
linter.lint
unless linter.errors.empty?
spec_with_errors_count += 1
puts "\n#{s.name} #{s.version}"
results = linter.errors.map do |r|
if r.type == :error then "\e[1;33m #{r.to_s}\e[0m"
else " " + r.to_s end
end
puts results * "\n"
end
end
puts
if incompatible_count.zero? && spec_with_errors_count.zero?
message = "#{total_count} podspecs analyzed. All compatible."
puts "\e[1;32m#{message}\e[0m" # Print in green
else
message = "#{incompatible_count} podspecs out of #{total_count} did fail to load."
message << "\n#{spec_with_errors_count} podspecs presents errors."
STDERR.puts "\e[1;31m#{message}\e[0m" # Print in red
exit 1
end
end
end
desc "Initializes your working copy to run the specs"
task :bootstrap do
puts "Updating submodules..."
`git submodule update --init --recursive`
puts "Installing gems"
`bundle install`
end
desc "Run all specs"
task :spec => 'spec:all'
task :default => :spec