Class: Fastlane::CrashlyticsBeta

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/setup/crashlytics_beta.rb

Instance Method Summary collapse

Constructor Details

#initialize(beta_info, ui) ⇒ CrashlyticsBeta

Returns a new instance of CrashlyticsBeta.



3
4
5
6
# File 'lib/fastlane/setup/crashlytics_beta.rb', line 3

def initialize(beta_info, ui)
  @beta_info = beta_info
  @ui = ui
end

Instance Method Details

#expanded_paths_equal?(path1, path2) ⇒ Boolean

Returns:

  • (Boolean)


87
88
89
90
91
# File 'lib/fastlane/setup/crashlytics_beta.rb', line 87

def expanded_paths_equal?(path1, path2)
  return nil if path1.nil? || path2.nil?

  File.expand_path(path1) == File.expand_path(path2)
end

#fastfile_templateObject



93
94
95
96
97
98
99
100
101
102
103
# File 'lib/fastlane/setup/crashlytics_beta.rb', line 93

def fastfile_template
  <<-eos
fastlane_version "#{Fastlane::VERSION}"

default_platform :ios

platform :ios do
#{lane_template}
end
eos
end

#lane_templateObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/fastlane/setup/crashlytics_beta.rb', line 46

def lane_template
  discovered_crashlytics_path = Fastlane::Helper::CrashlyticsHelper.discover_default_crashlytics_path

  unless expanded_paths_equal?(@beta_info.crashlytics_path, discovered_crashlytics_path)
    crashlytics_path_arg = "\n         crashlytics_path: '#{@beta_info.crashlytics_path}',"
  end

  beta_info_groups = @beta_info.groups_valid? ? "['#{@beta_info.groups.join("', '")}']" : "nil"
  beta_info_emails = @beta_info.emails_valid? ? "['#{@beta_info.emails.join("', '")}']" : "nil"

# rubocop:disable Style/IndentationConsistency
%{  #
  # Learn more here: https://github.com/fastlane/setups/blob/master/samples-ios/distribute-beta-build.md 🚀
  #
  lane :beta do |values|
# Fabric generated this lane for deployment to Crashlytics Beta
# set 'export_method' to 'ad-hoc' if your Crashlytics Beta distribution uses ad-hoc provisioning
gym(scheme: '#{@beta_info.schemes.first}', export_method: '#{@beta_info.export_method}')

emails = values[:test_email] ? values[:test_email] : #{beta_info_emails} # You can list more emails here
groups = values[:test_email] ? nil : #{beta_info_groups} # You can define groups on the web and reference them here

crashlytics(api_token: '#{@beta_info.api_key}',
         build_secret: '#{@beta_info.build_secret}',#{crashlytics_path_arg}
               emails: emails,
               groups: groups,
                notes: 'Distributed with fastlane', # Check out the changelog_from_git_commits action
        notifications: true) # Should this distribution notify your testers via email?

# for all available options run `fastlane action crashlytics`

# You can notify your team in chat that a beta build has been uploaded
# slack(
#   slack_url: "https://hooks.slack.com/services/YOUR/TEAM/INFO"
#   channel: "beta-releases",
#   message: "Successfully uploaded a beta release - see it at https://fabric.io/_/beta"
# )
  end}
  # rubocop:enable Style/IndentationConsistency
end

#runObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/fastlane/setup/crashlytics_beta.rb', line 8

def run
  setup = Setup.new

  @ui.message 'This command will generate a fastlane configuration for distributing your app with Beta by Crashlytics'
  @ui.message 'so that you can get your testers new builds with a single command!'

  @ui.message ''

  if setup.is_android?
    UI.user_error!('Sorry, Beta by Crashlytics configuration is currently only available for iOS projects!')
  elsif !setup.is_ios?
    UI.user_error!('Please run Beta by Crashlytics configuration from your iOS project folder.')
  end

  @ui.message "\nAttempting to detect your project settings in this directory...".cyan
  info_collector = CrashlyticsBetaInfoCollector.new(CrashlyticsProjectParser.new,
                                                    CrashlyticsBetaUserEmailFetcher.new,
                                                    @ui)
  info_collector.collect_info_into(@beta_info)

  if FastlaneFolder.setup?
    @ui.message ""
    @ui.header('Copy and paste the following lane into your Fastfile to use Crashlytics Beta!')
    @ui.message ""
    puts lane_template.cyan
    @ui.message ""
  else
    fastfile = fastfile_template
    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 the following command to build and upload to Beta by Crashlytics. 🎯')
  @ui.message("\n    fastlane beta")
  @ui.message ""
end