branch_io_cli 0.12.10 → 0.13.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 57f39dd1fd898a98b4de753d97c6c009ac8fd74c0a20b17d6dce8b97bf17ef8c
4
- data.tar.gz: a90d8ad9020c0012a9b81e4b98f29aa3e95750e452f1fd8d7aa8f76a62eff2b7
3
+ metadata.gz: 0e152cd651e5f3b196fe8a21e574e14cfdebfe3d240d8b8d7e7af69a27660b9d
4
+ data.tar.gz: 161b30c50fb66dda28a6300242dd63bf3ae050234e46293cad3c971ee6185a16
5
5
  SHA512:
6
- metadata.gz: c00d79ec662ce8baafdfce35ba28f5073c44d3030060e416057f261922f0af4d915f75c716905c30e3b7258c8ee15c16a4cee7376aed184e26812631c07e6e58
7
- data.tar.gz: 2e66dd0cb1430763d2c68841cb100caf7375343426ecd35e33b134454f905ffc50f5c6fee31ea507a096fe7e0bf92d647a066a555cd96c9fe05f1859034228ce
6
+ metadata.gz: bf27462ea52842ef5cd7e8c8d8adf4a4733424479035f57c6260a0cf0915bcf2e7de5e8689350c15991509a542107e6b3dadcb42eb262153051ccbb434edb768
7
+ data.tar.gz: 34a74447f9229e39f1cedc29d8ba56a387d260a4bde2db4461425a9e3ceb820f619980484c18babe4533b214ea22dec682418cdc83b04beb172c937a0c02af81
data/README.md CHANGED
@@ -7,6 +7,10 @@ This is a command-line tool to integrate the Branch SDK into mobile app projects
7
7
  [![License](https://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://github.com/BranchMetrics/branch_io_cli/blob/master/LICENSE)
8
8
  [![CircleCI](https://img.shields.io/circleci/project/github/BranchMetrics/branch_io_cli.svg)](https://circleci.com/gh/BranchMetrics/branch_io_cli)
9
9
 
10
+ ## Preliminary release
11
+
12
+ This is a preliminary release of this gem. Please report any problems by opening issues in this repo.
13
+
10
14
  ### Using Fastlane?
11
15
 
12
16
  See also the [Branch Fastlane plugin](https://github.com/BranchMetrics/fastlane-plugin-branch), which offers
@@ -22,17 +26,6 @@ gem install branch_io_cli
22
26
 
23
27
  Note that this command may require `sudo` access if you are using the system Ruby, i.e. `sudo gem install branch_io_cli`.
24
28
 
25
- ### Experimental: Install using Homebrew
26
-
27
- ```bash
28
- brew tap jdee/tap
29
- brew install branch_io_cli
30
- ```
31
-
32
- **Note:** Prerelease versions of the CLI are only available from RubyGems for now.
33
-
34
- ### Getting help
35
-
36
29
  ```bash
37
30
  branch_io -h
38
31
  branch_io setup -h
@@ -61,40 +54,18 @@ any Ruby-related environment variables if using the system Ruby.
61
54
 
62
55
  Add to `~/.bash_profile` or `~/.bashrc`:
63
56
 
64
- ##### RubyGems
65
-
66
57
  ```bash
67
58
  . `gem which branch_io_cli | sed 's+branch_io_cli.rb$+assets/completions/completion.bash+'`
68
59
  ```
69
60
 
70
- ##### Homebrew
71
-
72
- Source the script from the Cellar, e.g.:
73
-
74
- ```bash
75
- br_version=`br -v | awk '{ print $4 }'`
76
- . /usr/local/Cellar/branch_io_cli/${br_version}/libexec/gems/branch_io_cli-${br_version}/lib/assets/completions/completion.bash
77
- ```
78
-
79
61
  #### Zsh
80
62
 
81
63
  Add to `~/.zshrc`:
82
64
 
83
- ##### RubyGems
84
-
85
65
  ```zsh
86
66
  . `gem which branch_io_cli | sed 's+branch_io_cli.rb$+assets/completions/completion.zsh+'`
87
67
  ```
88
68
 
89
- ##### Homebrew
90
-
91
- Source the script from the Cellar, e.g.:
92
-
93
- ```bash
94
- br_version=`br -v | awk '{ print $4 }'`
95
- . /usr/local/Cellar/branch_io_cli/${br_version}/libexec/gems/branch_io_cli-${br_version}/lib/assets/completions/completion.zsh
96
- ```
97
-
98
69
  Currently command-line completion for bash is much more extensive than for zsh.
99
70
 
100
71
  ## Commands
@@ -189,7 +160,7 @@ See https://github.com/BranchMetrics/branch_io_cli#setup-command for more inform
189
160
  |--[no-]add-sdk|Add the Branch framework to the project (default: yes)|BRANCH_ADD_SDK|
190
161
  |--[no-]patch-source|Add Branch SDK calls to the AppDelegate (default: yes)|BRANCH_PATCH_SOURCE|
191
162
  |--commit [message]|Commit the results to Git if non-blank|BRANCH_COMMIT|
192
- |--[no-]confirm|Confirm configuration before proceeding (default: yes)|BRANCH_CONFIRM|
163
+ |--[no-]confirm|Enable or disable many prompts (default: yes)|BRANCH_CONFIRM|
193
164
 
194
165
 
195
166
  #### Examples
@@ -239,16 +210,26 @@ branch_io validate [OPTIONS]
239
210
  br validate [OPTIONS]
240
211
  ```
241
212
 
242
- This command validates all Universal Link domains configured in a project without making any
243
- modification. It validates both Branch and non-Branch domains. Unlike web-based Universal
244
- Link validators, this command operates directly on the project. It finds the bundle and
245
- signing team identifiers in the project as well as the app's Associated Domains. It requests
246
- the apple-app-site-association file for each domain and validates the file against the
247
- project's settings.
213
+ This command validates all Branch-related settings for a target in an Xcode project,
214
+ including validation of the apple-app-site-association file from each domain.
215
+ Multiple targets may be validated by running the command multiple times using
216
+ the `--target` option. Test targets are not supported.
217
+
218
+ For each Branch key present in the Info.plist, it retrieves the settings from Branch's
219
+ system. If the information cannot be retrieved (or if the `branch_key` is not present),
220
+ an error is recorded. If the `--live-key` or `--test-key` option is present,
221
+ the set of all keys used by the target must exactly match the options.
248
222
 
249
- Only app targets are supported for this command. By default, it will validate the first.
250
- If your project has multiple app targets, specify the `--target` option to validate other
251
- targets.
223
+ All domains and URI schemes configured for the target must include all domains
224
+ and URI schemes configured for all keys used by the target. Other domains or
225
+ URI schemes may also be present in the project.
226
+
227
+ This command validates all Universal Link domains configured in an application target
228
+ without making any modification. It validates both Branch and non-Branch domains. Unlike
229
+ web-based Universal Link validators, this command operates directly on the project. It
230
+ finds the bundle and signing team identifiers in the project as well as the app's
231
+ Associated Domains. It requests the apple-app-site-association file for each domain
232
+ and validates the file against the project's settings.
252
233
 
253
234
  By default, all build configurations in the project are validated. To validate a different list
254
235
  of configurations, including a single configuration, specify the `--configurations` option.
@@ -257,7 +238,7 @@ If `--domains` is specified, the list of Universal Link domains in the Associate
257
238
  Domains entitlement must exactly match this list, without regard to order, for all
258
239
  configurations under validation. If no `--domains` are provided, validation passes
259
240
  if at least one Universal Link domain is configured for each configuration and passes
260
- validation, and no Universal Link domain is present in anyconfiguration that does not
241
+ validation, and no Universal Link domain is present in any configuration that does not
261
242
  pass validation.
262
243
 
263
244
  All parameters are optional.
@@ -272,10 +253,14 @@ See https://github.com/BranchMetrics/branch_io_cli#validate-command for more inf
272
253
  |-h, --help|Prints a list of commands or help for each command||
273
254
  |-v, --version|Prints the current version of the CLI||
274
255
  |-t, --trace|Prints a stack trace when exceptions are raised||
275
- |-D, --domains example.com,www.example.com|Comma-separated list of domains to validate (Branch domains or non-Branch domains) (default: [])|BRANCH_DOMAINS|
276
- |--xcodeproj MyProject.xcodeproj|Path to an Xcode project to update|BRANCH_XCODEPROJ|
256
+ |-L, --live-key key_live_xxxx|Branch live key expected in project|BRANCH_LIVE_KEY|
257
+ |-T, --test-key key_test_yyyy|Branch test key expected in project|BRANCH_TEST_KEY|
258
+ |-D, --domains example.com,www.example.com|Comma-separated list of domains expected to be configured in the project (Branch domains or non-Branch domains) (default: [])|BRANCH_DOMAINS|
259
+ |--xcodeproj MyProject.xcodeproj|Path to an Xcode project to validate|BRANCH_XCODEPROJ|
277
260
  |--target MyAppTarget|Name of a target to validate in the Xcode project|BRANCH_TARGET|
278
261
  |--configurations Debug,Release|Comma-separated list of configurations to validate (default: all)|BRANCH_CONFIGURATIONS|
262
+ |--[no-]universal-links-only|Validate only the Universal Link configuration (default: no)|BRANCH_UNIVERSAL_LINKS_ONLY|
263
+ |--[no-]confirm|Enable or disable many prompts (default: yes)|BRANCH_CONFIRM|
279
264
 
280
265
 
281
266
 
@@ -314,7 +299,7 @@ building.
314
299
  |-H, --[no-]header-only|Write a report header to standard output and exit (default: no)|BRANCH_HEADER_ONLY|
315
300
  |--[no-]pod-repo-update|Update the local podspec repo before installing (default: yes)|BRANCH_POD_REPO_UPDATE|
316
301
  |-o, --out ./report.txt|Report output path (default: ./report.txt)|BRANCH_REPORT_PATH|
317
- |--[no-]confirm|Confirm before running certain commands (default: yes)|BRANCH_CONFIRM|
302
+ |--[no-]confirm|Enable or disable many prompts (default: yes)|BRANCH_CONFIRM|
318
303
 
319
304
 
320
305
 
@@ -17,7 +17,7 @@ _branch_io_complete()
17
17
 
18
18
  report_opts="--workspace --xcodeproj --scheme --target --configuration --sdk --podfile --cartfile --no-clean -H --header-only --no-pod-repo-update -o --out --no-confirm"
19
19
 
20
- validate_opts="-D --domains --xcodeproj --target --configurations"
20
+ validate_opts="-L --live-key -T --test-key -D --domains --xcodeproj --target --configurations --universal-links-only --no-confirm"
21
21
 
22
22
 
23
23
  if [[ ${cur} == -* ]] ; then
@@ -5,7 +5,7 @@ _branch_io_complete() {
5
5
  local word opts
6
6
  word="$1"
7
7
  opts="-h --help -t --trace -v --version"
8
- opts="$opts -L --live-key -T --test-key -D --domains --app-link-subdomain -U --uri-scheme -s --setting --test-configurations --xcodeproj --target --podfile --cartfile --carthage-command --frameworks --no-pod-repo-update --no-validate --force --no-add-sdk --no-patch-source --commit --no-confirm"
8
+ opts = "$opts -L --live-key -T --test-key -D --domains --app-link-subdomain -U --uri-scheme -s --setting --test-configurations --xcodeproj --target --podfile --cartfile --carthage-command --frameworks --no-pod-repo-update --no-validate --force --no-add-sdk --no-patch-source --commit --no-confirm"
9
9
 
10
10
  reply=( "${(ps: :)opts}" )
11
11
  }
@@ -5,7 +5,7 @@ _branch_io_complete() {
5
5
  local word opts
6
6
  word="$1"
7
7
  opts="-h --help -t --trace -v --version"
8
- <%= %(opts="$opts #{options_for_command 'setup'}") %>
8
+ <%= %(opts = "$opts #{options_for_command 'setup'}") %>
9
9
 
10
10
  reply=( "${(ps: :)opts}" )
11
11
  }
@@ -1,13 +1,23 @@
1
- This command validates all Universal Link domains configured in a project without making any
2
- modification. It validates both Branch and non-Branch domains. Unlike web-based Universal
3
- Link validators, this command operates directly on the project. It finds the bundle and
4
- signing team identifiers in the project as well as the app's Associated Domains. It requests
5
- the apple-app-site-association file for each domain and validates the file against the
6
- project's settings.
1
+ This command validates all Branch-related settings for a target in an Xcode project,
2
+ including validation of the apple-app-site-association file from each domain.
3
+ Multiple targets may be validated by running the command multiple times using
4
+ the <%= option :target %> option. Test targets are not supported.
7
5
 
8
- Only app targets are supported for this command. By default, it will validate the first.
9
- If your project has multiple app targets, specify the <%= option :target %> option to validate other
10
- targets.
6
+ For each Branch key present in the Info.plist, it retrieves the settings from Branch's
7
+ system. If the information cannot be retrieved (or if the `branch_key` is not present),
8
+ an error is recorded. If the <%= option :live_key %> or <%= option :test_key %> option is present,
9
+ the set of all keys used by the target must exactly match the options.
10
+
11
+ All domains and URI schemes configured for the target must include all domains
12
+ and URI schemes configured for all keys used by the target. Other domains or
13
+ URI schemes may also be present in the project.
14
+
15
+ This command validates all Universal Link domains configured in an application target
16
+ without making any modification. It validates both Branch and non-Branch domains. Unlike
17
+ web-based Universal Link validators, this command operates directly on the project. It
18
+ finds the bundle and signing team identifiers in the project as well as the app's
19
+ Associated Domains. It requests the apple-app-site-association file for each domain
20
+ and validates the file against the project's settings.
11
21
 
12
22
  By default, all build configurations in the project are validated. To validate a different list
13
23
  of configurations, including a single configuration, specify the <%= option :configurations %> option.
@@ -16,7 +26,7 @@ If <%= option :domains %> is specified, the list of Universal Link domains in th
16
26
  Domains entitlement must exactly match this list, without regard to order, for all
17
27
  configurations under validation. If no <%= option :domains %> are provided, validation passes
18
28
  if at least one Universal Link domain is configured for each configuration and passes
19
- validation, and no Universal Link domain is present in anyconfiguration that does not
29
+ validation, and no Universal Link domain is present in any configuration that does not
20
30
  pass validation.
21
31
 
22
32
  All parameters are optional.
@@ -1,4 +1,5 @@
1
1
  require "branch_io_cli/ascii_art"
2
+ require "branch_io_cli/branch_app"
2
3
  require "branch_io_cli/cli"
3
4
  require "branch_io_cli/command"
4
5
  require "branch_io_cli/configuration"
@@ -0,0 +1,70 @@
1
+ require "active_support/core_ext/hash"
2
+ require "json"
3
+ require "branch_io_cli/helper"
4
+
5
+ module BranchIOCLI
6
+ class BranchApp
7
+ class << self
8
+ def [](key)
9
+ fetch key
10
+ end
11
+
12
+ def fetch(key, cache: true)
13
+ @apps ||= {}
14
+ @apps[key] = new(key) unless cache && @apps[key]
15
+ @apps[key]
16
+ end
17
+ end
18
+
19
+ API_ENDPOINT = "https://api.branch.io/v1/app-link-settings/"
20
+
21
+ attr_reader :key
22
+ attr_reader :alternate_short_url_domain
23
+ attr_reader :android_package_name
24
+ attr_reader :android_uri_scheme
25
+ attr_reader :default_short_url_domain
26
+ attr_reader :ios_bundle_id
27
+ attr_reader :ios_team_id
28
+ attr_reader :ios_uri_scheme
29
+ attr_reader :short_url_domain
30
+
31
+ def initialize(key)
32
+ @key = key
33
+
34
+ say "Fetching configuration from Branch Dashboard for #{key}."
35
+
36
+ @hash = JSON.parse(Helper::BranchHelper.fetch("#{API_ENDPOINT}#{key}")).symbolize_keys.merge key: key
37
+
38
+ say "Done ✅"
39
+
40
+ @alternate_short_url_domain = @hash[:alternate_short_url_domain]
41
+ @android_package_name = @hash[:android_package_name]
42
+ @android_uri_scheme = @hash[:android_uri_scheme]
43
+ @default_short_url_domain = @hash[:default_short_url_domain]
44
+ @ios_bundle_id = @hash[:ios_bundle_id]
45
+ @ios_team_id = @hash[:ios_team_id]
46
+ @ios_uri_scheme = @hash[:ios_uri_scheme]
47
+ @short_url_domain = @hash[:short_url_domain]
48
+ end
49
+
50
+ def domains
51
+ [alternate_short_url_domain, default_short_url_domain, short_url_domain].compact.uniq
52
+ end
53
+
54
+ def to_hash
55
+ @hash
56
+ end
57
+
58
+ def to_s
59
+ # Changes
60
+ # {:key1=>"value1", :key2=>"value2"}
61
+ # to
62
+ # key1="value1" key2="value2"
63
+ @hash.to_s.sub(/^\{\:/, '').sub(/\}$/, '').gsub(/, \:/, ' ').gsub(/\=\>/, '=')
64
+ end
65
+
66
+ def inspect
67
+ "#<BranchIOCLI::BranchApp #{self}>"
68
+ end
69
+ end
70
+ end
@@ -37,8 +37,8 @@ module BranchIOCLI
37
37
  report.write "#{config.report_configuration}\n"
38
38
  report.write "#{report_helper.report_header}\n"
39
39
 
40
- report_helper.pod_install_if_required report
41
- report_helper.carthage_bootstrap_if_required report
40
+ tool_helper.pod_install_if_required report
41
+ tool_helper.carthage_bootstrap_if_required report
42
42
 
43
43
  # run xcodebuild -list
44
44
  report.sh(*report_helper.base_xcodebuild_cmd, "-list")
@@ -87,6 +87,10 @@ module BranchIOCLI
87
87
  def report_helper
88
88
  Helper::ReportHelper
89
89
  end
90
+
91
+ def tool_helper
92
+ Helper::ToolHelper
93
+ end
90
94
  end
91
95
  end
92
96
  end
@@ -21,15 +21,7 @@ module BranchIOCLI
21
21
  return 1 unless valid || config.force
22
22
  end
23
23
 
24
- # Make sure we can resolve all build settings in a project that uses
25
- # CocoaPods.
26
- if config.podfile_path && File.exist?(config.podfile_path) && config.pod_install_required?
27
- tool_helper.verify_cocoapods
28
- say "Installing pods to resolve current build settings"
29
- # We haven't modified anything yet. Don't use --repo-update at this stage.
30
- # This is unlikely to fail.
31
- sh "pod install", chdir: File.dirname(config.podfile_path)
32
- end
24
+ return false unless tool_helper.pod_install_if_required
33
25
 
34
26
  # Set up Universal Links and Branch key(s)
35
27
  update_project_settings
@@ -2,10 +2,16 @@ module BranchIOCLI
2
2
  module Command
3
3
  class ValidateCommand < Command
4
4
  def run!
5
- valid = true
5
+ say "\n"
6
6
 
7
7
  configurations = config.configurations || config.xcodeproj.build_configurations.map(&:name)
8
8
 
9
+ return false unless tool_helper.pod_install_if_required
10
+
11
+ valid = project_matches_keys?(configurations)
12
+ schemes_valid = uri_schemes_valid?(configurations)
13
+ valid &&= schemes_valid
14
+
9
15
  configurations.each do |configuration|
10
16
  message = "Validating #{configuration} configuration"
11
17
  say "\n<%= color('#{message}', [BOLD, CYAN]) %>\n\n"
@@ -16,30 +22,89 @@ module BranchIOCLI
16
22
  domains_valid = helper.validate_project_domains(config.domains, configuration)
17
23
 
18
24
  if domains_valid
19
- say "Project domains match :domains parameter: ✅"
25
+ say "Project domains match domains parameter. ✅"
20
26
  else
21
- say "Project domains do not match specified :domains"
27
+ say "Project domains do not match specified domains. ❌"
22
28
  helper.errors.each { |error| say " #{error}" }
23
29
  end
24
30
 
25
31
  config_valid &&= domains_valid
26
32
  end
27
33
 
28
- entitlements_valid = helper.validate_team_and_bundle_ids_from_aasa_files [], false, configuration
29
- unless entitlements_valid
30
- say "Universal Link configuration failed validation for #{configuration} configuration."
31
- helper.errors.each { |error| say " #{error}" }
34
+ if config.target.symbol_type == :application
35
+ entitlements_valid = helper.validate_team_and_bundle_ids_from_aasa_files [], false, configuration
36
+ unless entitlements_valid
37
+ say "Universal Link configuration failed validation for #{configuration} configuration. ❌"
38
+ helper.errors.each { |error| say " #{error}" }
39
+ end
40
+
41
+ config_valid &&= entitlements_valid
42
+
43
+ say "Universal Link configuration passed validation for #{configuration} configuration. ✅" if config_valid
32
44
  end
33
45
 
34
- config_valid &&= entitlements_valid
46
+ unless config.universal_links_only
47
+ branch_config_valid = helper.project_valid? configuration
48
+ unless branch_config_valid
49
+ say "Branch configuration failed validation for #{configuration} configuration. ❌"
50
+ helper.errors.each { |error| say " #{error}" }
51
+ end
35
52
 
36
- say "Universal Link configuration passed validation for #{configuration} configuration. ✅" if config_valid
53
+ config_valid &&= branch_config_valid
54
+
55
+ say "Branch configuration passed validation for #{configuration} configuration. ✅" if config_valid
56
+ end
37
57
 
38
58
  valid &&= config_valid
39
59
  end
40
60
 
61
+ unless valid
62
+ say "\nValidation failed. See errors above marked with ❌."
63
+ say "Please verify your app configuration at https://dashboard.branch.io."
64
+ say "If your Dashboard configuration is correct, br setup will fix most errors."
65
+ end
66
+
41
67
  valid ? 0 : 1
42
68
  end
69
+
70
+ def project_matches_keys?(configurations)
71
+ expected_keys = [config.live_key, config.test_key].compact
72
+ return true if expected_keys.empty?
73
+
74
+ # Validate the keys in the project against those passed in by the user.
75
+ branch_keys = helper.branch_keys_from_project(configurations).sort
76
+
77
+ keys_valid = expected_keys == branch_keys
78
+
79
+ say "\n"
80
+ if keys_valid
81
+ say "Branch keys from project match provided keys. ✅"
82
+ else
83
+ say "Branch keys from project do not match provided keys. ❌"
84
+ say " Expected: #{expected_keys.inspect}"
85
+ say " Actual: #{branch_keys.inspect}"
86
+ end
87
+
88
+ keys_valid
89
+ end
90
+
91
+ def uri_schemes_valid?(configurations)
92
+ uri_schemes = helper.branch_apps_from_project(configurations).map(&:ios_uri_scheme).compact.uniq
93
+ expected = uri_schemes.map { |s| BranchIOCLI::Configuration::Configuration.uri_scheme_without_suffix(s) }.sort
94
+ return true if expected.empty?
95
+
96
+ actual = helper.uri_schemes_from_project(configurations).sort
97
+ valid = (expected - actual).empty?
98
+ if valid
99
+ say "URI schemes from project match schemes from Dashboard. ✅"
100
+ else
101
+ say "URI schemes from project do not match schemes from Dashboard. ❌"
102
+ say " Expected: #{expected.inspect}"
103
+ say " Actual: #{actual.inspect}"
104
+ end
105
+
106
+ valid
107
+ end
43
108
  end
44
109
  end
45
110
  end