Class: Fastlane::CrashlyticsBeta
- Inherits:
-
Object
- Object
- Fastlane::CrashlyticsBeta
- Defined in:
- lib/fastlane/setup/crashlytics_beta.rb
Instance Method Summary collapse
- #api_key_valid?(key) ⇒ Boolean
- #build_secret_valid?(secret) ⇒ Boolean
- #fastfile_template(api_key, build_secret, scheme) ⇒ Object
- #includes_run_script?(string) ⇒ Boolean
- #keys_from_project(project) ⇒ Object
- #lane_template(api_key, build_secret, scheme) ⇒ Object
- #run ⇒ Object
Instance Method Details
#api_key_valid?(key) ⇒ Boolean
61 62 63 |
# File 'lib/fastlane/setup/crashlytics_beta.rb', line 61 def api_key_valid?(key) key.to_s.length == 40 end |
#build_secret_valid?(secret) ⇒ Boolean
65 66 67 |
# File 'lib/fastlane/setup/crashlytics_beta.rb', line 65 def build_secret_valid?(secret) secret.to_s.length == 64 end |
#fastfile_template(api_key, build_secret, scheme) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/fastlane/setup/crashlytics_beta.rb', line 87 def fastfile_template(api_key, build_secret, scheme) <<-eos fastlane_version "1.93.0" default_platform :ios platform :ios do lane :beta do gym(scheme: '#{scheme}') crashlytics(api_token: '#{api_key}', build_secret: '#{build_secret}', notifications: false, emails: [], groups: [] ) end end eos end |
#includes_run_script?(string) ⇒ Boolean
69 70 71 |
# File 'lib/fastlane/setup/crashlytics_beta.rb', line 69 def includes_run_script?(string) string.include?('Fabric/run') || string.include?('Crashlytics/run') || string.include?('Fabric.framework/run') || string.include?('Crashlytics.framework/run') end |
#keys_from_project(project) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/fastlane/setup/crashlytics_beta.rb', line 26 def keys_from_project(project) require 'xcodeproj' target_name = project.default_build_settings(key: 'TARGETNAME') path = project.is_workspace ? project.path.gsub('xcworkspace', 'xcodeproj') : project.path UI.crash!("No project available at path #{path}") unless File.exist?(path) xcode_project = Xcodeproj::Project.open(path) target = xcode_project.targets.find { |t| t.name == target_name } scripts = target.build_phases.select { |t| t.class == Xcodeproj::Project::Object::PBXShellScriptBuildPhase } crash_script = scripts.find { |s| includes_run_script?(s.shell_script) } UI.user_error!("Unable to find Crashlytics Run Script Build Phase") if crash_script.nil? script_array = crash_script.shell_script.split('\n').find { |l| includes_run_script?(l) }.split(' ') if script_array.count == 3 && api_key_valid?(script_array[1]) && build_secret_valid?(script_array[2]) { api_key: script_array[1], build_secret: script_array[2] } else UI.important('fastlane was unable to detect your Fabric API Key and Build Secret. 🔑') UI.important('Navigate to https://www.fabric.io/settings/organizations, select the appropriate organization,') UI.important('and copy the API Key and Build Secret.') keys = {} loop do keys[:api_key] = UI.input('API Key:') break if api_key_valid?(keys[:api_key]) UI.important "Invalid API Key, Please Try Again!" end loop do keys[:build_secret] = UI.input('Build Secret:') break if build_secret_valid?(keys[:build_secret]) UI.important "Invalid Build Secret, Please Try Again!" end keys end end |
#lane_template(api_key, build_secret, scheme) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/fastlane/setup/crashlytics_beta.rb', line 73 def lane_template(api_key, build_secret, scheme) %{ lane :beta do gym(scheme: '#{scheme}') crashlytics(api_token: '#{api_key}', build_secret: '#{build_secret}', notifications: false, emails: [], groups: [] ) end } end |
#run ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/fastlane/setup/crashlytics_beta.rb', line 3 def run UI.user_error!('Beta by Crashlytics configuration is currently only available for iOS projects.') unless Setup.new.is_ios? config = {} FastlaneCore::Project.detect_projects(config) project = FastlaneCore::Project.new(config) keys = keys_from_project(project) if FastlaneFolder.setup? UI.header('Copy and paste the following lane into your Fastfile to use Crashlytics Beta!') puts lane_template(keys[:api_key], keys[:build_secret], project.schemes.first).cyan else fastfile = fastfile_template(keys[:api_key], keys[:build_secret], project.schemes.first) FileUtils.mkdir_p('fastlane') File.write('fastlane/Fastfile', fastfile) UI.success('A Fastfile has been generated for you at ./fastlane/Fastfile 🚀') end UI.header('Next Steps') UI.success('Run `fastlane beta` to build and upload to Beta by Crashlytics. 🎯') UI.success('After submitting your beta, visit https://fabric.io/_/beta to add release notes and notify testers.') UI.success('You can edit your Fastfile to distribute and notify testers automatically.') UI.success('Learn more here: https://github.com/fastlane/setups/blob/master/samples-ios/distribute-beta-build.md 🚀') end |