Skip to content

Commit

Permalink
Fix: Running Fastlane with a single device
Browse files Browse the repository at this point in the history
  • Loading branch information
fjcaetano committed Nov 13, 2017
1 parent 44eba4a commit d0e74a8
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 60 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
## Build generated
build/
DerivedData
logs/

## Various settings
*.pbxuser
Expand Down
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "fastlane/actions"]
path = fastlane/actions
[submodule "fastlane/actions/codecov"]
path = fastlane/actions/codecov
url = https://gist.github.com/04126b3051f6cd6aebe041bb1dfe14e9.git
16 changes: 1 addition & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
osx_image: xcode9
language: objective-c

env:
matrix:
- DEVICE="iPhone X (11.0)"
- DEVICE="iPhone 7 (10.0)"
- DEVICE="iPhone 6 (9.0)"
- DEVICE="iPhone 5 (8.1)"

script:
- bundle exec fastlane test

jobs:
include:
- stage: dependency managers
script: bundle exec fastlane pod_lint
-
script: bundle exec fastlane carthage_lint
- bundle exec fastlane ci

deploy:
- provider: script
Expand Down
83 changes: 43 additions & 40 deletions fastlane/Fastfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
# Customise this file, documentation can be found here:
# https://docs.fastlane.tools/actions/
# All available actions: https://docs.fastlane.tools/actions
# can also be listed using the `fastlane actions` command

# Change the syntax highlighting to Ruby
# All lines starting with a # are ignored when running `fastlane`

# If you want to automatically update fastlane if a new version is available:
# update_fastlane

Expand All @@ -18,18 +10,34 @@ default_platform :ios
platform :ios do
skip_docs

lane :cov do
devices = [
"iPhone X (11.0)",
"iPhone 7 (10.0)",
"iPhone 6 (9.0)",
"iPhone 5s (8.1)",
]

desc "Runs the following lanes:\n- test\n- pod_lint\n- carthage_lint"
lane :ci do
test
pod_lint
carthage_lint
end

desc "Runs all the tests"
lane :test do
ios_simulator(
devices: devices,
reset_before_launching: is_ci,
)

cocoapods(
podfile: "Example/Podfile"
podfile: "Example/Podfile",
)

swiftlint(
executable: "Example/Pods/Swiftlint/swiftlint",
strict: true
strict: true,
)

# The problem lies in the fact (or rather: serious bug in xcodebuild) that
Expand All @@ -39,19 +47,23 @@ platform :ios do
# xcodebuild will give this "Canceling tests due to timeout" error.
# https://stackoverflow.com/questions/37922146/xctests-failing-on-physical-device-canceling-tests-due-to-timeout/40790171#40790171
scan(
workspace: "Example/ReCaptcha.xcworkspace",
build_for_testing: true,
devices: devices,
scheme: "ReCaptcha-Example",
device: ENV["DEVICE"],
workspace: "Example/ReCaptcha.xcworkspace",
code_coverage: true,
build_for_testing: true
buildlog_path: File.join(ENV['BITRISE_DEPLOY_DIR'] || '.', "logs/build"),
xcargs: '-maximum-concurrent-test-device-destinations=1',
)

scan(
workspace: "Example/ReCaptcha.xcworkspace",
test_without_building: true,
devices: devices,
scheme: "ReCaptcha-Example",
device: ENV["DEVICE"],
workspace: "Example/ReCaptcha.xcworkspace",
code_coverage: true,
test_without_building: true
buildlog_path: File.join(ENV['BITRISE_DEPLOY_DIR'] || '.', "logs/run"),
xcargs: '-maximum-concurrent-test-device-destinations=1',
)

if is_ci
Expand All @@ -67,14 +79,7 @@ platform :ios do

desc "Lint Cocoapods Lib"
lane :pod_lint do
cocoapods(
podfile: "Example/Podfile",
repo_update: true
)

pod_lib_lint(
allow_warnings: true # Remove this when RxSwift stops warning
)
pod_lib_lint
end

desc "Lint Carthage lib"
Expand All @@ -89,33 +94,38 @@ platform :ios do
command: "build",
platform: "iOS",
cache_builds: true,
no_skip_current: true
no_skip_current: true,
)
end

