diff --git a/Gemfile b/Gemfile index 369c26e..4f1b065 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,23 @@ source 'https://rubygems.org' gem 'cocoapods', '1.6.0.beta.1' -gem 'fastlane' +gem 'xcpretty' + +# Danger +group :test, :danger do + gem 'slather' + gem 'circleci_artifact' + gem 'xcov' + gem 'fastlane' +end + +group :danger do + gem 'danger' + gem 'danger-swiftlint' + gem 'danger-xcov' + gem 'danger-junit' +end + +plugins_path = File.join(File.dirname(__FILE__), 'fastlane', 'Pluginfile') +eval_gemfile(plugins_path) if File.exist?(plugins_path) + diff --git a/Gemfile.lock b/Gemfile.lock index 29f7de0..e12686d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -11,7 +11,15 @@ GEM public_suffix (>= 2.0.2, < 4.0) atomos (0.1.3) babosa (1.0.2) + circleci (2.0.2) + circleci_artifact (0.1.0) + circleci (~> 2.0) claide (1.0.2) + claide-plugins (0.9.2) + cork + nap + open4 (~> 1.3) + clamp (0.6.5) cocoapods (1.6.0.beta.1) activesupport (>= 4.0.2, < 5) claide (>= 1.0.2, < 2.0) @@ -50,6 +58,30 @@ GEM commander-fastlane (4.4.6) highline (~> 1.7.2) concurrent-ruby (1.0.5) + cork (0.3.0) + colored2 (~> 3.1) + danger (5.7.0) + claide (~> 1.0) + claide-plugins (>= 0.9.2) + colored2 (~> 3.1) + cork (~> 0.1) + faraday (~> 0.9) + faraday-http-cache (~> 1.0) + git (~> 1.5) + kramdown (~> 1.5) + no_proxy_fix + octokit (~> 4.7) + terminal-table (~> 1) + danger-junit (0.7.4) + danger (> 2.0) + ox (~> 2.0) + danger-swiftlint (0.17.4) + danger + rake (> 10) + thor (~> 0.19) + danger-xcov (0.4.1) + danger (>= 2.1) + xcov (>= 1.1.2) declarative (0.0.10) declarative-option (0.1.0) domain_name (0.5.20180417) @@ -63,6 +95,8 @@ GEM faraday-cookie_jar (0.0.6) faraday (>= 0.7.4) http-cookie (~> 1.0.0) + faraday-http-cache (1.3.1) + faraday (~> 0.8) faraday_middleware (0.12.2) faraday (>= 0.7.4, < 1.0) fastimage (2.1.4) @@ -105,6 +139,7 @@ GEM fourflusher (2.0.1) fuzzy_match (2.0.4) gh_inspector (1.1.3) + git (1.5.0) google-api-client (0.23.9) addressable (~> 2.5, >= 2.5.1) googleauth (>= 0.5, < 0.7.0) @@ -128,11 +163,13 @@ GEM concurrent-ruby (~> 1.0) json (2.1.0) jwt (2.1.0) + kramdown (1.17.0) memoist (0.16.0) mime-types (3.2.2) mime-types-data (~> 3.2015) mime-types-data (3.2018.0812) mini_magick (4.5.1) + mini_portile2 (2.3.0) minitest (5.11.3) molinillo (0.6.6) multi_json (1.13.1) @@ -142,9 +179,17 @@ GEM nap (1.1.0) naturally (2.2.0) netrc (0.11.0) + no_proxy_fix (0.1.2) + nokogiri (1.8.5) + mini_portile2 (~> 2.3.0) + octokit (4.13.0) + sawyer (~> 0.8.0, >= 0.5.3) + open4 (1.3.4) os (1.0.0) + ox (2.10.0) plist (3.4.0) public_suffix (2.0.5) + rake (12.3.1) representable (3.0.4) declarative (< 0.1.0) declarative-option (< 0.2.0) @@ -153,6 +198,9 @@ GEM rouge (2.0.7) ruby-macho (1.2.0) rubyzip (1.2.2) + sawyer (0.8.1) + addressable (>= 2.3.5, < 2.6) + faraday (~> 0.8, < 1.0) security (0.1.3) signet (0.9.2) addressable (~> 2.3) @@ -163,9 +211,15 @@ GEM CFPropertyList naturally slack-notifier (2.3.2) + slather (2.4.0) + activesupport (>= 4.0.2, < 5) + clamp (~> 0.6) + nokogiri (~> 1.6) + xcodeproj (>= 0.20, < 2.0.0) terminal-notifier (1.8.0) terminal-table (1.8.0) unicode-display_width (~> 1.1, >= 1.1.1) + thor (0.20.0) thread_safe (0.3.6) tty-cursor (0.6.0) tty-screen (0.6.5) @@ -185,6 +239,12 @@ GEM claide (>= 1.0.2, < 2.0) colored2 (~> 3.1) nanaimo (~> 0.2.6) + xcov (1.5.0) + fastlane (>= 2.82.0, < 3.0.0) + multipart-post + slack-notifier + terminal-table + xcodeproj xcpretty (0.3.0) rouge (~> 2.0.7) xcpretty-travis-formatter (1.0.0) @@ -194,8 +254,16 @@ PLATFORMS ruby DEPENDENCIES + circleci_artifact cocoapods (= 1.6.0.beta.1) + danger + danger-junit + danger-swiftlint + danger-xcov fastlane + slather + xcov + xcpretty BUNDLED WITH - 1.16.3 + 1.16.5 diff --git a/fastlane/Fastfile b/fastlane/Fastfile new file mode 100644 index 0000000..3d80b8f --- /dev/null +++ b/fastlane/Fastfile @@ -0,0 +1,165 @@ +# This file contains the fastlane.tools configuration +# You can find the documentation at https://docs.fastlane.tools +# +# For a list of all available actions, check out +# +# https://docs.fastlane.tools/actions +# + +# Uncomment the line if you want fastlane to automatically update itself +# update_fastlane + +# default_platform(:ios) +fastlane_require 'circleci_artifact' +fastlane_version "2.93.1" + +BUILD_PATH="./build" +DERIVED_DATA_PATH = "#{BUILD_PATH}/derived_data" +PROJECT_NAME='Anchorage.xcodeproj' + +desc "Tests: iOS, tvOS, macOS. Builds: watchOS." +lane :coverage_all do + bundle_ios = coverage(scheme: "Anchorage-iOS", devices: get_devices(ios_latest: true, ios_10_3: true)) + bundle_tvos = coverage(scheme: "Anchorage-tvOS") + # For some reason fastlane tries to build for tvOS simulator unless destination is manually set + bundle_macos = coverage(scheme: "Anchorage-OSX", destination: "platform=macOS") + + xchtmlreport(result_bundle_paths: [bundle_ios, bundle_tvos, bundle_macos], + enable_junit: true) + # Unit testing is not available on watchOS + xcodebuild(scheme: "Anchorage-watchOS", + derivedDataPath: DERIVED_DATA_PATH) +end + +platform :mac do + desc "Runs Tests & Generates Code Coverage Reports for macOS" + lane :coverage_macos do + coverage(scheme: "Anchorage-OSX") + end +end + +platform :ios do + desc "Runs Tests & Generates Code Coverage Reports for iOS 10.3.1 and latest iOS" + lane :coverage_ios do + devices = get_devices(ios_latest: true, ios_10_3: true) + coverage(scheme: "Anchorage-iOS", + devices: devices) + end + + desc "Runs Tests & Generates Code Coverage Reports for iOS 10.3.1" + lane :coverage_ios_10_3 do + devices = get_devices(ios_10_3: true) + coverage(scheme: "Anchorage-iOS", + devices: devices) + end + + desc "Runs Tests & Generates Code Coverage Reports for latest iOS" + lane :coverage_ios_latest do + devices = get_devices(ios_latest: true) + coverage(scheme: "Anchorage-iOS", + devices: devices) + end + + desc "Runs Tests & Generates Code Coverage Reports for tvOS" + lane :coverage_tvos do + coverage(scheme: "Anchorage-tvOS") + end + + # Tests cannot be run on watchOS + desc "Build for watchOS" + lane :build_watchos do + xcodebuild(scheme: "Anchorage-watchOS", + derivedDataPath: DERIVED_DATA_PATH) + end +end + + +def coverage(scheme:, devices: nil, destination: nil) + scan_output_path = "#{BUILD_PATH}/#{scheme}/scan" + + # NOTE: Running too many devices concurrently breaks CircleCI resource limits + disable_concurrent_testing = false + if ENV['CIRCLE_BUILD_NUM'] + disable_concurrent_testing = true + end + + begin + scan( + output_types: 'junit,html', + devices: devices, + destination: destination, + scheme: scheme, + output_directory: scan_output_path, + code_coverage: true, + derived_data_path: DERIVED_DATA_PATH, + result_bundle: true, + disable_concurrent_testing: disable_concurrent_testing + ) + rescue => ex + # Don't fail the entire lane when running tests, but print failure to STDERR + STDERR.puts ex + end + + result_bundle_path = Scan.cache[:result_bundle_path] + xchtmlreport(result_bundle_path: result_bundle_path) + + slather_use_circleci = "false" + + if ENV['CIRCLE_BUILD_NUM'] + slather_use_circleci = "true" + end + + xcov( + project: PROJECT_NAME, + scheme: scheme, + output_directory: "#{BUILD_PATH}/#{scheme}/xcov", + derived_data_path: DERIVED_DATA_PATH + ) + + # Add binaries here as you create internal frameworks + slather_binaries = ['Anchorage'] + slather_output_directory = "#{BUILD_PATH}/#{scheme}/slather" + + # html and cobertura_xml output must be run separately + slather( + proj: PROJECT_NAME, + scheme: scheme, + binary_basename: slather_binaries, + output_directory: slather_output_directory, + html: "true", + build_directory: DERIVED_DATA_PATH + ) + # Using Cobertura XML allows us to upload to Codecov.io + # Uploading to codecov is handled separately in the .circleci/config.yml + slather( + proj: PROJECT_NAME, + scheme: scheme, + binary_basename: slather_binaries, + output_directory: slather_output_directory, + circleci: slather_use_circleci, + cobertura_xml: "true", + build_directory: DERIVED_DATA_PATH + ) + result_bundle_path +end + +def get_devices(ios_latest: false, ios_10_3: false) + # The full list of iOS simulators available on CircleCI + # https://circleci.com/docs/2.0/testing-ios/#supported-xcode-versions + devices = [] + if ios_latest + devices.push("iPhone SE") + devices.push("iPhone X") + devices.push("iPhone 8") + devices.push("iPhone 8 Plus") + devices.push("iPad Pro (10.5-inch)") + end + + if ios_10_3 + devices.push("iPhone SE (10.3.1)") + devices.push("iPhone 7 (10.3.1)") + devices.push("iPhone 7 Plus (10.3.1)") + devices.push("iPad Pro (10.5-inch) (10.3.1)") + end + devices +end \ No newline at end of file diff --git a/fastlane/Pluginfile b/fastlane/Pluginfile new file mode 100644 index 0000000..273a6b6 --- /dev/null +++ b/fastlane/Pluginfile @@ -0,0 +1,3 @@ +# Autogenerated by fastlane +# +# Ensure this file is checked in to source control! diff --git a/fastlane/README.md b/fastlane/README.md new file mode 100644 index 0000000..924756d --- /dev/null +++ b/fastlane/README.md @@ -0,0 +1,66 @@ +fastlane documentation +================ +# Installation + +Make sure you have the latest version of the Xcode command line tools installed: + +``` +xcode-select --install +``` + +Install _fastlane_ using +``` +[sudo] gem install fastlane -NV +``` +or alternatively using `brew cask install fastlane` + +# Available Actions +### coverage_all +``` +fastlane coverage_all +``` +Tests: iOS, tvOS, macOS. Builds: watchOS. + +---- + +## Mac +### mac coverage_macos +``` +fastlane mac coverage_macos +``` +Runs Tests & Generates Code Coverage Reports for macOS + +---- + +## iOS +### ios coverage_ios +``` +fastlane ios coverage_ios +``` +Runs Tests & Generates Code Coverage Reports for iOS 10.3.1 and latest iOS +### ios coverage_ios_10_3 +``` +fastlane ios coverage_ios_10_3 +``` +Runs Tests & Generates Code Coverage Reports for iOS 10.3.1 +### ios coverage_ios_latest +``` +fastlane ios coverage_ios_latest +``` +Runs Tests & Generates Code Coverage Reports for latest iOS +### ios coverage_tvos +``` +fastlane ios coverage_tvos +``` +Runs Tests & Generates Code Coverage Reports for tvOS +### ios build_watchos +``` +fastlane ios build_watchos +``` +Build for watchOS + +---- + +This README.md is auto-generated and will be re-generated every time [fastlane](https://fastlane.tools) is run. +More information about fastlane can be found on [fastlane.tools](https://fastlane.tools). +The documentation of fastlane can be found on [docs.fastlane.tools](https://docs.fastlane.tools).