require 'rake/tasklib' require 'rubygems' require 'xcodebuild' require 'cucumber/rake/task' module FWToolkit module Tasks class BuildTask < ::Rake::TaskLib include Rake::DSL if defined?(Rake::DSL) attr_accessor :workspace attr_accessor :scheme attr_accessor :bundle_identifier def initialize(&block) yield self if block_given? define end private def define namespace :xcode do XcodeBuild::Tasks::BuildTask.new :debug_simulator do |t| t.invoke_from_within = '.' t.configuration = "Debug" t.sdk = "iphonesimulator" t.workspace = @workspace t.scheme = @scheme t.formatter = XcodeBuild::Formatters::ProgressFormatter.new end desc 'Upload IPA to FWBuild' task :upload, :file do |t, args| file = args.file auth_token=ENV['FWBUILD_AUTH_TOKEN'] file_name = File.basename(file) key = File.join('uploads', file_name) sh("curl -X POST -F 'key=#{key}' -F 'acl=bucket-owner-full-control' -F 'file=@#{file}' https://fw.fwbuild.production.s3.amazonaws.com/ --progress-bar") sh("curl 'http://fwbuild.futureworkshops.com/apps/builds.json?bundle_identifier=#{@bundle_identifier}&s3_upload_name=#{file_name}&auth_token=#{auth_token}'") end end namespace :frank do desc 'Setup Frank' task :setup do sh "frank setup" end desc 'Build the frankified App' task :build do sh "frank build --workspace #{@workspace} --scheme #{@scheme}" end Cucumber::Rake::Task.new(:ci_test, 'Run Frank acceptance tests with CI options') do |t| ENV['APP_BUNDLE_PATH'] = File.join( Dir.pwd, 'Frank/frankified_build/Frankified.app' ) ENV['USE_SIM_LAUNCHER_SERVER'] = 'YES' artifacts_dir = ENV['CC_BUILD_ARTIFACTS'] ? ENV['CC_BUILD_ARTIFACTS'] : '/tmp' t.cucumber_opts = "Frank/features --tags ~@wip --format pretty --format html --out '#{artifacts_dir}/frank_results.html' --format rerun --out '#{artifacts_dir}/frank_rerun.txt'" end desc 'Run Frank acceptance tests' task :test, :cucumber_options do |t, args| args.with_defaults(:cucumber_options => 'Frank/features --tag ~@wip') ENV['APP_BUNDLE_PATH'] = File.join( Dir.pwd, 'Frank/frankified_build/Frankified.app' ) ENV['USE_SIM_LAUNCHER_SERVER'] = nil sh "cucumber #{args.cucumber_options}" end end namespace :bundle do task :install do sh 'bundle' end end namespace :pod do task :clean do FileUtils.rm_rf('Pods') end task :install do sh 'pod install' end desc 'Clean and install Pods' task :clean_install => [:clean, :install] end namespace :fwbuild do task :upload do S3Cmd.put("path/to/a/file.ext", "s3://fw.fwbuild.production/uploads/") do |progress| puts progress end end task :build_upload => ["xcode:release_device:clean", "xcode:release_device:archive", "upload"] end namespace :ci do desc 'Clean, build and test' task :build => ["bundle:install", "xcode:debug_simulator:cleanbuild", "frank:build", "frank:ci_test"] desc 'Clean, build and test for Cocoapods projects' task :pod_build => ["bundle:install", "pod:clean_install", "ci:build"] end end end end end