Skip to content

Commit

Permalink
[Validation] Switch to CocoaPods 0.17
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiopelosin committed Mar 19, 2013
1 parent 922f162 commit 955a6e0
Show file tree
Hide file tree
Showing 3 changed files with 193 additions and 70 deletions.
10 changes: 6 additions & 4 deletions Gemfile
@@ -1,6 +1,8 @@
source :rubygems
source "http://rubygems.org"

# For now use 0.17 master
# gem 'cocoapods', ">= #{YAML.load_file(File.dirname(__FILE__) + "/CocoaPods-version.yml")['last']}"
gem "cocoapods-core", :git => "git://github.com/CocoaPods/Core.git"
gem "cocoapods", :git => "git://github.com/CocoaPods/CocoaPods.git"

# For now don't use 0.17.RCx
#gem 'cocoapods', ">= #{YAML.load_file(File.dirname(__FILE__) + "/CocoaPods-version.yml")['last']}"
gem 'cocoapods', '~> 0.16.4'
gem 'rake'
45 changes: 33 additions & 12 deletions Gemfile.lock
@@ -1,30 +1,50 @@
GEM
remote: http://rubygems.org/
GIT
remote: git://github.com/CocoaPods/CocoaPods.git
revision: a16ba2deb1ead40600ba75258ee3ed4d64467732
specs:
activesupport (3.2.12)
i18n (~> 0.6)
multi_json (~> 1.0)
addressable (2.3.3)
cocoapods (0.16.4)
cocoapods (0.17.0.rc5)
activesupport (~> 3.2.6)
claide (~> 0.2.0)
cocoapods-core (= 0.17.0.rc5)
cocoapods-downloader (~> 0.1.0)
colored (~> 1.2)
escape (~> 0.0.4)
faraday (~> 0.8.1)
json (~> 1.7.3)
octokit (~> 1.7)
open4 (~> 1.3.0)
rake (~> 10.0.0)
xcodeproj (~> 0.5.0)
xcodeproj (~> 0.5.2)

GIT
remote: git://github.com/CocoaPods/Core.git
revision: 8314fa4257027c8b2a39470568d8ec6b171f49cd
specs:
cocoapods-core (0.17.0.rc5)
activesupport (~> 3.2.6)
faraday (~> 0.8.1)
octokit (~> 1.7)
rake (~> 10.0.0)

GEM
remote: http://rubygems.org/
specs:
activesupport (3.2.13)
i18n (= 0.6.1)
multi_json (~> 1.0)
addressable (2.3.3)
claide (0.2.0)
cocoapods-downloader (0.1.0)
colored (1.2)
escape (0.0.4)
faraday (0.8.6)
multipart-post (~> 1.1)
faraday_middleware (0.9.0)
faraday (>= 0.7.4, < 0.9)
hashie (1.2.0)
i18n (0.6.3)
i18n (0.6.1)
json (1.7.7)
multi_json (1.6.1)
multi_json (1.7.1)
multipart-post (1.2.0)
netrc (0.7.7)
octokit (1.23.0)
Expand All @@ -36,13 +56,14 @@ GEM
netrc (~> 0.7.7)
open4 (1.3.0)
rake (10.0.3)
xcodeproj (0.5.0)
xcodeproj (0.5.2)
activesupport (~> 3.2.6)
colored (~> 1.2)

PLATFORMS
ruby

DEPENDENCIES
cocoapods (~> 0.16.4)
cocoapods!
cocoapods-core!
rake
208 changes: 154 additions & 54 deletions Rakefile
@@ -1,78 +1,178 @@
require 'pathname'
require 'cocoapods-core'
require 'cocoapods'

def rvm_ruby_dir
@rvm_ruby_dir ||= File.expand_path('../..', `which ruby`.strip)
end
#-----------------------------------------------------------------------------#

# 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('Last Commit Specs')
puts "The Master repo doesn't accepts specifications with warnings."
puts "The specifications from the last commit are linted with the"
puts "most strict settings. Please take action if you fail the tests."
puts
puts

