Skip to content

Commit 1bb3648

Browse files
authored
Merge pull request #307 from BranchMetrics/automated-version-bump
Automated version bump and bug fixes
2 parents f723ac8 + dfa570b commit 1bb3648

File tree

8 files changed

+155
-53
lines changed

8 files changed

+155
-53
lines changed

android/src/main/java/io/branch/rnbranch/RNBranchModule.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import io.branch.referral.*;
2020
import io.branch.referral.Branch.BranchLinkCreateListener;
21+
import io.branch.referral.BuildConfig;
2122
import io.branch.referral.util.*;
2223
import io.branch.referral.Branch;
2324
import io.branch.indexing.*;
@@ -79,6 +80,7 @@ public class RNBranchModule extends ReactContextBaseJavaModule {
7980

8081
private static Activity mActivity = null;
8182
private static boolean mUseDebug = false;
83+
private static boolean mInitialized = false;
8284

8385
private AgingHash<String, BranchUniversalObject> mUniversalObjectMap = new AgingHash<>(AGING_HASH_TTL);
8486

@@ -592,21 +594,17 @@ public static LinkProperties createLinkProperties(ReadableMap linkPropertiesMap,
592594
}
593595

594596
private static Branch setupBranch(Context context) {
595-
RNBranchConfig config = new RNBranchConfig(context);
596-
String branchKey = config.getBranchKey();
597-
if (branchKey == null) branchKey = config.getUseTestInstance() ? config.getTestKey() : config.getLiveKey();
598-
599-
/*
600-
* This differs a little from iOS. If you add "useTestInstance": true to branch.json but
601-
* don't add the testKey, on iOS, it will use the test key from the Info.plist if configured.
602-
* On Android, useTestInstance in branch.json will be ignored unless testKey is present. If
603-
* testKey is not specified in branch.json, it's necessary to add io.branch.sdk.TestMode to
604-
* the Android manifest to use the test instance. It's not clear if there's a programmatic
605-
* way to select the test key without specifying the key explicitly.
606-
*/
607-
Branch branch = branchKey != null ? Branch.getInstance(context, branchKey) : Branch.getInstance(context);
608-
609-
if (mUseDebug || config.getDebugMode()) branch.setDebug();
597+
Branch branch = Branch.getInstance(context);
598+
599+
if (!mInitialized) {
600+
Log.i(REACT_CLASS, "Initializing Branch SDK v. " + BuildConfig.VERSION_NAME);
601+
602+
RNBranchConfig config = new RNBranchConfig(context);
603+
604+
if (mUseDebug || config.getDebugMode()) branch.setDebug();
605+
606+
mInitialized = true;
607+
}
610608

611609
return branch;
612610
}

fastlane/Fastfile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
actions_path("lib")
1+
actions_path("lib/actions")
22

33
fastlane_version "2.69.0"
44

@@ -30,3 +30,12 @@ lane :native_update do
3030
# verbose: true # Generate verbose output. Default: false
3131
# )
3232
end
33+
34+
# Examples:
35+
# bundle exec fastlane bump # patch increment
36+
# bundle exec fastlane bump version:2.3.0 # update to any specific version
37+
# bundle exec fastlane bump tag:yes # add a tag after committing
38+
desc "Increment version number"
39+
lane :bump do |opts|
40+
version_bump opts
41+
end

fastlane/lib/update_native_sdks.rb renamed to fastlane/lib/actions/update_native_sdks.rb

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require "xcodeproj"
2+
require_relative "../helper/update_helper"
23

34
module Fastlane
45
module Actions
@@ -164,36 +165,6 @@ def update_branch_podspec_from_submodule
164165
UI.success "Updated ios/Branch-SDK.podspec"
165166
end
166167

167-
def update_pods_in_tests_and_examples
168-
# Updates to CocoaPods for unit tests and examples (requires
169-
# node_modules for each)
170-
%w{
171-
examples/testbed_native_ios
172-
examples/webview_example_native_ios
173-
.
174-
}.each do |folder|
175-
other_action.yarn package_path: File.join("..", folder, "package.json")
176-
177-
pods_folder = folder
178-
179-
# The Podfile there installs from node_modules in the repo root.
180-
pods_folder = "native-tests/ios" if folder == "."
181-
182-
other_action.cocoapods(
183-
# relative to fastlane folder when using other_action
184-
podfile: File.join("..", pods_folder, "Podfile"),
185-
silent: true,
186-
use_bundle_exec: true
187-
)
188-
189-
other_action.git_add(path: File.join("..", pods_folder))
190-
191-
# node_modules only required for pod install. Remove to speed up
192-
# subsequent calls to yarn.
193-
sh "rm", "-fr", File.join(folder, "node_modules")
194-
end
195-
end
196-
197168
def adjust_rnbranch_xcodeproj
198169
@project = Xcodeproj::Project.open "#{@ios_subdir}/RNBranch.xcodeproj"
199170
# check_file_refs
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
require "fastlane/action"
2+
require "active_support/core_ext/hash"
3+
require "pattern_patch"
4+
require_relative "../helper/update_helper"
5+
6+
module Fastlane
7+
module Actions
8+
class VersionBumpAction < Action
9+
class << self
10+
def run(params)
11+
version = new_version params
12+
13+
UI.message "Bumping to version #{version}."
14+
15+
update_package_json version
16+
patch_index_js version
17+
update_pods_in_tests_and_examples
18+
sh "git", "commit", "-a", "-m", "[Fastlane] Version bump to #{version}"
19+
sh "git", "tag", version if params[:tag]
20+
true
21+
end
22+
23+
def available_options
24+
[
25+
FastlaneCore::ConfigItem.new(
26+
key: :version,
27+
type: String,
28+
description: "New version",
29+
optional: true,
30+
default_value: nil
31+
),
32+
FastlaneCore::ConfigItem.new(
33+
key: :tag,
34+
is_string: false,
35+
description: "Whether to tag after committing",
36+
optional: true,
37+
default_value: false
38+
)
39+
]
40+
end
41+
42+
def update_package_json(version)
43+
package_json[:version] = version
44+
json_text = JSON.generate(
45+
package_json,
46+
indent: " " * 2,
47+
object_nl: "\n",
48+
array_nl: "\n",
49+
space: " "
50+
)
51+
52+
File.write "package.json", "#{json_text}\n"
53+
end
54+
55+
def patch_index_js(version)
56+
PatternPatch::Patch.new(
57+
regexp: /(\sVERSION\s*=\s*")\d+\.\d+\.\d+/,
58+
text: "\\1#{version}",
59+
mode: :replace
60+
).apply "src/index.js"
61+
end
62+
63+
def new_version(params)
64+
version = params[:version]
65+
66+
if version.nil?
67+
# Increment version from package.json
68+
# Gem::Version doesn't seem to have a reasonable method for this.
69+
components = current_version.split(".")
70+
components[-1] = (components[-1].to_i + 1).to_s
71+
version = components.join(".")
72+
end
73+
74+
version
75+
end
76+
77+
def current_version
78+
package_json[:version]
79+
end
80+
81+
def package_json
82+
return @package_json if @package_json
83+
@package_json = JSON.parse(File.read("package.json")).symbolize_keys
84+
@package_json
85+
end
86+
end
87+
end
88+
end
89+
end
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
module UpdateHelper
2+
def update_pods_in_tests_and_examples
3+
# Updates to CocoaPods for unit tests and examples (requires
4+
# node_modules for each)
5+
%w{
6+
examples/testbed_native_ios
7+
examples/webview_example_native_ios
8+
.
9+
}.each do |folder|
10+
other_action.yarn package_path: File.join("..", folder, "package.json")
11+
12+
pods_folder = folder
13+
14+
# The Podfile there installs from node_modules in the repo root.
15+
pods_folder = "native-tests/ios" if folder == "."
16+
17+
other_action.cocoapods(
18+
# relative to fastlane folder when using other_action
19+
podfile: File.join("..", pods_folder, "Podfile"),
20+
silent: true,
21+
use_bundle_exec: true
22+
)
23+
24+
other_action.git_add(path: File.join("..", pods_folder))
25+
26+
# node_modules only required for pod install. Remove to speed up
27+
# subsequent calls to yarn.
28+
sh "rm", "-fr", File.join(folder, "node_modules")
29+
end
30+
end
31+
end
32+
33+
include UpdateHelper

ios/RNBranch.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ + (BOOL)requiresMainQueueSetup {
7474

7575
+ (void)setupBranchInstance:(Branch *)instance
7676
{
77+
RCTLogInfo(@"Initializing Branch SDK v. %@", BNC_SDK_VERSION);
7778
RNBranchConfig *config = RNBranchConfig.instance;
7879
if (config.debugMode) {
7980
[instance setDebug];

src/branchUniversalObject.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,16 @@ export default async function createBranchUniversalObject(identifier, options =
1717
}
1818
}
1919

20-
// For the benefit of NSDecimalNumber on iOS.
21-
const price = contentMetadata.price === undefined ? undefined : '' + contentMetadata.price
22-
2320
const branchUniversalObject = {
2421
canonicalIdentifier: identifier,
25-
contentMetadata: {
26-
price: price,
27-
...contentMetadata
28-
},
22+
contentMetadata: contentMetadata,
2923
...options
3024
}
3125

26+
// For the benefit of NSDecimalNumber on iOS.
27+
const price = contentMetadata.price === undefined ? undefined : '' + contentMetadata.price
28+
branchUniversalObject.contentMetadata.price = price
29+
3230
if (options.automaticallyListOnSpotlight !== undefined) {
3331
console.info('[Branch] automaticallyListOnSpotlight is deprecated. Please use locallyIndex instead.')
3432
}

src/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import createBranchUniversalObject from './branchUniversalObject'
66
import BranchEvent from './BranchEvent'
77

88
export const DEFAULT_INIT_SESSION_TTL = 5000
9+
export const VERSION = '2.2.2'
910

1011
export const AddToCartEvent = RNBranch.ADD_TO_CART_EVENT
1112
export const AddToWishlistEvent = RNBranch.ADD_TO_WISHLIST_EVENT
@@ -27,6 +28,8 @@ class Branch {
2728

2829
constructor(options = {}) {
2930
if (options.debug) this._debug = true
31+
32+
console.info('Initializing react-native-branch v. ' + VERSION)
3033
}
3134

3235
subscribe(listener) {

0 commit comments

Comments
 (0)