Class: Fastlane::Actions::SetupBranchAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/branch/actions/setup_branch_action.rb

Class Method Summary collapse

Class Method Details

.authorsObject



85
86
87
88
89
90
# File 'lib/fastlane/plugin/branch/actions/setup_branch_action.rb', line 85

def self.authors
  [
    "Branch <[email protected]>",
    "Jimmy Dee <[email protected]>"
  ]
end

.available_optionsObject



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/fastlane/plugin/branch/actions/setup_branch_action.rb', line 112

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :xcodeproj,
                            env_name: "BRANCH_XCODEPROJ",
                         description: "Path to an Xcode project to modify",
                            optional: true,
                                type: String),
    FastlaneCore::ConfigItem.new(key: :android_project_path,
                            env_name: "BRANCH_ANDROID_PROJECT_PATH",
                         description: "Path to an Android project to modify",
                            optional: true,
                                type: String),
    FastlaneCore::ConfigItem.new(key: :android_manifest_path,
                            env_name: "BRANCH_ANDROID_MANIFEST_PATH",
                         description: "Path to and Android manifest to modify",
                            optional: true,
                                type: String),
    FastlaneCore::ConfigItem.new(key: :live_key,
                            env_name: "BRANCH_LIVE_KEY",
                         description: "The Branch live key for your app",
                            optional: true,
                                type: String),
    FastlaneCore::ConfigItem.new(key: :test_key,
                            env_name: "BRANCH_TEST_KEY",
                         description: "The Branch test key for your app",
                            optional: true,
                                type: String),
    FastlaneCore::ConfigItem.new(key: :domains,
                            env_name: "BRANCH_DOMAINS",
                         description: "Branch (and/or non-Branch) Universal Link/App Link domains to add (comma-separated list or array)",
                            optional: true,
                           is_string: false),
    FastlaneCore::ConfigItem.new(key: :app_link_subdomain,
                            env_name: "BRANCH_APP_LINK_SUBDOMAIN",
                         description: "app.link subdomain",
                            optional: true,
                                type: String),
    FastlaneCore::ConfigItem.new(key: :uri_scheme,
                            env_name: "BRANCH_URI_SCHEME",
                         description: "Custom URI scheme used with Branch (Android only)",
                            optional: true,
                                type: String),
    FastlaneCore::ConfigItem.new(key: :activity_name,
                            env_name: "BRANCH_ACTIVITY_NAME",
                         description: "Name of the Activity in the manifest containing Branch intent-filers (Android only)",
                            optional: true,
                                type: String),
    FastlaneCore::ConfigItem.new(key: :target,
                            env_name: "BRANCH_TARGET",
                         description: "Name of the target in the Xcode project to modify (iOS only)",
                            optional: true,
                                type: String),
    FastlaneCore::ConfigItem.new(key: :update_bundle_and_team_ids,
                            env_name: "BRANCH_UPDATE_BUNDLE_AND_TEAM_IDS",
                         description: "If set to true, updates the bundle and team identifiers to match the AASA file (iOS only)",
                            optional: true,
                       default_value: false,
                           is_string: false),
    FastlaneCore::ConfigItem.new(key: :remove_existing_domains,
                            env_name: "BRANCH_REMOVE_EXISTING_DOMAINS",
                         description: "If set to true, removes any existing domains before adding Branch domains",
                            optional: true,
                       default_value: false,
                           is_string: false),
    FastlaneCore::ConfigItem.new(key: :force,
                            env_name: "BRANCH_FORCE_UPDATE",
                         description: "Update project(s) even if Universal Link validation fails",
                            optional: true,
                       default_value: false,
                           is_string: false),
    FastlaneCore::ConfigItem.new(key: :commit,
                            env_name: "BRANCH_COMMIT_CHANGES",
                         description: "Set to true to commit changes to Git; set to a string to commit with a custom message",
                            optional: true,
                       default_value: false,
                           is_string: false)
  ]
end

.categoryObject



195
196
197
# File 'lib/fastlane/plugin/branch/actions/setup_branch_action.rb', line 195

def self.category
  :project
end

.descriptionObject

rubocop: enable Metrics/PerceivedComplexity



81
82
83
# File 'lib/fastlane/plugin/branch/actions/setup_branch_action.rb', line 81

def self.description
  "Adds Branch keys, custom URI schemes and domains to iOS and Android projects."
end

.detailsObject



