Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Set code coverage #66

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -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)

70 changes: 69 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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
165 changes: 165 additions & 0 deletions fastlane/Fastfile
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions fastlane/Pluginfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Autogenerated by fastlane
#
# Ensure this file is checked in to source control!
Loading