desc "Deploy a new version to Github and Cocoapods"
lane :release do
carthage "archive"
ci unless is_ci

carthage(
command: "archive",
)

pod_push(
path: "ReCaptcha.podspec",
verbose: true
verbose: true,
)

prev_tag = sh "git describe --abbrev=0 --tags `git rev-list --tags --skip=1 --max-count=1`"
changelog = changelog_from_git_commits(
tag_match_pattern: "*",
between: [last_git_tag, prev_tag.strip],
pretty: "- %s"
)

set_github_release(
repository_name: "fjcaetano/ReCaptcha",
tag_name: last_git_tag,
upload_assets: ["ReCaptcha.framework"],
description: changelog
name: last_git_tag,
upload_assets: ["ReCaptcha.framework.zip"],
description: changelog,
)
end

# You can define as many lanes as you want

after_all do |lane|
# This block is called, only if the executed lane was successful

Expand All @@ -131,10 +141,3 @@ platform :ios do
# )
end
end


# More information about multiple platforms in fastlane: https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Platforms.md
# All available actions: https://docs.fastlane.tools/actions

# fastlane reports which actions are used. No personal data is recorded.
# Learn more at https://github.com/fastlane/fastlane#metrics
1 change: 0 additions & 1 deletion fastlane/actions
Submodule actions deleted from 75911f
1 change: 1 addition & 0 deletions fastlane/actions/codecov
Submodule codecov added at 2f03a6
1 change: 1 addition & 0 deletions fastlane/actions/codecov.rb
78 changes: 78 additions & 0 deletions fastlane/actions/ios_simulator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
module Fastlane
module Actions
module SharedValues
IOS_SIMULATOR_CUSTOM_VALUE = :IOS_SIMULATOR_CUSTOM_VALUE
end

class IosSimulatorAction < Action
@@already_booted_code = 164

def self.run(params)
devices = params[:devices] || Array(params[:device])
available_sims = FastlaneCore::Simulator.all

devices.each do |device|
sim = available_sims.detect { |d| device == "#{d.name} (#{d.os_version})" }
if sim.nil?
UI.error "Device not found: #{device}"
next
end

if params[:reset_before_launching]
sim.reset
end

`xcrun simctl boot #{sim.udid} > /dev/null 2>&1`
if $?.exitstatus == @@already_booted_code
UI.important "Skipping #{device} (already booted)"
end

UI.message "Booted #{device} [#{sim.udid}]" unless $?.exitstatus == @@already_booted_code
end
end

#####################################################
# @!group Documentation
#####################################################

def self.description
"Launch iOS simulators beforehand to allow for boot time"
end

def self.details
"Run `xcrun instruments -s` for the list of available simulators"
end

def self.available_options
[
FastlaneCore::ConfigItem.new(key: :device,
env_name: "SCAN_DEVICE",
description: "The name of the simulator type you want to run tests on (e.g. 'iPhone 6 (10.0)')", # a short description of this parameter
conflicting_options: [:devices],
),
FastlaneCore::ConfigItem.new(key: :devices,
env_name: "SCAN_DEVICES",
description: "Array of devices to run the tests on (e.g. ['iPhone 6 (10.0)', 'iPad Air (8.3)'])",
is_string: false,
conflicting_options: [:device],
optional: true,
),
FastlaneCore::ConfigItem.new(key: :reset_before_launching,
env_name: "FL_IOS_SIMULATOR_RESET",
description: "Should reset simulators before launching",
is_string: false,
default_value: false,
),
]
end

def self.author
"Flávio Caetano (@fjcaetano)"
end

def self.is_supported?(platform)
platform == :ios
end
end
end
end
4 changes: 2 additions & 2 deletions pre-push.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/bin/sh

if $(which bundle &> /dev/null); then
bundle exec fastlane test
bundle exec fastlane ci
elif $(which fastlane &> /dev/null); then
fastlane test
fastlane ci
else
echo 'Fastlane not installed; Run `bundle install` or install Fastlane directly'
exit 1
Expand Down

0 comments on commit d0e74a8

Please sign in to comment.