92
93
94
95
96
97
# File 'lib/fastlane/plugin/branch/actions/setup_branch_action.rb', line 92

def self.details
  "This action automatically configures Xcode and Android projects that use the Branch SDK " \
    "for Universal Links, App Links and custom URI handling. It modifies Xcode project settings and " \
    "entitlements as well as Info.plist and AndroidManifest.xml files. It also validates the Universal Link " \
    "configuration for Xcode projects."
end

.example_codeObject



99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/fastlane/plugin/branch/actions/setup_branch_action.rb', line 99

def self.example_code
  [
    "      setup_branch live_key: \"key_live_xxxx\",\n                   test_key: \"key_test_yyyy\",\n         app_link_subdomain: \"myapp\",\n                 uri_scheme: \"myscheme\", # Android only\n       android_project_path: \"MyAndroidApp\", # MyAndroidApp/src/main/AndroidManifest.xml\n                  xcodeproj: \"MyIOSApp.xcodeproj\"\n    EOF\n  ]\nend\n"

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


191
192
193
# File 'lib/fastlane/plugin/branch/actions/setup_branch_action.rb', line 191

def self.is_supported?(platform)
  [:ios, :android].include? platform
end

.run(params) ⇒ Object

rubocop: disable Metrics/PerceivedComplexity



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
45
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
# File 'lib/fastlane/plugin/branch/actions/setup_branch_action.rb', line 8

def self.run(params)
  # First augment with any defaults from Branchfile, if present
  params.load_configuration_file("Branchfile")

  helper = Helper::BranchHelper

  keys = helper.keys_from_params params
  raise "Must specify :live_key or :test_key." if keys.empty?

  domains = helper.domains_from_params params
  raise "Cannot determine domains to add to project. Specify :app_link_subdomain or :domains." if domains.empty?

  if params[:xcodeproj].nil? and params[:android_project_path].nil? and params[:android_manifest_path].nil?
    raise ":xcodeproj, :android_manifest_path or :android_project_path is required"
  end

  UI.message "live key: #{keys[:live]}" unless keys[:live].nil?
  UI.message "test key: #{keys[:test]}" unless keys[:test].nil?
  UI.message "domains: #{domains}"

  if params[:xcodeproj]
    # raises
    xcodeproj = Xcodeproj::Project.open params[:xcodeproj]

    target = params[:target] # may be nil

    if params[:update_bundle_and_team_ids]
      helper.update_team_and_bundle_ids_from_aasa_file xcodeproj, target, domains.first
    elsif helper.validate_team_and_bundle_ids_from_aasa_files xcodeproj, target, domains, params[:remove_existing_domains]
      UI.message "Universal Link configuration passed validation. ✅"
    else
      UI.error "Universal Link configuration failed validation."
      helper.errors.each { |error| UI.error " #{error}" }
      return unless params[:force]
    end

    # the following calls can all raise IOError
    helper.add_keys_to_info_plist xcodeproj, target, keys
    helper.add_branch_universal_link_domains_to_info_plist xcodeproj, target, domains
    new_path = helper.add_universal_links_to_project xcodeproj, target, domains, params[:remove_existing_domains]
    other_action.git_add path: new_path if params[:commit] && new_path
    xcodeproj.save
  end

  if params[:android_project_path] || params[:android_manifest_path]
    # :android_manifest_path overrides :android_project_path
    manifest_path = params[:android_manifest_path] || "#{params[:android_project_path]}/app/src/main/AndroidManifest.xml"
    manifest = File.open(manifest_path) { |f| REXML::Document.new f }

    helper.add_keys_to_android_manifest manifest, keys
    # :activity_name and :uri_scheme may be nil. :remove_existing_domains defaults to false
    helper.add_intent_filters_to_android_manifest manifest,
                                                  domains,
                                                  params[:uri_scheme],
                                                  params[:activity_name],
                                                  params[:remove_existing_domains]

    File.open(manifest_path, "w") do |f|
      manifest.write f, 4
    end

    helper.add_change File.expand_path(manifest_path, Bundler.root)
  end

  if params[:commit]
    message = params[:commit].kind_of?(String) ? params[:commit] : "[Fastlane] Branch SDK integration"
    other_action.git_commit path: helper.changes.to_a, message: message
  end
rescue => e
  UI.user_error! "Error in SetupBranchAction: #{e.message}\n#{e.backtrace}"
end