Skip to content

Commit df5f304

Browse files
authored
Merge pull request #1865 from StoDevX/bugsnag-sourcemaps
Upload source maps to Bugsnag for actual line-based error numbers
2 parents 918879f + 5272e04 commit df5f304

File tree

9 files changed

+311
-28
lines changed

9 files changed

+311
-28
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ before_install:
164164
- nvm install "$TRAVIS_NODE_VERSION"
165165
- nvm use "$TRAVIS_NODE_VERSION"
166166
- echo "node -v is now $(node -v)"
167-
167+
168168
# travis doesn't install yarn automatically on osx
169169
- if [[ $TRAVIS_OS_NAME == "osx" ]]; then brew install yarn --without-node; fi
170170

Gemfile.lock

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ GEM
3636
faraday_middleware (0.12.2)
3737
faraday (>= 0.7.4, < 1.0)
3838
fastimage (2.1.0)
39-
fastlane (2.62.0)
39+
fastlane (2.64.0)
4040
CFPropertyList (>= 2.3, < 3.0.0)
4141
addressable (>= 2.3, < 3.0.0)
4242
babosa (>= 1.0.2, < 2.0.0)
@@ -104,7 +104,7 @@ GEM
104104
httparty (0.15.6)
105105
multi_xml (>= 0.5.2)
106106
httpclient (2.8.3)
107-
i18n (0.9.0)
107+
i18n (0.9.1)
108108
concurrent-ruby (~> 1.0)
109109
json (2.1.0)
110110
jwt (2.1.0)
@@ -131,7 +131,7 @@ GEM
131131
public_suffix (2.0.5)
132132
rainbow (2.2.2)
133133
rake
134-
rake (12.1.0)
134+
rake (12.2.1)
135135
representable (3.0.4)
136136
declarative (< 0.1.0)
137137
declarative-option (< 0.2.0)
@@ -175,23 +175,23 @@ GEM
175175
terminal-table (1.8.0)
176176
unicode-display_width (~> 1.1, >= 1.1.1)
177177
thread_safe (0.3.6)
178-
tty-screen (0.5.0)
179-
tzinfo (1.2.3)
178+
tty-screen (0.5.1)
179+
tzinfo (1.2.4)
180180
thread_safe (~> 0.1)
181181
uber (0.1.0)
182182
unf (0.1.4)
183183
unf_ext
184184
unf_ext (0.0.7.4)
185185
unicode-display_width (1.3.0)
186186
word_wrap (1.0.0)
187-
xcodeproj (1.5.2)
187+
xcodeproj (1.5.3)
188188
CFPropertyList (~> 2.3.3)
189189
claide (>= 1.0.2, < 2.0)
190190
colored2 (~> 3.1)
191191
nanaimo (~> 0.2.3)
192192
xcpretty (0.2.8)
193193
rouge (~> 2.0.7)
194-
xcpretty-travis-formatter (0.0.4)
194+
xcpretty-travis-formatter (1.0.0)
195195
xcpretty (~> 0.2, >= 0.0.7)
196196

197197
PLATFORMS
@@ -205,6 +205,5 @@ DEPENDENCIES
205205
rubocop (= 0.46)
206206
xcodeproj
207207

208-
209208
BUNDLED WITH
210-
1.15.4
209+
1.16.0

fastlane/README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ xcode-select --install
1212

1313
<table width="100%" >
1414
<tr>
15-
<th width="33%"><a href="http://brew.sh">Homebrew</a></td>
16-
<th width="33%">Installer Script</td>
17-
<th width="33%">Rubygems</td>
15+
<th width="33%"><a href="http://brew.sh">Homebrew</a></th>
16+
<th width="33%">Installer Script</th>
17+
<th width="33%">RubyGems</th>
1818
</tr>
1919
<tr>
2020
<td width="33%" align="center">macOS</td>
@@ -53,6 +53,11 @@ Submit a new beta build to Google Play
5353
fastlane android nightly
5454
```
5555
Submit a new nightly build to Google Play
56+
### android sourcemap
57+
```
58+
fastlane android sourcemap
59+
```
60+
Bundle an Android sourcemap
5661
### android ci-run
5762
```
5863
fastlane android ci-run
@@ -97,6 +102,11 @@ Submit a new Beta Build to Testflight
97102
fastlane ios nightly
98103
```
99104
Submit a new nightly Beta Build to Testflight
105+
### ios sourcemap
106+
```
107+
fastlane ios sourcemap
108+
```
109+
Bundle an iOS sourcemap
100110
### ios refresh_dsyms
101111
```
102112
fastlane ios refresh_dsyms

fastlane/lib/util.rb

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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
6465
end
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*.
68133
def newest_tag

fastlane/platforms/android.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727

2828
supply(track: track,
2929
check_superseded_tracks: true)
30+
31+
generate_sourcemap
32+
upload_sourcemaps_to_bugsnag
3033
end
3134

3235
desc 'Submit a new beta build to Google Play'
@@ -39,6 +42,11 @@
3942
submit(track: 'alpha')
4043
end
4144

45+
desc 'Bundle an Android sourcemap'
46+
lane :sourcemap do
47+
generate_sourcemap
48+
end
49+
4250
desc 'Run the appropriate action on CI'
4351
lane :'ci-run' do
4452
# prepare for the bright future with signed android betas

fastlane/platforms/ios.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# 'iPhone 4s',
1414
'iPad Pro (9.7-inch)',
1515
'iPad Pro (12.9-inch)',
16-
]
16+
]
1717
snapshot(devices: devices,
1818
languages: ['en-US'],
1919
scheme: ENV['GYM_SCHEME'],
@@ -47,6 +47,13 @@
4747
puts 'Changelog failed to upload:'
4848
puts error
4949
end
50+
generate_sourcemap
51+
upload_sourcemaps_to_bugsnag
52+
end
53+
54+
desc 'Bundle an iOS sourcemap'
55+
lane :sourcemap do
56+
generate_sourcemap
5057
end
5158

5259
desc 'Upload dYSM symbols to Bugsnag from Apple'

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
"babel-jest": "21.2.0",
105105
"babel-plugin-flow-react-proptypes": "9.0.0",
106106
"babel-preset-react-native": "3.0.1",
107+
"bugsnag-sourcemaps": "1.0.1",
107108
"danger": "2.0.1",
108109
"eslint": "4.10.0",
109110
"eslint-config-prettier": "2.7.0",

source/bugsnag.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
// @flow
22
import {Client, Configuration} from 'bugsnag-react-native'
3-
import pkg from '../package.json'
43

5-
const PRODUCTION = process.env.NODE_ENV === 'production'
4+
const IS_PRODUCTION = process.env.NODE_ENV === 'production'
65

76
const config = new Configuration()
8-
config.autoNotify = PRODUCTION
9-
config.codeBundleId = pkg.version
10-
if (!PRODUCTION) {
7+
config.autoNotify = IS_PRODUCTION
8+
if (!IS_PRODUCTION) {
119
// disable bugsnag in dev builds
1210
config.beforeSendCallbacks.push(() => false)
1311
}

0 commit comments

Comments
 (0)