@@ -49,7 +49,8 @@ def propagate_version(**args)
4949 UI . message "Propagating version: #{ version } "
5050 UI . message 'into the Info.plist and build.gradle files'
5151
52- # encode build number into js-land
52+ # encode build number into js-land – we've already fetched it, so we'll
53+ # never set the "+" into the binaries
5354 set_package_data ( data : { version : "#{ version } +#{ build } " } )
5455
5556 case lane_context [ :PLATFORM_NAME ]
@@ -63,6 +64,70 @@ def propagate_version(**args)
6364 end
6465end
6566
67+ # Generate argument values for the generate_sourcemap and upload_sourcemap_to_bugsnag lanes
68+ def get_sourcemap_args
69+ # The cwd is /fastlane. I don't know why entry_file doesn't need to be ../, but
70+ # I believe that watchman finds the project root and automatically looks there
71+ case lane_context [ :PLATFORM_NAME ]
72+ when :android
73+ platform = 'android'
74+ entry_file = 'index.android.js'
75+ bundle_output = '../android-release.bundle'
76+ sourcemap_output = '../android-release.bundle.map'
77+ bundle_url = 'index.android.bundle'
78+ when :ios
79+ platform = 'ios'
80+ entry_file = 'index.ios.js'
81+ bundle_output = '../ios-release.bundle'
82+ sourcemap_output = '../ios-release.bundle.map'
83+ bundle_url = 'main.jsbundle'
84+ end
85+
86+ {
87+ platform : platform ,
88+ entry_file : entry_file ,
89+ bundle_output : bundle_output ,
90+ sourcemap_output : sourcemap_output ,
91+ bundle_url : bundle_url ,
92+ }
93+ end
94+
95+ # Use react-native cli to generate the source map
96+ def generate_sourcemap
97+ args = get_sourcemap_args
98+
99+ cmd = [
100+ 'npx react-native bundle' ,
101+ '--dev false' ,
102+ "--platform '#{ args [ :platform ] } '" ,
103+ "--entry-file '#{ args [ :entry_file ] } '" ,
104+ "--bundle-output '#{ args [ :bundle_output ] } '" ,
105+ "--sourcemap-output '#{ args [ :sourcemap_output ] } '" ,
106+ ] . join ' '
107+
108+ FastlaneCore ::CommandExecutor . execute ( command : cmd ,
109+ print_all : true ,
110+ print_command : true )
111+ end
112+
113+ # Upload source map to Bugsnag
114+ def upload_sourcemap_to_bugsnag
115+ args = get_sourcemap_args
116+
117+ cmd = [
118+ 'npx bugsnag-sourcemaps upload' ,
119+ "--api-key '#{ ENV [ 'BUGSNAG_KEY' ] } '" ,
120+ "--minified-file '#{ args [ :bundle_output ] } '" ,
121+ "--source-map '#{ args [ :sourcemap_output ] } '" ,
122+ "--minified-url '#{ args [ :bundle_url ] } '" ,
123+ '--upload-sources' ,
124+ ] . join ' '
125+
126+ FastlaneCore ::CommandExecutor . execute ( command : cmd ,
127+ print_all : true ,
128+ print_command : true )
129+ end
130+
66131# last_git_tag returns the most recent tag, chronologically.
67132# newest_tag returns the most recent tag *on this branch*.
68133def newest_tag
0 commit comments