From d0e74a8d02b1e7e76e095f1aa1cea05f2f6bade1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=A1vio=20Caetano?= Date: Fri, 3 Nov 2017 21:40:05 -0200 Subject: [PATCH] Fix: Running Fastlane with a single device --- .gitignore | 1 + .gitmodules | 4 +- .travis.yml | 16 +----- fastlane/Fastfile | 83 ++++++++++++++++--------------- fastlane/actions | 1 - fastlane/actions/codecov | 1 + fastlane/actions/codecov.rb | 1 + fastlane/actions/ios_simulator.rb | 78 +++++++++++++++++++++++++++++ pre-push.sh | 4 +- 9 files changed, 129 insertions(+), 60 deletions(-) delete mode 160000 fastlane/actions create mode 160000 fastlane/actions/codecov create mode 120000 fastlane/actions/codecov.rb create mode 100644 fastlane/actions/ios_simulator.rb diff --git a/.gitignore b/.gitignore index cc47f4b..48b266a 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ ## Build generated build/ DerivedData +logs/ ## Various settings *.pbxuser diff --git a/.gitmodules b/.gitmodules index cd39db7..7bf2682 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/.travis.yml b/.travis.yml index 4d6cae3..bcbcbc5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/fastlane/Fastfile b/fastlane/Fastfile index 282452f..f0f5bc8 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -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 @@ -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 @@ -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 @@ -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" @@ -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 @@ -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 diff --git a/fastlane/actions b/fastlane/actions deleted file mode 160000 index 75911fa..0000000 --- a/fastlane/actions +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 75911fa21bda7824d7fe638eb3ff0f5d5f8ffe9a diff --git a/fastlane/actions/codecov b/fastlane/actions/codecov new file mode 160000 index 0000000..2f03a68 --- /dev/null +++ b/fastlane/actions/codecov @@ -0,0 +1 @@ +Subproject commit 2f03a689732adc3a6d1ccc4143b57a5de206d131 diff --git a/fastlane/actions/codecov.rb b/fastlane/actions/codecov.rb new file mode 120000 index 0000000..d4efafe --- /dev/null +++ b/fastlane/actions/codecov.rb @@ -0,0 +1 @@ +codecov/codecov.rb \ No newline at end of file diff --git a/fastlane/actions/ios_simulator.rb b/fastlane/actions/ios_simulator.rb new file mode 100644 index 0000000..9e451ce --- /dev/null +++ b/fastlane/actions/ios_simulator.rb @@ -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 diff --git a/pre-push.sh b/pre-push.sh index c9f6410..ed04ae4 100755 --- a/pre-push.sh +++ b/pre-push.sh @@ -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