namespace :travis do
task :install_opencflite_debs do
sh "mkdir -p .debs"
Dir.chdir(".debs") do
sh "wget http://archive.ubuntu.com/ubuntu/pool/main/i/icu/libicu44_4.4.2-2ubuntu0.11.04.1_i386.deb" unless File.exist?("libicu44_4.4.2-2ubuntu0.11.04.1_i386.deb")
base_url = "https://github.com/downloads/CocoaPods/OpenCFLite"
%w{ opencflite1_248-1_i386.deb opencflite-dev_248-1_i386.deb }.each do |deb|
sh "wget #{File.join(base_url, deb)}" unless File.exist?(deb)
end
sh "sudo dpkg -i *.deb"
has_commit_failures = false
last_commit_specs.each do |spec_path|
puts "#{spec_path}\n\n"
spec = Pod::Spec.from_file(spec_path)
acceptable = check_if_can_be_accepted(spec, spec_path)
if ENV['TRAVIS_PULL_REQUEST']
lints = lint(spec)
else
lints = quick_lint(spec)
end
end

task :fix_rvm_include_dir do
unless File.exist?(File.join(rvm_ruby_dir, 'include'))
# Make Ruby headers available, RVM seems to do not create a include dir on 1.8.7, but it does on 1.9.3.
sh "mkdir '#{rvm_ruby_dir}/include'"
sh "ln -s '#{rvm_ruby_dir}/lib/ruby/1.8/i686-linux' '#{rvm_ruby_dir}/include/ruby'"
if acceptable && lints
puts green("The spec can be accepted.")
else
has_commit_failures = true
end
end

task :setup => [:install_opencflite_debs, :fix_rvm_include_dir] do
sh "CFLAGS='-I#{rvm_ruby_dir}/include' bundle update"
report = generate_health_report
puts "\n\n\n"
print_health_report(report)

unless has_commit_failures && report.pods_by_error.empty?
exit 1
end
end

desc "Run `pod spec lint` on all specs"
task :lint do
exit if ENV['skip-lint']
#-----------------------------------------------------------------------------#

ENV['SKIP_SETUP']='1'
ENV['CP_REPOS_DIR']= Pathname.new(Dir.pwd).dirname.to_s
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

specs = `git diff-index --name-only HEAD | grep '.podspec$'`.strip.split("\n")
specs = ['.'] if specs.empty?
last_commit_podspecs = `git diff --diff-filter=ACMRTUXB --name-only HEAD~1..HEAD | grep '.podspec$'`.strip.split("\n")
last_commit_specs = last_commit_podspecs.map {|p| p.gsub(/(.*)\/.*\/.*/,'\1')}.uniq
#-----------------------------------------------------------------------------#

failures = 0
task :default => :lint

# unless last_commit_podspecs.empty?
# puts "\n>>> last commit podspecs (full lint) <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n"
# command = "pod spec lint '#{last_commit_podspecs.join("' '")}' "
# failures += 1 unless excute_command(command)
# end
# group Analysis helpers
#-----------------------------------------------------------------------------#

unless last_commit_specs.empty?
puts "\n>>> last commit pods (quick lint with warnings) <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n"
command = "pod spec lint --quick '#{last_commit_specs.join("' '")}' "
failures += 1 unless excute_command(command)
# @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|
failures += 1
puts red("- #{error}")
end
errors.count.zero?
end

puts "\n>>> Repo <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n"
command = "pod repo lint ."
failures += 1 unless excute_command(command)
# @return [Bool] Whether the spec lints
#
def lint(spec)
validator = Pod::Validator.new(spec)
validator.validate
end

unless failures.zero?
exit 1
# @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

def excute_command(command)
# begin
puts command
# do it this way so we can trap Interrupt, doesn't work well with Kernel::system and Rake's sh
system command
# rescue Interrupt
# break
# false
# @return [Pod::Source::HealthReport] Returns the health report of the repo.
#
def generate_health_report
title('Health Report')
validator = Pod::Source::HealthReporter.new('.')
validator.pre_check do |name, version|
print '.'
end
validator.analyze
end

task :default => :lint
# 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.each do |message, versions_by_name|
puts yellow("-> #{message}")
versions_by_name.each { |name, versions| puts " - #{name} (#{versions * ', '})" }
puts
end

report.pods_by_error.each do |message, versions_by_name|
puts red("-> #{message}")
versions_by_name.each { |name, versions| puts " - #{name} (#{versions * ', '})" }
puts
end
end

#-----------------------------------------------------------------------------#

module Pod
# Suppress the warnings because they make too much noise at this stage.
def CoreUI.warn(message)
end
end

0 comments on commit 955a6e0

Please sign in to comment.